Namespace
Module
Methods
- assert_broadcast_on
- assert_broadcasts
- assert_has_stream
- assert_has_stream_for
- assert_no_streams
- perform
- stub_connection
- subscribe
- transmissions
- unsubscribe
Included Modules
Constants
CHANNEL_IDENTIFIER | = | "test_stub" |
Attributes
[R] | connection | |
[R] | subscription |
Instance Public methods
assert_broadcast_on(stream_or_object, *args)
📝 Source code
# File actioncable/lib/action_cable/channel/test_case.rb, line 278
def assert_broadcast_on(stream_or_object, *args)
super(broadcasting_for(stream_or_object), *args)
end
🔎 See on GitHub
assert_broadcasts(stream_or_object, *args)
Enhance TestHelper
assertions to handle non-String broadcastings
📝 Source code
# File actioncable/lib/action_cable/channel/test_case.rb, line 274
def assert_broadcasts(stream_or_object, *args)
super(broadcasting_for(stream_or_object), *args)
end
🔎 See on GitHub
assert_has_stream(stream)
Asserts that the specified stream has been started.
def test_assert_started_stream
subscribe
assert_has_stream 'messages'
end
📝 Source code
# File actioncable/lib/action_cable/channel/test_case.rb, line 300
def assert_has_stream(stream)
assert subscription.streams.include?(stream), "Stream #{stream} has not been started"
end
🔎 See on GitHub
assert_has_stream_for(object)
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
📝 Source code
# File actioncable/lib/action_cable/channel/test_case.rb, line 311
def assert_has_stream_for(object)
assert_has_stream(broadcasting_for(object))
end
🔎 See on GitHub
assert_no_streams()
Asserts that no streams have been started.
def test_assert_no_started_stream
subscribe
assert_no_streams
end
📝 Source code
# File actioncable/lib/action_cable/channel/test_case.rb, line 289
def assert_no_streams
assert subscription.streams.empty?, "No streams started was expected, but #{subscription.streams.count} found"
end
🔎 See on GitHub
perform(action, data = {})
Perform action on a channel.
NOTE: Must be subscribed.
📝 Source code
# File actioncable/lib/action_cable/channel/test_case.rb, line 261
def perform(action, data = {})
check_subscribed!
subscription.perform_action(data.stringify_keys.merge("action" => action.to_s))
end
🔎 See on GitHub
stub_connection(identifiers = {})
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')
📝 Source code
# File actioncable/lib/action_cable/channel/test_case.rb, line 239
def stub_connection(identifiers = {})
@connection = ConnectionStub.new(identifiers)
end
🔎 See on GitHub
subscribe(params = {})
Subscribe to the channel under test. Optionally pass subscription parameters as a Hash
.
📝 Source code
# File actioncable/lib/action_cable/channel/test_case.rb, line 244
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
🔎 See on GitHub
transmissions()
Returns messages transmitted into channel
📝 Source code
# File actioncable/lib/action_cable/channel/test_case.rb, line 267
def transmissions
# Return only directly sent message (via #transmit)
connection.transmissions.filter_map { |data| data["message"] }
end
🔎 See on GitHub
unsubscribe()
Unsubscribe the subscription under test.
📝 Source code
# File actioncable/lib/action_cable/channel/test_case.rb, line 253
def unsubscribe
check_subscribed!
subscription.unsubscribe_from_channel
end
🔎 See on GitHub