2013-12-09 49 views
0

我使用硒來測試我的谷歌的oauth2登錄:軌+水豚+硒測試谷歌的oauth2回調

#spec/featurers/google_spec.rb 
require 'spec_helper' 

describe "the signin process", type: :feature do 
    before do 
     Capybara.current_driver = :selenium 
     visit user_omniauth_authorize_path(:google_oauth2) 
     fill_in "Email", :with => '[email protected]' 
     fill_in "Password", :with => 'test' 
     click_button 'Accedi' 
     #in this point it crash 
     click_button 'Consenti' 
    end 
    it { page.should have_content('Google') } 
end 

它的工作原理,但我有一個問題來管理谷歌的回調:

Errore:redirect_uri_mismatch 
The redirect URI in the request: http://127.0.0.1:58272/users/auth/google_oauth2/callback did not match a registered redirect URI 

我怎樣才能管理這種callaback?如果一個真正的測試,而不是127.0.01:58272我有localhost:3000,它的工作原理。

SOLUTION

在spec_helper.rb,或者更具體地說,在塊之前,在你的spec文件。

describe "the signin process" do 
    before do 
    Capybara.run_server = true #Whether start server when testing 
    Capybara.current_driver = :selenium 
    Capybara.server_host= 'localhost' #this is the goal 
    Capybara.server_port = 3000 
    visit user_omniauth_authorize_path(:google_oauth2) 
    end 
    it {#some} 
end 
+0

查看此問題:http://stackoverflow.com/questions/20388082/rails3-2rspeccapybara1-0-test-devise-google-oauth2-0 – kddeisz

+0

我有一個不同的問題,即時通訊能夠訪問外部鏈接,但我不能管理回調URL – user1066183

回答

0

redirect_uri如果您在您的控制檯生成客戶端ID上https://code.google.com/apis/console/不只是工作。

在創建客戶端ID,你必須選擇Installed Application,使其工作。有關生成客戶端ID的更多信息:https://developers.google.com/console/help/#generatingoauth2

+0

我剛剛張貼了我的解決方案 – user1066183

+0

所以你必須在你的谷歌控制檯創建了127.0.0.1:3000客戶端ID?請記住,通過將測試環境的端口設置爲3000,您將必須確保沒有開發模式的服務器在端口3000上運行。 – cantonic