使用 Cucumber 时,在 OmniAuth 中打开测试模式不会重定向请求
我正在尝试通过在向 OmniAuth 登录过程>/auth/facebook
,如此处和此处。问题是,当我打开测试模式时,请求作为错误返回,这与未打开测试模式时的行为相同。
user_management.feature
Feature: User management
@omniauth_test
Scenario: Login
Given a user exists
And that user is signed in
web_steps.rbomniauth.rb
...
And /^that user is signed in$/ do
visit "/auth/facebook"
end
...
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'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该将这两个放入测试初始值设定项中:
You should throw these two in an test initializer:
在 features/support 下的omniauth.rb中添加以下内容,并标记需要使用@omniauth_test进行fb登录的场景
Throw the following in omniauth.rb under features/support and mark your scenario which requires fb login with @omniauth_test
问题不在于你的测试。它与您的路由有关,或更具体地说与omniauths 路由有关。
您确定在 config/initializers/omniauth.rb 中为 facebook 设置了策略吗?
你可以用 gemform 获取它 https://github.com/mkdynamic/omniauth-facebook
另外,添加新策略后请记住重新启动网络服务器。 (这让我有一次;))
The problem is not with your tests. It's with your routing, or more specifically with omniauths routing.
Are you sure that you have a strategy set up in config/initializers/omniauth.rb for facebook?
You can get it in gemform https://github.com/mkdynamic/omniauth-facebook
Also, remember to restart your webserver after adding a new strategy. (That got me once ;))