I did this using google_auth, but you can do the same with facebook, twitter and github.
First of all remove this line:
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:facebook]
Add those lines, in your 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'
}
})
Then in your helper:
module FeatureHelpers
def login_with_oauth(service = :google_apps)
visit "/users/auth/#{service}"
end
end
Include your helper into spec_helper.rb
RSpec.configure do |config|
config.include FeatureHelpers, type: :feature
end
And finally, in your feature/capybara_spec.rb file
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
I know is kinda late and maybe you found the answer, but if you couldn't or anybody is reading this is good to have it!