2014-04-09 22 views
3

我已經在我的網站上設置Facebook登錄後this tutorial和我使用黃瓜和水豚。我嘗試過其他SO帖子like this,這些帖子解釋瞭如何設置虛假登錄帳戶。如果我直接用這個,我得到:測試Facebook的登錄與導航黃瓜

When I follow "sign_in"          # features/step_definitions/web_steps.rb:56 
     No route matches [GET] "/oauth/authorize" (ActionController::RoutingError) 
     ./features/step_definitions/web_steps.rb:57:in `/^(?:|I)follow "([^"]*)"$/' 
     features/facebook_signin.feature:9:in `When I follow "sign_in"' 

如果我添加get "/oauth/authorize"我的路,我得到:

When I follow "sign_in"          # features/step_definitions/web_steps.rb:56 
     uninitialized constant OauthController (ActionController::RoutingError) 
     ./features/step_definitions/web_steps.rb:57:in `/^(?:|I)follow "([^"]*)"$/' 
     features/facebook_signin.feature:9:in `When I follow "sign_in"' 

我不知道是怎麼回事,爲什麼它是抱怨。如果我從gem 'omniauth-facebook', '1.4.0'改變我的Gemfile只是gem 'omniauth-facebook'我得到上面幾乎同樣的錯誤,除了代替:

/oauth/authorize,我得到/dialog/oauth和替代uninitialized constant OauthController,我得到uninitialized constant DialogController

有沒有人最近成功地建立了黃瓜測試用Facebook登錄?

當我在localhost:3000,然後導航到本地主機:3000 /認證/ Facebook的一切工作和我使用的是sessionsController,所以我不明白爲什麼在測試中,它試圖利用這些oauthControllers或DialogueControllers。

回答

1

你在這個測試中啓用了Javascript嗎?作爲教程提到facebook.js.coffee?

describe 'When I follow "sign in"', js: true do 

另一種可能性是,你只在的Gemfile中

group :development do 
    gem 'omniauth-facebook' 
end 

BTW的development塊包括寶石:你不應該對「真實」的外部終結點進行測試。看看webmock這種測試嘲笑Facebook的迴應

+0

我已經upvoted這個,因爲它解決了我的問題。但是,我注意到我正在使用實時API執行測試,以便我可以用vcr gem記錄它。 – Obromios

0

我不得不把@omniauth_test_success放在功能之前,而不是步驟定義。另外,我不得不解決一些路由問題。本週晚些時候會發布完整報告。

5

最近我有同樣的問題或非常相似的問題:

ActionController::RoutingError: 
    No route matches [GET] "/dialog/oauth" 

我採取了哪些正確地從其他項目中建立模擬反應,是相當驚訝地突然得到這個錯誤的工作規範。

經過一番痛苦我有一個重大的捂臉時刻,當我意識到我已經忘了設置OmniAuth使用測試模式:

# spec/rails_helper.rb 
OmniAuth.config.test_mode = true 

這將導致OmniAuth短路,使您可以設置身份驗證通過迴應:

OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new({ 
    :provider => 'facebook', 
    :uid => '123545' 
    # etc. 
}) 

我認爲錯誤是由於OmniAuth試圖通過使用在測試環境中:developer策略,這樣你就無法獲得通過身份驗證提供者禁止很有幫助。

請參閱https://github.com/intridea/omniauth/wiki/Integration-Testing