我使用硒來測試我的谷歌的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
查看此問題:http://stackoverflow.com/questions/20388082/rails3-2rspeccapybara1-0-test-devise-google-oauth2-0 – kddeisz
我有一個不同的問題,即時通訊能夠訪問外部鏈接,但我不能管理回調URL – user1066183