module Minitest::Rails::Expectations::ActionCable::TestHelper

Public Instance Methods

must_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'
  must_broadcast_on('messages', text: 'hello')
end

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

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

See also ActionCable::TestHelper#assert_broadcast_on See api.rubyonrails.org/v6.1/classes/ActionCable/TestHelper.html#method-i-assert_broadcast_on

# File lib/minitest/rails/expectations/action_cable.rb, line 88
extend ::ActiveSupport::Concern
must_have_broadcasts(stream, number) click to toggle source

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

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

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

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

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

See also ActionCable::TestHelper#assert_broadcasts See api.rubyonrails.org/v6.1/classes/ActionCable/TestHelper.html#method-i-assert_broadcasts

# File lib/minitest/rails/expectations/action_cable.rb, line 39
          
wont_have_broadcasts(stream, &block) click to toggle source

Asserts that no messages have been sent to the stream.

def test_no_broadcasts
  wont_have_broadcasts 'messages'
  ActionCable.server.broadcast 'messages', { text: 'hi' }
  must_have_broadcasts 'messages', 1
end

If a block is passed, that block should not cause any message to be sent.

def test_broadcasts_again
  wont_have_broadcasts 'messages' do
    # No job messages should be sent from this block
  end
end

Note: This assertion is simply a shortcut for:

must_have_broadcasts 'messages', 0, &block

See also ActionCable::TestHelper#wont_have_broadcasts See api.rubyonrails.org/v6.1/classes/ActionCable/TestHelper.html#method-i-assert_no_broadcasts

# File lib/minitest/rails/expectations/action_cable.rb, line 66