命名空間
方法
- 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 282 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 278 def assert_broadcasts(stream_or_object, *args) super(broadcasting_for(stream_or_object), *args) end
assert_has_no_stream(stream) 連結
斷言指定的串流尚未啟動。
def test_assert_no_started_stream
subscribe
assert_has_no_stream 'messages'
end
程式碼:顯示 | 在 GitHub 上
# File actioncable/lib/action_cable/channel/test_case.rb, line 326 def assert_has_no_stream(stream) assert subscription.streams.exclude?(stream), "Stream #{stream} has been started" end
assert_has_no_stream_for(object) 連結
斷言模型的指定串流尚未啟動。
def test_assert_no_started_stream_for
subscribe id: 41
assert_has_no_stream_for User.find(42)
end
程式碼:顯示 | 在 GitHub 上
# File actioncable/lib/action_cable/channel/test_case.rb, line 337 def assert_has_no_stream_for(object) assert_has_no_stream(broadcasting_for(object)) 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 304 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 315 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 293 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 266 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 243 def stub_connection(identifiers = {}) @connection = ConnectionStub.new(identifiers) end
subscribe(params = {}) 連結
訂閱測試中的通道。可以選擇以 Hash
的形式傳遞訂閱參數。
程式碼:顯示 | 在 GitHub 上
# File actioncable/lib/action_cable/channel/test_case.rb, line 249 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 272 def transmissions # Return only directly sent message (via #transmit) connection.transmissions.filter_map { |data| data["message"] } end
unsubscribe() 連結
取消訂閱測試中的訂閱。
程式碼:顯示 | 在 GitHub 上
# File actioncable/lib/action_cable/channel/test_case.rb, line 258 def unsubscribe check_subscribed! subscription.unsubscribe_from_channel end