We are a small web development and marketing studio.
We are known for being efficient and pragmatic without compromising on quality.

How to test Facebook login using Devise, Omniauth, Rspec and Capybara

rails,tutorial,devise,omniauth

Last week, one of the features requested for the new version of My Drinkaware app was to implement a Facebook login and signup.

The app was already using Devise for the Authentication, so implementing the feature using Omniauth was super easy.

If you’ve never done it before I recommend you read the Devise Omniauth wiki page and you’ll be ready in no time.

Writing the tests

Writing the tests for the Facebook login and signup is really easy as well, thanks to Omniauth test_mode.

Even though, at the moment, the client only wants to support Facebook authentication, the chances are that, in the future, Twitter or Gmail could be part of the scope.

So what I’ve ended up creating 2 helpers in my support/omniauth.rb file:

With this sweet setup, I can now have multiple defaults in my tests, which makes changes very clean:

There you go, I hope it’ll help someone some day!

Nathalie mini profile image Post written by Nicolas Alpi

Nicolas is a talented Ruby on Rails/javaScript developer. He manipulates his TypeMatrix keyboard like no one else, likes VIM, Linux, and above all loves finding pragmatic solutions to complex problems. When he is not developing a new web application, he likes reading, hiking and eating Nathalie's cookies.

You can also follow Nicolas on Twitter at @spyou.

If you have any questions contact him at nicolas@wealsodocookies.com or leave a comment.