Jake Smith
Jake Smith

Reputation: 2813

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

Upvotes: 3

Views: 119

Answers (1)

Bruno Paulino
Bruno Paulino

Reputation: 5770

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

Upvotes: 1

Related Questions