Module: TurboRspec::Assertions

Defined in:
lib/turbo_rspec/assertions.rb

Overview

Minitest-compatible assertions. Include in your test class:

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase include TurboRspec::Assertions end

No RSpec dependency required.

Instance Method Summary collapse

Instance Method Details

#assert_broadcasted_turbo_stream_to(stream, action: nil, target: nil, targets: nil, content: nil, partial: nil, message: nil, &block) ⇒ Object

Assert that a block broadcasts a ++ to the given stream. Requires ActionCable's test adapter.

Parameters:

  • stream (String)

    the stream name

  • action (Symbol, String, nil) (defaults to: nil)

    optional action constraint

  • target (String, nil) (defaults to: nil)

    optional target constraint

  • targets (String, nil) (defaults to: nil)

    optional targets (CSS selector) constraint

  • content (String, nil) (defaults to: nil)

    optional content constraint

  • partial (String, nil) (defaults to: nil)

    optional partial path constraint

  • message (String, nil) (defaults to: nil)

    optional custom failure message



26
27
28
29
# File 'lib/turbo_rspec/assertions.rb', line 26

def assert_broadcasted_turbo_stream_to(stream, action: nil, target: nil, targets: nil, content: nil, partial: nil, message: nil, &block)
  matcher = build_broadcast_matcher(stream, action: action, target: target, targets: targets, content: content, partial: partial)
  assert matcher.matches?(block), message || matcher.failure_message
end

#assert_turbo_frame(response_or_body, id: nil, content: nil, partial: nil, message: nil) ⇒ Object



50
51
52
53
# File 'lib/turbo_rspec/assertions.rb', line 50

def assert_turbo_frame(response_or_body, id: nil, content: nil, partial: nil, message: nil)
  matcher = build_frame_matcher(id: id, content: content, partial: partial)
  assert matcher.matches?(response_or_body), message || matcher.failure_message
end

#assert_turbo_stream(response_or_body, action: nil, target: nil, targets: nil, content: nil, partial: nil, message: nil) ⇒ Object



40
41
42
43
# File 'lib/turbo_rspec/assertions.rb', line 40

def assert_turbo_stream(response_or_body, action: nil, target: nil, targets: nil, content: nil, partial: nil, message: nil)
  matcher = build_stream_matcher(action: action, target: target, targets: targets, content: content, partial: partial)
  assert matcher.matches?(response_or_body), message || matcher.failure_message
end

#refute_broadcasted_turbo_stream_to(stream, action: nil, target: nil, targets: nil, content: nil, partial: nil, message: nil, &block) ⇒ Object

Assert that a block does NOT broadcast a ++ to the given stream. Requires ActionCable's test adapter.

Parameters:

  • stream (String)

    the stream name



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

def refute_broadcasted_turbo_stream_to(stream, action: nil, target: nil, targets: nil, content: nil, partial: nil, message: nil, &block)
  matcher = build_broadcast_matcher(stream, action: action, target: target, targets: targets, content: content, partial: partial)
  assert matcher.does_not_match?(block), message || matcher.failure_message_when_negated
end

#refute_turbo_frame(response_or_body, id: nil, content: nil, partial: nil, message: nil) ⇒ Object



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

def refute_turbo_frame(response_or_body, id: nil, content: nil, partial: nil, message: nil)
  matcher = build_frame_matcher(id: id, content: content, partial: partial)
  assert matcher.does_not_match?(response_or_body), message || matcher.failure_message_when_negated
end

#refute_turbo_stream(response_or_body, action: nil, target: nil, targets: nil, content: nil, partial: nil, message: nil) ⇒ Object



45
46
47
48
# File 'lib/turbo_rspec/assertions.rb', line 45

def refute_turbo_stream(response_or_body, action: nil, target: nil, targets: nil, content: nil, partial: nil, message: nil)
  matcher = build_stream_matcher(action: action, target: target, targets: targets, content: content, partial: partial)
  assert matcher.does_not_match?(response_or_body), message || matcher.failure_message_when_negated
end