【发布时间】:2019-04-12 06:48:53
【问题描述】:
我有以下测试:
require "rails_helper"
RSpec.describe MyChannel, type: :channel do
let (:current_user) { User.first }
it "subscribes to a unique room for the user" do
stub_connection current_user: User.first
subscribe
expect(subscription).to be_confirmed
expect(streams).to include("my_channel_#{current_user.id}")
end
end
失败并出现此错误:
Failure/Error: stub_connection current_user: User.first
NoMethodError:
undefined method `stub_connection' for #<RSpec::ExampleGroups::MyChannel:0x00000000deadbeef>
# ./spec/channels/my_channel_spec.rb:7:in `block (2 levels) in <top (required)>'
根据the documentation 和我发现的所有示例,stub_connection 应该在 RSpec 通道测试中自动可用。我做错了什么?
【问题讨论】:
标签: ruby rspec ruby-on-rails-5 actioncable