class ActionCable::TestCase

Public Instance Methods

assert_broadcast_on(stream, data) click to toggle source

Asserts that the specified message has been sent to the stream.

def test_assert_transmitted_message
  ActionCable.server.broadcast 'messages', text: 'hello'
  assert_broadcast_on('messages', text: 'hello')

If a block is passed, that block should cause a message with the specified data to be sent.

def test_assert_broadcast_on_again
  assert_broadcast_on('messages', text: 'hello') do
    ActionCable.server.broadcast 'messages', text: 'hello'

See also Minitest::Rails::Expectations::ActionCable::TestHelper#must_broadcast_on See

# File lib/minitest/rails/assertions/action_cable.rb, line 80
assert_broadcasts(stream, number) click to toggle source

Asserts that the number of broadcasted messages to the stream matches the given number.

def test_broadcasts
  assert_broadcasts 'messages', 0
  ActionCable.server.broadcast 'messages', { text: 'hello' }
  assert_broadcasts 'messages', 1
  ActionCable.server.broadcast 'messages', { text: 'world' }
  assert_broadcasts 'messages', 2

If a block is passed, that block should cause the specified number of messages to be broadcasted.

def test_broadcasts_again
  assert_broadcasts('messages', 1) do
    ActionCable.server.broadcast 'messages', { text: 'hello' }

  assert_broadcasts('messages', 2) do
    ActionCable.server.broadcast 'messages', { text: 'hi' }
    ActionCable.server.broadcast 'messages', { text: 'how are you?' }

See also Minitest::Rails::Expectations::ActionCable::TestHelper#must_have_broadcasts See

# File lib/minitest/rails/assertions/action_cable.rb, line 30