Failure/Error: expect(response.status).to eq(200) rspec

1k views Asked by At

i always get 302 redirect after sign_in user with in sessions request test

Failure/Error: expect(response.status).to eq(200)
     
       expected: 200
            got: 302

spec/requests/sessions_spec.rb

  describe do
   let!(:user) { create(:user) }

    context do
      before { sign_in user }

      it do
        get api_users_path
        expect(response.status).to eq(200)
      end
    end
  end

config: spec_helper.rb

  config.include Devise::Test::IntegrationHelpers, type: :request
  config.include Warden::Test::Helpers, type: :request
1

There are 1 answers

0
Almokhtar On

The solution is by providing Token in headers

request.headers['HTTP_ACCEPT'] = 'application/json'
request.headers['Authorization'] = token

and removing sign_in