Ruby 未定义的方法“存根”连接';ActionCable信道的RSpec测试
我有以下测试:Ruby 未定义的方法“存根”连接';ActionCable信道的RSpec测试,ruby,rspec,ruby-on-rails-5,actioncable,Ruby,Rspec,Ruby On Rails 5,Actioncable,我有以下测试: 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).t
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)>'
故障/错误:存根\u连接当前\u用户:user.first
命名错误:
未定义的方法“存根连接”#
#./spec/channels/my_channel_spec.rb:7:in'block(2层)in'
根据我发现的所有示例,stub\u连接
应该在RSpec通道测试中自动可用。我做错了什么?我需要安装。在我写这个答案的时候,这个gem的功能是
之后,请确保:
RSpec用法
首先,您需要安装rspec rails
其次,在要求环境.rb
之后,将其添加到您的“rails\u helper.rb”
:
要求“操作\u电缆/测试/rspec”