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/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, HaveTurboFrame, HaveTurboStream, HaveTurboStreams, MatchTurboStreamSnapshot

Instance Method Summary collapse

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 ++ to the given stream.

Parameters:

  • stream_or_object (String, Object)

    stream name or streamable object

Returns:



21
22
23
# File 'lib/turbo_rspec/matchers.rb', line 21

def have_broadcasted_turbo_stream_to(stream_or_object)
  HaveBroadcastedTurboStreamTo.new(stream_or_object)
end

#have_turbo_frameHaveTurboFrame

Assert that a response body contains a ++ element.

Returns:



30
31
32
# File 'lib/turbo_rspec/matchers.rb', line 30

def have_turbo_frame
  HaveTurboFrame.new
end

#have_turbo_streamHaveTurboStream Also known as: assert_no_turbo_stream

Assert that a response body contains a ++ element.

Returns:



36
37
38
# File 'lib/turbo_rspec/matchers.rb', line 36

def have_turbo_stream
  HaveTurboStream.new
end

#have_turbo_streams(*matchers) ⇒ HaveTurboStreams

Assert that a response body contains all of the given turbo streams.

Parameters:

Returns:



47
48
49
# File 'lib/turbo_rspec/matchers.rb', line 47

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.

Parameters:

  • name (String)

    snapshot name, used as the file path within +snapshot_dir+

Returns:



56
57
58
# File 'lib/turbo_rspec/matchers.rb', line 56

def match_turbo_stream_snapshot(name)
  MatchTurboStreamSnapshot.new(name)
end