Class: TurboRspec::Matchers::HaveTurboStream
- Inherits:
-
Object
- Object
- TurboRspec::Matchers::HaveTurboStream
- Defined in:
- lib/turbo_rspec/matchers/have_turbo_stream.rb
Instance Method Summary collapse
- #description ⇒ Object
- #does_not_match?(response_or_body) ⇒ Boolean
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize ⇒ HaveTurboStream
constructor
A new instance of HaveTurboStream.
- #matches?(response_or_body) ⇒ Boolean
- #rendering(partial) ⇒ Object
- #targeting(dom_id) ⇒ Object
- #targeting_all(selector) ⇒ Object
- #with_action(action) ⇒ Object
- #with_content(text) ⇒ Object
Constructor Details
#initialize ⇒ HaveTurboStream
Returns a new instance of HaveTurboStream.
8 9 10 11 12 13 14 |
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 8 def initialize @action = nil @target = nil @target_all = nil @content = nil @partial = nil end |
Instance Method Details
#description ⇒ Object
59 60 61 |
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 59 def description "have turbo stream#{constraint_description}" end |
#does_not_match?(response_or_body) ⇒ Boolean
47 48 49 |
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 47 def does_not_match?(response_or_body) !matches?(response_or_body) end |
#failure_message ⇒ Object
51 52 53 |
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 51 def "expected response to contain a turbo stream#{constraint_description}\n#{}" end |
#failure_message_when_negated ⇒ Object
55 56 57 |
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 55 def "expected response not to contain a turbo stream#{constraint_description}" end |
#matches?(response_or_body) ⇒ Boolean
41 42 43 44 45 |
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 41 def matches?(response_or_body) @body = extract_body(response_or_body) @streams = parse_streams(@body) @streams.any? { |stream| stream_matches?(stream) } end |
#rendering(partial) ⇒ Object
36 37 38 39 |
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 36 def rendering(partial) @partial = partial.to_s self end |
#targeting(dom_id) ⇒ Object
21 22 23 24 |
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 21 def targeting(dom_id) @target = dom_id.to_s self end |
#targeting_all(selector) ⇒ Object
26 27 28 29 |
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 26 def targeting_all(selector) @target_all = selector.to_s self end |
#with_action(action) ⇒ Object
16 17 18 19 |
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 16 def with_action(action) @action = action.to_s self end |
#with_content(text) ⇒ Object
31 32 33 34 |
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 31 def with_content(text) @content = text.to_s self end |