Skip to content

Instantly share code, notes, and snippets.

@mhenrixon
Forked from nicalpi/facebook_registration.rb
Created July 15, 2018 14:03
Show Gist options
  • Save mhenrixon/af20677b1cc5670712ccd13d88e5a9f5 to your computer and use it in GitHub Desktop.
Save mhenrixon/af20677b1cc5670712ccd13d88e5a9f5 to your computer and use it in GitHub Desktop.
Testing Omniauth with Devise, Rspec and Capybara
background do
set_omniauth()
click_link_or_button 'Sign up with Facebook'
end
# You can read about this gist at: http://wealsodocookies.com/posts/how-to-test-facebook-login-using-devise-omniauth-rspec-and-capybara
def set_omniauth(opts = {})
default = {:provider => :facebook,
:uuid => "1234",
:facebook => {
:email => "[email protected]",
:gender => "Male",
:first_name => "foo",
:last_name => "bar"
}
}
credentials = default.merge(opts)
provider = credentials[:provider]
user_hash = credentials[provider]
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[provider] = {
'uid' => credentials[:uuid],
"extra" => {
"user_hash" => {
"email" => user_hash[:email],
"first_name" => user_hash[:first_name],
"last_name" => user_hash[:last_name],
"gender" => user_hash[:gender]
}
}
}
end
def set_invalid_omniauth(opts = {})
credentials = { :provider => :facebook,
:invalid => :invalid_crendentials
}.merge(opts)
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[credentials[:provider]] = credentials[:invalid]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment