instance method
assert_turbo_stream_broadcasts
Ruby on Rails 1.5.0
Since v1.5.0 Last seen in v2.0.23Available in: v1.5.0 v2.0.23
Signature
assert_turbo_stream_broadcasts(stream_name_or_object, count: nil, &block)
Asserts that ‘<turbo-stream>` elements were broadcast over Action Cable
Arguments
-
stream_name_or_objectthe objects used to generate the channel Action Cable name, or the name itself -
&blockoptional block executed before the assertion
Options
-
count:the number of ‘<turbo-stream>` elements that are
expected to be broadcast
Asserts ‘<turbo-stream>` elements were broadcast:
message = Message.find(1) message.broadcast_replace_to "messages" assert_turbo_stream_broadcasts "messages"
Asserts that two ‘<turbo-stream>` elements were broadcast:
message = Message.find(1) message.broadcast_replace_to "messages" message.broadcast_remove_to "messages" assert_turbo_stream_broadcasts "messages", count: 2
You can pass a block to run before the assertion:
message = Message.find(1) assert_turbo_stream_broadcasts "messages" do message.broadcast_append_to "messages" end
In addition to a String, the helper also accepts an Object or Array to determine the name of the channel the elements are broadcast to:
message = Message.find(1) assert_turbo_stream_broadcasts message do message.broadcast_replace end
Parameters
-
stream_name_or_objectreq -
countkey = nil -
blockblock
Source
# File lib/turbo/broadcastable/test_helper.rb, line 58
def assert_turbo_stream_broadcasts(stream_name_or_object, count: nil, &block)
payloads = capture_turbo_stream_broadcasts(stream_name_or_object, &block)
stream_name = stream_name_from(stream_name_or_object)
if count.nil?
assert_not_empty payloads, "Expected at least one broadcast on #{stream_name.inspect}, but there were none"
else
broadcasts = "Turbo Stream broadcast".pluralize(count)
assert count == payloads.count, "Expected #{count} #{broadcasts} on #{stream_name.inspect}, but there were none"
end
end
Defined in lib/turbo/broadcastable/test_helper.rb line 58
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Turbo::Broadcastable::TestHelper