Created
September 7, 2011 11:48
-
-
Save nicalpi/1200365 to your computer and use it in GitHub Desktop.
Testing Omniauth with Devise, Rspec and Capybara
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
background do | |
set_omniauth() | |
click_link_or_button 'Sign up with Facebook' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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
After supplying the above, it does not seem to be saving all the pertinent details in the
request.env["omniauth.auth"]
hash. Am having problems with the integration test. advice much appreciated