# File actioncable/lib/action_cable/test_helper.rb, line 97
def assert_broadcast_on(stream, data, &block)
# Encode to JSON and backâwe want to use this value to compare
# with decoded JSON.
# Comparing JSON strings doesn't work due to the order if the keys.
serialized_msg =
ActiveSupport::JSON.decode(ActiveSupport::JSON.encode(data))
new_messages = broadcasts(stream)
if block_given?
old_messages = new_messages
clear_messages(stream)
assert_nothing_raised(&block)
new_messages = broadcasts(stream)
clear_messages(stream)
# Restore all sent messages
(old_messages + new_messages).each { |m| pubsub_adapter.broadcast(stream, m) }
end
message = new_messages.find { |msg| ActiveSupport::JSON.decode(msg) == serialized_msg }
assert message, "No messages sent with #{data} to #{stream}"
end