简体   繁体   中英

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

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" => "bret@facebook.com",
  }

  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].

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM