- A
- P
- S
- T
- U
Constants
| CHANNEL_IDENTIFIER | = | "test_stub" |
Attributes
| [R] | subscription | Use testserver (not test_server) to silence “Test is missing assertions: |
| [R] | testserver | Use testserver (not test_server) to silence “Test is missing assertions: |
Instance Public methods
advance_time(seconds) Link
Advances all registered periodic timers by the given number of seconds, firing their blocks for each elapsed interval:
def test_timer subscribe advance_time 5.seconds assert_equal 1, subscription.tick_count end
assert_broadcast_on(stream_or_object, *args) Link
assert_broadcasts(stream_or_object, *args) Link
Enhance TestHelper assertions to handle non-String broadcastings
assert_has_no_stream(stream) Link
Asserts that the specified stream has not been started.
def test_assert_no_started_stream subscribe assert_has_no_stream 'messages' end
assert_has_no_stream_for(object) Link
Asserts that the specified stream for a model has not started.
def test_assert_no_started_stream_for subscribe id: 41 assert_has_no_stream_for User.find(42) end
assert_has_stream(stream) Link
Asserts that the specified stream has been started.
def test_assert_started_stream subscribe assert_has_stream 'messages' end
assert_has_stream_for(object) Link
Asserts that the specified stream for a model has started.
def test_assert_started_stream_for subscribe id: 42 assert_has_stream_for User.find(42) end
assert_no_streams() Link
Asserts that no streams have been started.
def test_assert_no_started_stream subscribe assert_no_streams end
perform(action, data = {}) Link
Perform action on a channel.
NOTE: Must be subscribed.
stub_connection(server: ActionCable.server, **identifiers) Link
Set up test connection with the specified identifiers:
class ApplicationCable < ActionCable::Connection::Base identified_by :user, :token end stub_connection(user: users[:john], token: 'my-secret-token')
# File actioncable/lib/action_cable/channel/test_case.rb, line 207 def stub_connection(server: ActionCable.server, **identifiers) @socket = Connection::TestSocket.new(Connection::TestSocket.build_request(ActionCable.server.config.mount_path || "/cable")) @testserver = Connection::TestServer.new(server) @connection = self.class.connection_class.new(testserver, socket).tap do |conn| identifiers.each do |identifier, val| conn.public_send("#{identifier}=", val) end end end
subscribe(params = {}) Link
Subscribe to the channel under test. Optionally pass subscription parameters as a Hash.
# File actioncable/lib/action_cable/channel/test_case.rb, line 219 def subscribe(params = {}) @connection ||= stub_connection @subscription = self.class.channel_class.new(connection, CHANNEL_IDENTIFIER, params.with_indifferent_access) @subscription.singleton_class.include(ChannelExt) @subscription.subscribe_to_channel @subscription end
transmissions() Link
Returns messages transmitted into channel