Class: TurboRspec::Matchers::HaveTurboStreams
- Inherits:
-
Object
- Object
- TurboRspec::Matchers::HaveTurboStreams
- Defined in:
- lib/turbo_rspec/matchers/have_turbo_streams.rb
Instance Method Summary collapse
- #description ⇒ Object
- #does_not_match?(response_or_body) ⇒ Boolean
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(expected_streams) ⇒ HaveTurboStreams
constructor
A new instance of HaveTurboStreams.
- #matches?(response_or_body) ⇒ Boolean
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
#description ⇒ Object
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
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_message ⇒ Object
23 24 25 26 27 |
# File 'lib/turbo_rspec/matchers/have_turbo_streams.rb', line 23 def 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_negated ⇒ Object
29 30 31 |
# File 'lib/turbo_rspec/matchers/have_turbo_streams.rb', line 29 def "expected response not to contain all of the specified turbo streams" end |
#matches?(response_or_body) ⇒ 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 |