Merge pull request #47204 from StephaneRob/feat-improve-assert-broadcast-on-message

feat: improve `assert_broadcast_on` error message
This commit is contained in:
Jean Boussier 2023-02-05 00:24:46 +01:00 committed by GitHub
commit 3d0d027bfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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