Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise sign_in method throws NoMethodError in RSpec test

The Devise sign_in method is supposed to accept store: false as a second parameter, which it seems to do that fine unless I'm in RSpec and using the Devise::TestHelpers.

When I run this test from sessions_controller_spec.rb:

require 'rails_helper'
describe Api::V1::SessionsController do
  before(:each) do
    @user = FactoryGirl.create :user
  end
  ...
  describe 'DELETE #destroy' do
    before(:each) do
      sign_in @user, store: false
      delete :destroy, id: @user.auth_token
    end
    it { should respond_with 204 }
  end
end

I get this failure: enter image description here

like image 510
Jake Smith Avatar asked Dec 11 '25 21:12

Jake Smith


1 Answers

I have got the same problem. According to Devise website, there is no such method. Try to remove the "store: false" parameter and run it again. It solved my problem.

...
describe 'DELETE #destroy' do
before(:each) do
  sign_in @user
  delete :destroy, id: @user.auth_token
end
it { should respond_with 204 }
...

And remember to put the following inside a file named spec/support/devise.rb or in your spec/spec_helper.rb (or spec/rails_helper.rb if you are using rspec-rails

RSpec.configure do |config|
  config.include Devise::TestHelpers, type: :controller 
end

Take a look on this link

like image 109
Bruno Paulino Avatar answered Dec 16 '25 00:12

Bruno Paulino



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!