Class: TurboRspec::Matchers::HaveTurboStream
- Inherits:
-
Object
- Object
- TurboRspec::Matchers::HaveTurboStream
- Defined in:
- lib/turbo_rspec/matchers/have_turbo_stream.rb
Overview
RSpec matcher for asserting that a response body contains a
+
Instance Method Summary collapse
- #description ⇒ String
- #does_not_match?(response_or_body) ⇒ Boolean
- #failure_message ⇒ String
- #failure_message_when_negated ⇒ String
-
#initialize ⇒ HaveTurboStream
constructor
A new instance of HaveTurboStream.
- #matches?(response_or_body) ⇒ Boolean
-
#rendering(partial) ⇒ self
Constrains the match to streams whose rendered HTML includes the given partial path.
-
#targeting(dom_id) ⇒ self
Constrains the match to streams targeting a specific DOM id.
-
#targeting_all(selector) ⇒ self
Constrains the match to streams targeting a CSS selector (the +targets+ attribute).
-
#with_action(action) ⇒ self
Constrains the match to streams with the given action.
-
#with_content(text) ⇒ self
Constrains the match to streams whose template content includes the given text.
Constructor Details
#initialize ⇒ HaveTurboStream
Returns a new instance of HaveTurboStream.
25 26 27 28 29 30 31 |
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 25 def initialize @action = nil @target = nil @target_all = nil @content = nil @partial = nil end |
Instance Method Details
#description ⇒ String
98 99 100 |
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 98 def description "have turbo stream#{constraint_description}" end |
#does_not_match?(response_or_body) ⇒ Boolean
83 84 85 |
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 83 def does_not_match?(response_or_body) !matches?(response_or_body) end |
#failure_message ⇒ String
88 89 90 |
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 88 def "expected response to contain a turbo stream#{constraint_description}\n#{}" end |
#failure_message_when_negated ⇒ String
93 94 95 |
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 93 def "expected response not to contain a turbo stream#{constraint_description}" end |
#matches?(response_or_body) ⇒ Boolean
75 76 77 78 79 |
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 75 def matches?(response_or_body) @body = extract_body(response_or_body) @streams = parse_streams(@body) @streams.any? { |stream| stream_matches?(stream) } end |
#rendering(partial) ⇒ self
Constrains the match to streams whose rendered HTML includes the given partial path.
68 69 70 71 |
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 68 def rendering(partial) @partial = partial.to_s self end |
#targeting(dom_id) ⇒ self
Constrains the match to streams targeting a specific DOM id.
44 45 46 47 |
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 44 def targeting(dom_id) @target = dom_id.to_s self end |
#targeting_all(selector) ⇒ self
Constrains the match to streams targeting a CSS selector (the +targets+ attribute).
52 53 54 55 |
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 52 def targeting_all(selector) @target_all = selector.to_s self end |
#with_action(action) ⇒ self
Constrains the match to streams with the given action.
36 37 38 39 |
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 36 def with_action(action) @action = action.to_s self end |
#with_content(text) ⇒ self
Constrains the match to streams whose template content includes the given text.
60 61 62 63 |
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 60 def with_content(text) @content = text.to_s self end |