mirror of https://github.com/rails/rails
Merge pull request #47204 from StephaneRob/feat-improve-assert-broadcast-on-message
feat: improve `assert_broadcast_on` error message
This commit is contained in:
commit
3d0d027bfd
|
@ -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.
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue