class ActionCable::Channel::TestCase

end
end
perform :speak, message: “Hello, Rails!”
assert_broadcast_on(rooms(:chat), text: “Hello, Rails!”) do
subscribe room_id: rooms(:chat).id
def test_speak
end
broadcast_to room, text: data[“message”]
def speak(data)
# in your channel
assert_broadcasts) to handle broadcasting to models:
ActionCable::Channel::TestCase enhances ActionCable::TestHelper assertions (e.g.
== Testing broadcasting
stub_connection(user: users(:john))
To do this just use:
You need to set up your connection manually to provide values for the identifiers.
== Specifying connection identifiers
end
tests SpecialChannel
class SpecialEdgeCaseChannelTest < ActionCable::Channel::TestCase
class name, you can explicitly set it with tests.
from the test class name. If the channel cannot be inferred from the test
ActionCable::Channel::TestCase will automatically infer the channel under test
== Channel is automatically inferred
A list of all messages that have been transmitted into the channel.
transmissions::
An instance of the current channel, created when you call subscribe.
subscription::
An ActionCable::Channel::ConnectionStub, representing the current HTTP connection.
connection::
methods for use in the tests:
ActionCable::Channel::TestCase will also automatically provide the following instance
== Special methods
end
assert_equal “Hello, Rails!”, transmissions.last[“text”]

perform :speak, message: “Hello, Rails!”
subscribe room_number: 1
def test_perform_speak
You can also perform actions:
end
end
assert subscription.rejected?
# Asserts that the subscription was rejected
subscribe
def test_does_not_subscribe_without_room_number
end
assert_no_streams
# Asserts that not streams was started
subscribe room_number: -1
def test_does_not_stream_with_incorrect_room_number
end
assert_has_stream_for Room.find(1)
# stream created for a model
# Asserts that the channel subscribes connection to a specific
assert_has_stream “chat_1”
# Asserts that the channel subscribes connection to a stream
assert subscription.confirmed?
# Asserts that the subscription was successfully created
subscribe room_number: 1
# Simulate a subscription creation
def test_subscribed_with_room_number
class ChatChannelTest < ActionCable::Channel::TestCase
For example:
transmitted messages, subscribed streams, etc.
2. Then, one asserts whether the current state is as expected. “State” can be anything:
1. First, one uses the subscribe method to simulate subscription creation.
Functional tests are written as follows:
== Basic example
Superclass for Action Cable channel functional tests.