# File actioncable/lib/action_cable/test_helper.rb, line 116
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?
new_messages = new_broadcasts_from(new_messages, stream, "assert_broadcast_on", &block)
end
message = new_messages.find { |msg| ActiveSupport::JSON.decode(msg) == serialized_msg }
error_message = "No messages sent with #{data} to #{stream}"
if new_messages.any?
error_message = new_messages.inject("#{error_message}\nMessage(s) found:\n") do |error_message, new_message|
error_message + "#{ActiveSupport::JSON.decode(new_message)}\n"
end
else
error_message = "#{error_message}\nNo message found for #{stream}"
end
assert message, error_message
end