Class: TurboRspec::Matchers::HaveTurboStreams

Inherits:
Object
  • Object
show all
Defined in:
lib/turbo_rspec/matchers/have_turbo_streams.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected_streams) ⇒ HaveTurboStreams

Returns a new instance of HaveTurboStreams.



8
9
10
# File 'lib/turbo_rspec/matchers/have_turbo_streams.rb', line 8

def initialize(expected_streams)
  @expected_streams = expected_streams
end

Instance Method Details

#descriptionObject



33
34
35
# File 'lib/turbo_rspec/matchers/have_turbo_streams.rb', line 33

def description
  "have turbo streams: #{@expected_streams.map(&:description).join(", ")}"
end

#does_not_match?(response_or_body) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/turbo_rspec/matchers/have_turbo_streams.rb', line 19

def does_not_match?(response_or_body)
  !matches?(response_or_body)
end

#failure_messageObject



23
24
25
26
27
# File 'lib/turbo_rspec/matchers/have_turbo_streams.rb', line 23

def failure_message
  descriptions = @unmatched.map { |m| "  #{m.description}" }.join("\n")
  "expected response to contain all turbo streams, but missing:\n#{descriptions}\n\n" \
    "found streams:\n#{found_streams_summary}"
end

#failure_message_when_negatedObject



29
30
31
# File 'lib/turbo_rspec/matchers/have_turbo_streams.rb', line 29

def failure_message_when_negated
  "expected response not to contain all of the specified turbo streams"
end

#matches?(response_or_body) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
# File 'lib/turbo_rspec/matchers/have_turbo_streams.rb', line 12

def matches?(response_or_body)
  @body = extract_body(response_or_body)
  @found = parse_streams(@body)
  @unmatched = @expected_streams.reject { |expected| any_stream_matches?(expected) }
  @unmatched.empty?
end