We use Rails 6.1 API application with devise
and devise-jwt
. I tried to write a feature spec using RSpec for sign_in
method but could not write. I have the following in my rails_helper.rb
config.include Devise::Test::ControllerHelpers, type: :controller
config.include Devise::Test::ControllerHelpers, type: :view
config.include Devise::Test::IntegrationHelpers, type: :request
config.include Devise::Test::IntegrationHelpers, type: :feature
config.extend ControllerMacros, :type => :controller
config.include Warden::Test::Helpers
Warden.test_mode!
config.include FactoryBot::Syntax::Methods
and the spec under spec/requests/users/sessions_controller_spec.rb
is
context 'When logging in' do
before do
request.env["devise.mapping"] = Devise.mappings[:user]
user = FactoryBot.create(:user)
sign_in user
end
it 'returns a token' do
expect(response.headers['Authorization']).to be_present
end
it 'returns 200' do
expect(response.status).to eq(200)
end
end
But still not able to succeed any idea?