私は google_auth を使用してこれを行いましたが、facebook、twitter、および github でも同じことができます。
まず、次の行を削除します。
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:facebook]
これらの行を spec_helper.rb に追加します。
Capybara.default_host = 'http://localhost:3000' #This is very important!
OmniAuth.config.test_mode = true
OmniAuth.config.add_mock(:default, {
:info => {
:email => 'foobar@test.com',
:name => 'foo',
:password => 'qwerty123'
}
})
次に、ヘルパーで:
module FeatureHelpers
def login_with_oauth(service = :google_apps)
visit "/users/auth/#{service}"
end
end
ヘルパーを spec_helper.rb に含めます
RSpec.configure do |config|
config.include FeatureHelpers, type: :feature
end
そして最後に、feature/capybara_spec.rb ファイルで
feature "Signing in" do
before do
Capybara.current_driver = :selenium
login_with_oauth #call your helper method
end
scenario "Signing in with correct credentials" do
expect(page).to have_content('Welcome')
end
end
ちょっと遅れて、答えを見つけたかもしれませんが、できなかった場合、または誰かが読んでいる場合は、これを入手してください。