Module: TurboRspec::Matchers
- Defined in:
- lib/turbo_rspec/matchers.rb,
lib/turbo_rspec/matchers/have_turbo_frame.rb,
lib/turbo_rspec/matchers/have_turbo_stream.rb,
lib/turbo_rspec/matchers/have_turbo_streams.rb,
lib/turbo_rspec/matchers/have_stimulus_action.rb,
lib/turbo_rspec/matchers/have_stimulus_target.rb,
lib/turbo_rspec/matchers/have_stimulus_controller.rb,
lib/turbo_rspec/matchers/match_turbo_stream_snapshot.rb,
lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb
Overview
RSpec matchers for Turbo Stream and Turbo Frame assertions. Auto-included in +type: :request+ and +type: :controller+ example groups. Include explicitly for other contexts:
RSpec.configure do |config| config.include TurboRspec::Matchers end
Defined Under Namespace
Classes: HaveBroadcastedTurboStreamTo, HaveStimulusAction, HaveStimulusController, HaveStimulusTarget, HaveTurboFrame, HaveTurboStream, HaveTurboStreams, MatchTurboStreamSnapshot
Instance Method Summary collapse
-
#have_broadcasted_turbo_stream_to(stream_or_object) ⇒ HaveBroadcastedTurboStreamTo
(also: #broadcast_turbo_stream_to)
Assert that a block broadcasts a +
+ to the given stream. -
#have_stimulus_action(action_descriptor) ⇒ HaveStimulusAction
Assert that a response body contains an element with the given Stimulus action.
-
#have_stimulus_controller(controller_name) ⇒ HaveStimulusController
Assert that a response body contains an element with the given Stimulus controller.
-
#have_stimulus_target(controller_name, target_name) ⇒ HaveStimulusTarget
Assert that a response body contains an element with the given Stimulus target.
-
#have_turbo_frame ⇒ HaveTurboFrame
Assert that a response body contains a +
+ element. -
#have_turbo_stream ⇒ HaveTurboStream
(also: #assert_no_turbo_stream)
Assert that a response body contains a +
+ element. -
#have_turbo_streams(*matchers) ⇒ HaveTurboStreams
Assert that a response body contains all of the given turbo streams.
-
#match_turbo_stream_snapshot(name) ⇒ MatchTurboStreamSnapshot
Assert that a response body matches a stored turbo stream snapshot.
Instance Method Details
#have_broadcasted_turbo_stream_to(stream_or_object) ⇒ HaveBroadcastedTurboStreamTo Also known as: broadcast_turbo_stream_to
Assert that a block broadcasts a +
24 25 26 |
# File 'lib/turbo_rspec/matchers.rb', line 24 def have_broadcasted_turbo_stream_to(stream_or_object) HaveBroadcastedTurboStreamTo.new(stream_or_object) end |
#have_stimulus_action(action_descriptor) ⇒ HaveStimulusAction
Assert that a response body contains an element with the given Stimulus action.
64 65 66 |
# File 'lib/turbo_rspec/matchers.rb', line 64 def have_stimulus_action(action_descriptor) HaveStimulusAction.new(action_descriptor) end |
#have_stimulus_controller(controller_name) ⇒ HaveStimulusController
Assert that a response body contains an element with the given Stimulus controller.
57 58 59 |
# File 'lib/turbo_rspec/matchers.rb', line 57 def have_stimulus_controller(controller_name) HaveStimulusController.new(controller_name) end |
#have_stimulus_target(controller_name, target_name) ⇒ HaveStimulusTarget
Assert that a response body contains an element with the given Stimulus target.
72 73 74 |
# File 'lib/turbo_rspec/matchers.rb', line 72 def have_stimulus_target(controller_name, target_name) HaveStimulusTarget.new(controller_name, target_name) end |
#have_turbo_frame ⇒ HaveTurboFrame
Assert that a response body contains a +
33 34 35 |
# File 'lib/turbo_rspec/matchers.rb', line 33 def have_turbo_frame HaveTurboFrame.new end |
#have_turbo_stream ⇒ HaveTurboStream Also known as: assert_no_turbo_stream
Assert that a response body contains a +
39 40 41 |
# File 'lib/turbo_rspec/matchers.rb', line 39 def have_turbo_stream HaveTurboStream.new end |
#have_turbo_streams(*matchers) ⇒ HaveTurboStreams
Assert that a response body contains all of the given turbo streams.
50 51 52 |
# File 'lib/turbo_rspec/matchers.rb', line 50 def have_turbo_streams(*matchers) HaveTurboStreams.new(matchers) end |
#match_turbo_stream_snapshot(name) ⇒ MatchTurboStreamSnapshot
Assert that a response body matches a stored turbo stream snapshot. Creates the snapshot on the first run; diffs against it on subsequent runs. Set +UPDATE_TURBO_SNAPSHOTS=1+ to overwrite an existing snapshot.
81 82 83 |
# File 'lib/turbo_rspec/matchers.rb', line 81 def match_turbo_stream_snapshot(name) MatchTurboStreamSnapshot.new(name) end |