跳至內容 跳至搜尋

Test adapter for Action Cable

test adapter 只能用於測試。與 ActionCable::TestHelper 結合使用,是測試 Rails 應用程式的絕佳工具。

若要使用 test adapter,請在 config/cable.yml 檔案中將 adapter 值設定為 test

注意:Test adapter 延伸 ActionCable::SubscriptionAdapter::Async adapter,因此也可以用於系統測試。

方法
B
C

執行個體公開方法

broadcast(channel, payload)

# File actioncable/lib/action_cable/subscription_adapter/test.rb, line 18
def broadcast(channel, payload)
  broadcasts(channel) << payload
  super
end

broadcasts(channel)

# File actioncable/lib/action_cable/subscription_adapter/test.rb, line 23
def broadcasts(channel)
  channels_data[channel] ||= []
end

clear()

# File actioncable/lib/action_cable/subscription_adapter/test.rb, line 31
def clear
  @channels_data = nil
end

clear_messages(channel)

# File actioncable/lib/action_cable/subscription_adapter/test.rb, line 27
def clear_messages(channel)
  channels_data[channel] = []
end