如何在 rspec 上没有监狱长回调的情况下登录(请求规范)
How to sign in without warden callback on rspec (request spec)
我想根据请求规范致电 sign_in(user)
,无需 warden 回电。
有人知道解决方法吗?
我想根据要求规范使用 bypass_sign_in 之类的东西。
我在下面试过了。
- 我将
Devise::Test::IntegrationHelpers
添加到我的 spec/rails_helper.rb
config.include Devise::Test::IntegrationHelpers, type: :feature
- 2-a。我这样写请求规范。
有用。但它会调用 warden 回调
RSpec.describe '/ajax/stores', type: :request do
context 'login as valid user' do
it do
sign_in(user)
end
end
end
- 2-b。我使用
login_as
(监狱长的方法)写请求另一个规范,但它也调用监狱长回调
RSpec.describe '/ajax/stores', type: :request do
context 'login as valid user' do
it do
login_as(user, bypass: true)
end
end
end
您可以将 run_callbacks: false
选项传递给 Warden 的 login_as
助手:
login_as(user, run_callbacks: false)
我想根据请求规范致电 sign_in(user)
,无需 warden 回电。
有人知道解决方法吗?
我想根据要求规范使用 bypass_sign_in 之类的东西。
我在下面试过了。
- 我将
Devise::Test::IntegrationHelpers
添加到我的 spec/rails_helper.rb
- 我将
config.include Devise::Test::IntegrationHelpers, type: :feature
- 2-a。我这样写请求规范。 有用。但它会调用 warden 回调
RSpec.describe '/ajax/stores', type: :request do
context 'login as valid user' do
it do
sign_in(user)
end
end
end
- 2-b。我使用
login_as
(监狱长的方法)写请求另一个规范,但它也调用监狱长回调
RSpec.describe '/ajax/stores', type: :request do
context 'login as valid user' do
it do
login_as(user, bypass: true)
end
end
end
您可以将 run_callbacks: false
选项传递给 Warden 的 login_as
助手:
login_as(user, run_callbacks: false)