Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 控制器规范中的存根身份验证-映射_Ruby On Rails_Rspec_Devise - Fatal编程技术网

Ruby on rails 控制器规范中的存根身份验证-映射

Ruby on rails 控制器规范中的存根身份验证-映射,ruby-on-rails,rspec,devise,Ruby On Rails,Rspec,Devise,我试图遵循此指南,但我有以下错误: 找不到# 助手代码: def sign_in(user = double('user')) if user.nil? allow(request.env['warden']).to receive(:authenticate!).and_throw(:warden, {:scope => :user}) allow(controller).to receive(:current_user).and_return(ni

我试图遵循此指南,但我有以下错误:


找不到#

助手代码:

  def sign_in(user = double('user'))
    if user.nil?
      allow(request.env['warden']).to receive(:authenticate!).and_throw(:warden, {:scope => :user})
      allow(controller).to receive(:current_user).and_return(nil)
    else
      allow(request.env['warden']).to receive(:authenticate!).and_return(user)
      allow(controller).to receive(:current_user).and_return(user)
    end
  end
我的测试有:

before do
   sign_in
end
我做错了什么


谢谢

您能发布您在测试中使用的实际代码吗?问题中包含代码。
用户
是您在
设计
中使用的唯一型号,还是您在
设计
中也有
管理员
型号或类似型号?另外,您的
routes.rb
文件中是否有
design_:users
?是的,只有用户模型。如果我使用类似于facture.create(:user)的东西而不是double,它会工作得很好