модуль ActionCable::Channel::TestCase::Behavior
Константы
- CHANNEL_IDENTIFIER
Атрибуты
connection[R]
subscription[R]
Открытые методы экземпляров
# 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
Вызов метода суперкласса
ActionCable::TestHelper#assert_broadcast_on # 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
Расширение утверждений TestHelper для обработки нестроковых трансляций
Вызов метода суперкласса
ActionCable::TestHelper#assert_broadcasts # 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 Утверждает, что указанный поток был запущен.
def test_assert_started_stream subscribe assert_has_stream 'messages' end
# File actioncable/lib/action_cable/channel/test_case.rb, line 311 def assert_has_stream_for(object) assert_has_stream(broadcasting_for(object)) end
Утверждает, что указанный поток для модели был запущен.
def test_assert_started_stream_for subscribe id: 42 assert_has_stream_for User.find(42) end
# 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 Утверждает, что потоки не были запущены.
def test_assert_no_started_stream subscribe assert_no_streams end
# 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 Выполнить действие на канале.
ПРИМЕЧАНИЕ: Необходимо подписаться.
# File actioncable/lib/action_cable/channel/test_case.rb, line 239
def stub_connection(identifiers = {})
@connection = ConnectionStub.new(identifiers)
end Настройка тестового подключения со следующими идентификаторами:
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 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 Подписаться на канал для тестирования. При необходимости передать параметры подписки как Hash.
# 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 Возвращает сообщения, переданные в канал
# File actioncable/lib/action_cable/channel/test_case.rb, line 253 def unsubscribe check_subscribed! subscription.unsubscribe_from_channel end
Отписаться от подписки для тестирования.
© 2004–2021 David Heinemeier Hansson
Licensed under the MIT License.