Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.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 使用rspec、设备和感知用户_Ruby On Rails_Devise_Rspec2 - Fatal编程技术网

Ruby on rails 使用rspec、设备和感知用户

Ruby on rails 使用rspec、设备和感知用户,ruby-on-rails,devise,rspec2,Ruby On Rails,Devise,Rspec2,我正在使用Desive和Senient_用户Gem-。 当我在模型中使用当前用户时,它可以正常工作。 问题是我的Rspec测试失败了。 在我的Rspec测试中 describe MyModelWhereIUseCurrentUser do include Devise::TestHelpers before(:each) do @user = Factory(:user) sign_in @user end describe "

我正在使用Desive和Senient_用户Gem-。 当我在模型中使用当前用户时,它可以正常工作。 问题是我的Rspec测试失败了。 在我的Rspec测试中

  describe MyModelWhereIUseCurrentUser do

    include Devise::TestHelpers

    before(:each) do 
      @user = Factory(:user)
      sign_in @user
    end 

   describe "current_user should work here" do 
     it "should do something" do 
       # Reference to MyModelWhereIUseCurrentUser and current_user is null there
     end
   end 
 end
然后在descripe块中,我调用了我使用的模型 当前用户。 我的测试失败,因为当前用户为零。
我没有正确登录用户,或者问题出在Senient_用户上?

Senient_用户添加了一个
使_成为当前的
方法,可以在用户实例上调用该方法。您的问题可以通过添加
@user来解决。将_设置为当前
到块前