如何在RSpec中为ActionCable Connection
编写测试?我已经发现documentation和other questions有关测试Channel
的信息,但是我很难找到有关测试Connection
的信息。>
答案 0 :(得分:1)
action-cable-testing gem支持测试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