feat: improve assert_broadcast_on error message

This commit is contained in:
StephaneRob 2023-01-31 18:05:10 +01:00
parent 3cca0d5205
commit 1333260e11
3 changed files with 25 additions and 1 deletions

View File

@ -1,3 +1,7 @@
* Display broadcasted messages on error message when using `assert_broadcast_on`
*Stéphane Robino*
* The Action Cable client now supports subprotocols to allow passing arbitrary data
to the server.

View File

@ -116,7 +116,17 @@ module ActionCable
message = new_messages.find { |msg| ActiveSupport::JSON.decode(msg) == serialized_msg }
assert message, "No messages sent with #{data} to #{stream}"
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
def pubsub_adapter # :nodoc:

View File

@ -112,5 +112,15 @@ class TransmittedDataTest < ActionCable::TestCase
end
assert_match(/No messages sent/, error.message)
assert_match(/Message\(s\) found:\nhello/, error.message)
end
def test_assert_broadcast_on_message_with_empty_channel
error = assert_raises Minitest::Assertion do
assert_broadcast_on("test", "world")
end
assert_match(/No messages sent/, error.message)
assert_match(/No message found for test/, error.message)
end
end