- A
- P
- S
- T
- U
常量
CHANNEL_IDENTIFIER | = | "test_stub" |
属性
[R] | connection | |
[R] | subscription |
实例公共方法
assert_broadcast_on(stream_or_object, *args) 链接
来源:显示 | 在 GitHub 上
# 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
assert_broadcasts(stream_or_object, *args) 链接
增强 TestHelper
断言以处理非字符串广播
来源:显示 | 在 GitHub 上
# 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
assert_has_stream(stream) 链接
断言已启动指定流。
def test_assert_started_stream
subscribe
assert_has_stream 'messages'
end
来源:显示 | 在 GitHub 上
# 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
assert_has_stream_for(object) 链接
断言模型的指定流已启动。
def test_assert_started_stream_for
subscribe id: 42
assert_has_stream_for User.find(42)
end
来源:显示 | 在 GitHub 上
# File actioncable/lib/action_cable/channel/test_case.rb, line 311 def assert_has_stream_for(object) assert_has_stream(broadcasting_for(object)) end
assert_no_streams() 链接
断言没有启动任何流。
def test_assert_no_started_stream
subscribe
assert_no_streams
end
来源:显示 | 在 GitHub 上
# 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
perform(action, data = {}) 链接
在频道上执行操作。
注意:必须订阅。
来源:显示 | 在 GitHub 上
# 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
stub_connection(identifiers = {}) 链接
使用指定的标识符设置测试连接
class ApplicationCable < ActionCable::Connection::Base
identified_by :user, :token
end
stub_connection(user: users[:john], token: 'my-secret-token')
来源:显示 | 在 GitHub 上
# File actioncable/lib/action_cable/channel/test_case.rb, line 239 def stub_connection(identifiers = {}) @connection = ConnectionStub.new(identifiers) end
subscribe(params = {}) 链接
订阅正在测试的频道。可以选择将订阅参数作为 Hash
传递。
来源:显示 | 在 GitHub 上
# 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
transmissions() 链接
返回传输到频道中的消息
来源:显示 | 在 GitHub 上
# 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
取消订阅() 链接
取消正在测试的订阅。
来源:显示 | 在 GitHub 上
# File actioncable/lib/action_cable/channel/test_case.rb, line 253 def unsubscribe check_subscribed! subscription.unsubscribe_from_channel end