Basic example

First, one uses the subscribe method to simulate subscription
creation.

Then, one asserts whether the current state is as expected. “State” can be
anything: transmitted messages, subscribed streams, etc.

For example:

class ChatChannelTest < ActionCable::Channel::TestCase
def test_subscribed_with_room_number
# Simulate a subscription creation
subscribe room_number: 1
# Asserts that the subscription was successfully created
assert subscription.confirmed?
# Asserts that the channel subscribes connection to a stream
assert_has_stream "chat_1"
# Asserts that the channel subscribes connection to a specific
# stream created for a model
assert_has_stream_for Room.find(1)
end
def test_does_not_stream_with_incorrect_room_number
subscribe room_number: -1
# Asserts that not streams was started
assert_no_streams
end
def test_does_not_subscribe_without_room_number
subscribe
# Asserts that the subscription was rejected
assert subscription.rejected?
end
end

ActionCable::Channel::TestCase will
automatically infer the channel under test from the test class name. If the
channel cannot be inferred from the test class name, you can explicitly set
it with tests.