instance method
assert_turbo_stream
Ruby on Rails 1.5.0
Since v1.3.3 Last seen in v2.0.23Signature
assert_turbo_stream(action:, target: nil, targets: nil, count: 1, &block)
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 callingdom_id -
:targets[String] matches the element’s[targets]attribute -
:count[Integer] indicates how many turbo streams are expected. Defaults to1.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
Parameters
-
actionkeyreq -
targetkey = nil -
targetskey = nil -
countkey = 1 -
blockblock
Source
# 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
Defined in lib/turbo/test_assertions.rb line 48
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Turbo::TestAssertions