module ActionCable::Channel::TestCase::Behavior

def assert_broadcast_on(stream_or_object, *args)

def assert_broadcast_on(stream_or_object, *args)
  super(broadcasting_for(stream_or_object), *args)
end

def assert_broadcasts(stream_or_object, *args)

broadcastings
Enhance TestHelper assertions to handle non-String
def assert_broadcasts(stream_or_object, *args)
  super(broadcasting_for(stream_or_object), *args)
end

def assert_has_stream(stream)


end
assert_has_stream 'messages'
subscribe
def test_assert_started_stream

Asserts that the specified stream has been started.
def assert_has_stream(stream)
  assert subscription.streams.include?(stream), "Stream #{stream} has not been started"
end

def assert_has_stream_for(object)


end
assert_has_stream_for User.find(42)
subscribe id: 42
def test_assert_started_stream_for

Asserts that the specified stream for a model has started.
def assert_has_stream_for(object)
  assert_has_stream(broadcasting_for(object))
end

def assert_no_streams


end
assert_no_streams
subscribe
def test_assert_no_started_stream

Asserts that no streams have been started.
def assert_no_streams
  assert subscription.streams.empty?, "No streams started was expected, but #{subscription.streams.count} found"
end

def broadcasting_for(stream_or_object)

def broadcasting_for(stream_or_object)
  return stream_or_object if stream_or_object.is_a?(String)
  self.class.channel_class.broadcasting_for(stream_or_object)
end

def check_subscribed!

def check_subscribed!
  raise "Must be subscribed!" if subscription.nil? || subscription.rejected?
end

def perform(action, data = {})

NOTE: Must be subscribed.

Perform action on a channel.
def perform(action, data = {})
  check_subscribed!
  subscription.perform_action(data.stringify_keys.merge("action" => action.to_s))
end

def stub_connection(identifiers = {})

stub_connection(user: users[:john], token: 'my-secret-token')

end
identified_by :user, :token
class ApplicationCable < ActionCable::Connection::Base

Set up test connection with the specified identifiers:
def stub_connection(identifiers = {})
  @connection = ConnectionStub.new(identifiers)
end

def subscribe(params = {})

Subscribe to the channel under test. Optionally pass subscription parameters as a Hash.
def subscribe(params = {})
  @connection ||= stub_connection
  @subscription = self.class.channel_class.new(connection, CHANNEL_IDENTIFIER, params.with_indifferent_access)
  @subscription.singleton_class.include(ChannelStub)
  @subscription.subscribe_to_channel
  @subscription
end

def transmissions

Returns messages transmitted into channel
def transmissions
  # Return only directly sent message (via #transmit)
  connection.transmissions.map { |data| data["message"] }.compact
end

def unsubscribe

Unsubscribe the subscription under test.
def unsubscribe
  check_subscribed!
  subscription.unsubscribe_from_channel
end