AnApprentice
AnApprentice

Reputation: 111080

How to use Omniauth + capybara for testing FB Connect?

I have a rails 3 app + devise using capybara for integration tests. Right now I have sign and sign up tests working but don't have tests for FB Connect.

How can I add Omniauth tests to ensure sign up and sign in work? Any one have an example or a up to date tutorial that shows how this is done? All I could find is fragments of info.

Thanks

Upvotes: 2

Views: 1624

Answers (1)

e3matheus
e3matheus

Reputation: 2132

I don't have the complete example. I added the following to my test.rb(You can add it to a initializer and add it if the enviroment is test).

  OmniAuth.config.test_mode = true

  FACEBOOK_INFO = {
    "id"=> "220439",
    "email" => "[email protected]",
  }

  OmniAuth.config.mock_auth[:facebook] = {
    "uid" => '12345',
    "provider" => 'facebook',
    "user_info" => {"name" => "Bret Taylor", "nickname" => 'btaylor'},
    "credentials" => {"token" => 'plataformatec'},
    "extra" => {"user_hash" => FACEBOOK_INFO}
  }

This simulates the call to omniauth. So in your test, when you simulate a click to the facebook button, the response you will get is the one from OmniAuth.config.mock_auth[:facebook].

Upvotes: 4

Related Questions