ruby - 如何测试 ActionCable 连接?
问题描述
如何Connection
在 RSpec 中为 ActionCable 编写测试?我找到了有关 testing的文档和其他 问题Channel
,但是我很难找到有关 testing的信息Connection
。
解决方案
action-cable-testing gem包括对 testing的支持Connection
。这是文档:https ://github.com/palkan/action-cable-testing#rspec-usage
这是文档中给出的 RSpec 示例:
require "rails_helper"
RSpec.describe ApplicationCable::Connection, type: :channel do
it "successfully connects" do
connect "/cable", headers: { "X-USER-ID" => "325" }
expect(connection.user_id).to eq "325"
end
it "rejects connection" do
expect { connect "/cable" }.to have_rejected_connection
end
end
推荐阅读
- ios - 如何将标签文本添加到 tableViewCell
- react-virtualized - React-virtualized - 是否可以使用自定义列?
- rxjs - 用于组合 RxJS Observables 的布尔代数助手
- java - 使用两个堆栈来计算中缀表达式
- android - android dev.中是否需要布尔代数知识?
- python - 即使最后一个命令(但不是第一个命令)引发异常,Try 块也会给出输出
- git - PR中推送分支的Git回滚/删除
- reactjs - 构造函数中的 Prop-Type 检查
- python-requests - 使用 python 请求授权
- c# - Servicestack 可以在没有命名空间的情况下反序列化 XML