Class: TurboRspec::Matchers::HaveBroadcastedTurboStreamTo
- Inherits:
-
Object
- Object
- TurboRspec::Matchers::HaveBroadcastedTurboStreamTo
- Defined in:
- lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb
Instance Method Summary collapse
- #at_least(n) ⇒ Object
- #at_most(n) ⇒ Object
- #description ⇒ Object
- #does_not_match?(block) ⇒ Boolean
- #exactly(n) ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(stream_or_object) ⇒ HaveBroadcastedTurboStreamTo
constructor
A new instance of HaveBroadcastedTurboStreamTo.
- #matches?(block) ⇒ Boolean
-
#once ⇒ Object
Count qualifiers.
- #rendering(partial) ⇒ Object
- #supports_block_expectations? ⇒ Boolean
- #targeting(dom_id) ⇒ Object
- #targeting_all(selector) ⇒ Object
- #times ⇒ Object
- #twice ⇒ Object
-
#with_action(action) ⇒ Object
Stream constraints (mirrors HaveTurboStream).
- #with_content(text) ⇒ Object
Constructor Details
#initialize(stream_or_object) ⇒ HaveBroadcastedTurboStreamTo
Returns a new instance of HaveBroadcastedTurboStreamTo.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 8 def initialize(stream_or_object) @stream_or_object = stream_or_object @action = nil @target = nil @target_all = nil @content = nil @partial = nil @expected_count = nil @count_type = :at_least end |
Instance Method Details
#at_least(n) ⇒ Object
62 63 64 65 66 |
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 62 def at_least(n) @expected_count = n @count_type = :at_least self end |
#at_most(n) ⇒ Object
68 69 70 71 72 |
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 68 def at_most(n) @expected_count = n @count_type = :at_most self end |
#description ⇒ Object
101 102 103 |
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 101 def description "broadcast a turbo stream to #{stream_name.inspect}#{constraint_description}" end |
#does_not_match?(block) ⇒ Boolean
89 90 91 |
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 89 def does_not_match?(block) !matches?(block) end |
#exactly(n) ⇒ Object
56 57 58 59 60 |
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 56 def exactly(n) @expected_count = n @count_type = :exactly self end |
#failure_message ⇒ Object
93 94 95 |
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 93 def "expected block to broadcast a turbo stream to #{stream_name.inspect}#{constraint_description}#{count_description}\n#{}" end |
#failure_message_when_negated ⇒ Object
97 98 99 |
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 97 def "expected block not to broadcast a turbo stream to #{stream_name.inspect}#{constraint_description}" end |
#matches?(block) ⇒ Boolean
82 83 84 85 86 87 |
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 82 def matches?(block) before = snapshot block.call @matching = (snapshot - before).select { |msg| (msg) } count_matches?(@matching.size) end |
#once ⇒ Object
Count qualifiers
48 49 50 |
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 48 def once exactly(1) end |
#rendering(partial) ⇒ Object
41 42 43 44 |
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 41 def rendering(partial) @partial = partial.to_s self end |
#supports_block_expectations? ⇒ Boolean
78 79 80 |
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 78 def supports_block_expectations? true end |
#targeting(dom_id) ⇒ Object
26 27 28 29 |
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 26 def targeting(dom_id) @target = dom_id.to_s self end |
#targeting_all(selector) ⇒ Object
31 32 33 34 |
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 31 def targeting_all(selector) @target_all = selector.to_s self end |
#times ⇒ Object
74 75 76 |
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 74 def times self end |
#twice ⇒ Object
52 53 54 |
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 52 def twice exactly(2) end |
#with_action(action) ⇒ Object
Stream constraints (mirrors HaveTurboStream)
21 22 23 24 |
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 21 def with_action(action) @action = action.to_s self end |
#with_content(text) ⇒ Object
36 37 38 39 |
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 36 def with_content(text) @content = text.to_s self end |