Module: Turbo::TestAssertions::IntegrationTestAssertions

Defined in:
lib/turbo/test_assertions/integration_test_assertions.rb

Instance Method Summary collapse

Instance Method Details

#assert_no_turbo_stream(status: :ok, **attributes) ⇒ Object

Assert that the Turbo Stream request's response body's HTML does not contain a <turbo-stream> element.

Options

  • :status [Integer, Symbol] the HTTP response status

  • :action [String] matches the element's [action] attribute

  • :target [String, #to_key] matches the element's [target] attribute. If the value responds to #to_key, the value will be transformed by calling dom_id

  • :targets [String] matches the element's [targets] attribute

    Given the following HTML response body:

    <turbo-stream action="remove" target="message_1"></turbo-stream>
    

    The following assertion would fail:

    assert_no_turbo_stream action: "remove", target: "message_1"


69
70
71
72
73
# File 'lib/turbo/test_assertions/integration_test_assertions.rb', line 69

def assert_no_turbo_stream(status: :ok, **attributes)
  assert_response status
  assert_equal Mime[:turbo_stream], response.media_type
  super(**attributes)
end

#assert_turbo_stream(status: :ok, **attributes, &block) ⇒ Object

Assert that the Turbo Stream request's response body's HTML contains a <turbo-stream> element.

Options

  • :status [Integer, Symbol] the HTTP response status

  • :action [String] matches the element's [action] attribute

  • :target [String, #to_key] matches the element's [target] attribute. If the value responds to #to_key, the value will be transformed by calling dom_id

  • :targets [String] matches the element's [targets] attribute

    Given the following HTML response body:

    <turbo-stream action="remove" target="message_1"></turbo-stream>
    

    The following assertion would pass:

    assert_turbo_stream action: "remove", target: "message_1"
    

You can also pass a block make assertions about the contents of the element. Given the following HTML response body:

<turbo-stream action="replace" target="message_1">
  <template>
    <p>Hello!</p>
  <template>
</turbo-stream>

The following assertion would pass:

assert_turbo_stream action: "replace", target: "message_1" do
  assert_select "template p", text: "Hello!"
end


41
42
43
44
45
# File 'lib/turbo/test_assertions/integration_test_assertions.rb', line 41

def assert_turbo_stream(status: :ok, **attributes, &block)
  assert_response status
  assert_equal Mime[:turbo_stream], response.media_type
  super(**attributes, &block)
end