Omniauth
OmniAuth is a Rack-based authentication system for twitter (and many other services). Its rack middleware is the one that talks with twitter and puts the twitter user data in the env variable. You can watch the railcast to see an explanation of how it works (it's only 8 minutes).
BDD
Ok, I know how to integrate Twitter authentication in my application. How do I test it? How do I continue with my BDD cycle? When we are testing our application, we don't want to rely on the actual Twitter service. It will make our tests slower and brittle. We need to have control of our tests, so we need to fake the Twitter server. Fortunately, doing it with omniauth is very easy.
We only need to put omniauth in test mode and give it the information we want to receive from Twitter in our test:
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
OmniAuth.config.test_mode = true | |
OmniAuth.config.mock_auth[:twitter] = { | |
'provider' => 'twitter', | |
'uid' => '1234', | |
'user_info' => {'name' => user_name} | |
} |
In this case, we're telling omniauth to, when asked about Twitter, give us the provider, the user uid and the user name.
We can integrate this easy in a cucumber hook, or even in a cucumber step, to mock the Twitter server and continue with our BDD cycle :D
No hay comentarios:
Publicar un comentario