如何测试 ActionCable 连接?
How do I test an ActionCable connection?
如何在 RSpec 中为 ActionCable Connection
编写测试?我发现 documentation and 关于测试 Channel
s,但我很难找到关于测试 Connection
s 的信息。
action-cable-testing gem includes support for testing Connection
s. Here's the documentation: 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
如何在 RSpec 中为 ActionCable Connection
编写测试?我发现 documentation and Channel
s,但我很难找到关于测试 Connection
s 的信息。
action-cable-testing gem includes support for testing Connection
s. Here's the documentation: 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