,当我试图当一个请求到/auth/facebook
制成,如描述here和here提供伪造的认证哈希来测试我的OmniAuth登录过程不将请求重定向。问题是,当我打开测试模式时,请求返回为错误,这与未打开测试模式时的行为相同。打开在OmniAuth测试模式下使用黄瓜
user_management.feature
Feature: User management
@omniauth_test
Scenario: Login
Given a user exists
And that user is signed in
web_steps.rb
...
And /^that user is signed in$/ do
visit "/auth/facebook"
end
...
omniauth.rb
Before('@omniauth_test') do
OmniAuth.config.test_mode = true
p "OmniAuth.config.test_mode is #{OmniAuth.config.test_mode}"
# the symbol passed to mock_auth is the same as the name of the provider set up in the initializer
OmniAuth.config.mock_auth[:facebook] = {
"provider"=>"facebook",
"uid"=>"uid",
"user_info"=>{"email"=>"[email protected]", "first_name"=>"Test", "last_name"=>"User", "name"=>"Test User"}
}
end
After('@omniauth_test') do
OmniAuth.config.test_mode = false
end
成果
Feature: User management
@omniauth_test
Scenario: Login # features/user_management.feature:3
"OmniAuth.config.test_mode is true"
Given a user exists # features/step_definitions/pickle_steps.rb:4
And that user is signed in # features/step_definitions/web_steps.rb:40
No route matches [GET] "/auth/facebook" (ActionController::RoutingError)
./features/step_definitions/web_steps.rb:41:in `/^that user is signed in$/'
features/testing.feature:5:in `And that user is signed in'