Module: Turbo::TestAssertions
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/turbo/test_assertions.rb,
lib/turbo/test_assertions/integration_test_assertions.rb
Defined Under Namespace
Modules: IntegrationTestAssertions
Instance Method Summary collapse
-
#assert_no_turbo_frame(*ids, **options, &block) ⇒ Object
Assert that the rendered fragment of HTML does not contain a
<turbo-frame>element. -
#assert_no_turbo_stream(action:, target: nil, targets: nil) ⇒ Object
Assert that the rendered fragment of HTML does not contain a
<turbo-stream>element. -
#assert_turbo_frame(*ids, loading: nil, src: nil, target: nil, count: 1, &block) ⇒ Object
Assert that the rendered fragment of HTML contains a
<turbo-frame>element. -
#assert_turbo_stream(action:, target: nil, targets: nil, count: 1, &block) ⇒ Object
Assert that the rendered fragment of HTML contains a
<turbo-stream>element.
Instance Method Details
#assert_no_turbo_frame(*ids, **options, &block) ⇒ Object
Assert that the rendered fragment of HTML does not contain a <turbo-frame>
element.
Arguments
- ids [String, Array<String, ActiveRecord::Base>] matches the [id] attribute
Options
-
:loading [String] matches the element's [loading] attribute
-
:src [String] matches the element's [src] attribute
-
:target [String] matches the element's [target] attribute
Given the following HTML fragment:
<turbo-frame id="example" target="_top"></turbo-frame>The following assertion would fail:
assert_no_turbo_frame id: "example", target: "_top"
153 154 155 |
# File 'lib/turbo/test_assertions.rb', line 153 def assert_no_turbo_frame(*ids, **, &block) assert_turbo_frame(*ids, **, count: 0, &block) end |
#assert_no_turbo_stream(action:, target: nil, targets: nil) ⇒ Object
Assert that the rendered fragment of HTML does not contain a <turbo-stream>
element.
Options
-
: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 fragment:
<turbo-stream action="remove" target="message_1"></turbo-stream>The following assertion would fail:
assert_no_turbo_stream action: "remove", target: "message_1"
76 77 78 79 80 81 |
# File 'lib/turbo/test_assertions.rb', line 76 def assert_no_turbo_stream(action:, target: nil, targets: nil) selector = %(turbo-stream[action="#{action}"]) selector << %([target="#{target.respond_to?(:to_key) ? dom_id(target) : target}"]) if target selector << %([targets="#{targets}"]) if targets assert_select selector, count: 0 end |
#assert_turbo_frame(*ids, loading: nil, src: nil, target: nil, count: 1, &block) ⇒ Object
Assert that the rendered fragment of HTML contains a <turbo-frame>
element.
Arguments
- ids [String, Array<String, ActiveRecord::Base>] matches the element's [id] attribute
Options
-
:loading [String] matches the element's [loading] attribute
-
:src [String] matches the element's [src] attribute
-
:target [String] matches the element's [target] attribute
-
:count [Integer] indicates how many turbo frames are expected. Defaults to 1.
Given the following HTML fragment:
<turbo-frame id="example" target="_top"></turbo-frame>The following assertion would pass:
assert_turbo_frame id: "example", target: "_top"
You can also pass a block make assertions about the contents of the element. Given the following HTML fragment:
<turbo-frame id="example">
<p>Hello!</p>
</turbo-frame>
The following assertion would pass:
assert_turbo_frame id: "example" do
assert_select "p", text: "Hello!"
end
121 122 123 124 125 126 127 128 |
# File 'lib/turbo/test_assertions.rb', line 121 def assert_turbo_frame(*ids, loading: nil, src: nil, target: nil, count: 1, &block) id = ids.first.respond_to?(:to_key) ? ActionView::RecordIdentifier.dom_id(*ids) : ids.join('_') selector = %(turbo-frame[id="#{id}"]) selector << %([loading="#{loading}"]) if loading selector << %([src="#{src}"]) if src selector << %([target="#{target}"]) if target assert_select selector, count: count, &block end |
#assert_turbo_stream(action:, target: nil, targets: nil, count: 1, &block) ⇒ Object
Assert that the rendered fragment of HTML contains a <turbo-stream>
element.
Options
-
: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
-
:count [Integer] indicates how many turbo streams are expected. Defaults to 1.
Given the following HTML fragment:
<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 fragment:
<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
48 49 50 51 52 53 |
# File 'lib/turbo/test_assertions.rb', line 48 def assert_turbo_stream(action:, target: nil, targets: nil, count: 1, &block) selector = %(turbo-stream[action="#{action}"]) selector << %([target="#{target.respond_to?(:to_key) ? dom_id(target) : target}"]) if target selector << %([targets="#{targets}"]) if targets assert_select selector, count: count, &block end |