设计+ Omniauth - 测试 - 没有路由匹配“/oauth/authorize”

发布于 2024-11-29 14:08:39 字数 1541 浏览 0 评论 0原文

我正在尝试编写 Twitter 和 Facebook 的身份验证测试。我正在使用 Devise 和 Omniauth。当我尝试它时,它工作正常,但我无法通过测试。

我正在遵循说明 ,但它对我来说不够深入,而且我做的事情有点不同(已经有一些代码库)。我有一个用于omniauth_callbacks 和注册的自定义控制器。

我的问题是,当我运行测试时,它显示:

(::) failed steps (::)

No route matches "/oauth/authorize" (ActionController::RoutingError)
<internal:prelude>:10:in `synchronize'
(eval):2:in `click_link'
./features/step_definitions/web_steps.rb:57:in `/^(?:|I )follow "([^"]*)"$/'
features/link_twitter.feature:19:in `And I link twitter'

Failing Scenarios:
cucumber features/link_twitter.feature:16 # Scenario: User links twitter

/oauth/authorize 路由来自哪里以及如何处理?

它看起来并没有到达我的 OmniauthCallbacksController 。它跟随链接然后死掉。我认为这与测试模式下 Omniauth 的回调方法有关,但我不确定如何更改/管理它。

更新:这是我的 Devise 路线。

devise_for :users, :controllers => { 
    :omniauth_callbacks => "users/omniauth_callbacks", 
    :registrations => 'registrations', 
    :passwords => 'passwords', 
    :sessions => 'sessions', 
    :confirmations => 'confirmations' 
} do
  match 'confirmations/unconfirmed' => 'confirmations#unconfirmed', :as => :unconfirmed
  match 'confirmations/send_advisor_confirmation/:id' => 'confirmations#unregistered_advisor_confirmation', :as => :send_advisor_confirmation
  get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
end

I'm trying to write tests for authentication with Twitter and Facebook. I am using Devise and Omniauth. When I try it out it works correctly, but I can't get the tests to pass for it.

I'm following instructions, but it isn't in depth enough for me, plus I'm doing things a little differently (already have some code base). I have a custom controllers for omniauth_callbacks and registrations.

My problem is that when I run the tests it says:

(::) failed steps (::)

No route matches "/oauth/authorize" (ActionController::RoutingError)
<internal:prelude>:10:in `synchronize'
(eval):2:in `click_link'
./features/step_definitions/web_steps.rb:57:in `/^(?:|I )follow "([^"]*)"$/'
features/link_twitter.feature:19:in `And I link twitter'

Failing Scenarios:
cucumber features/link_twitter.feature:16 # Scenario: User links twitter

Where is this /oauth/authorize route coming from and how do I handle that?

It does not look like it is getting to my OmniauthCallbacksController. It follows the link and then dies. I think it has to do with Omniauth's call back method during test mode, but I'm not sure how to change / manage that.

Update: Here are my routes for Devise.

devise_for :users, :controllers => { 
    :omniauth_callbacks => "users/omniauth_callbacks", 
    :registrations => 'registrations', 
    :passwords => 'passwords', 
    :sessions => 'sessions', 
    :confirmations => 'confirmations' 
} do
  match 'confirmations/unconfirmed' => 'confirmations#unconfirmed', :as => :unconfirmed
  match 'confirmations/send_advisor_confirmation/:id' => 'confirmations#unregistered_advisor_confirmation', :as => :send_advisor_confirmation
  get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

隱形的亼 2024-12-06 14:08:39

我忘记将以下内容放入 env.rb

# features/support/env.rb
OmniAuth.config.test_mode = true

有关测试的更多信息,请阅读此处< /a>.

I forgot to put the following into env.rb

# features/support/env.rb
OmniAuth.config.test_mode = true

For more information read about the testing here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文