失败/错误:expect(response.status).to eq(200)rspec

r1zhe5dt  于 2021-09-29  发布在  Java
关注(0)|答案(1)|浏览(370)

在使用in sessions请求测试登录用户后,我总是得到302重定向

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

       expected: 200
            got: 302

规范/请求/会话\u规范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

配置:spec_helper.rb

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

x9ybnkn61#

解决方案是在报头中提供令牌

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

以及删除登录名

相关问题