HowTo Write tests for Devise & Omniauth in my Rails 3 app?

I have a Rails 3 app with Omniauth and Devise. I could not find a solid tutorial showing how I should write specifications for testing functionality.

I want to make registration and login forms work ... which means that users can create accounts. I also want to be sure that Omniauth FB Connect also always works.

What / how can I write a test for these scenarios above?

thanks

0
source share
1 answer

The tests were very useful for testing a rather complex method that I have to handle using Yahoo, Facebook, Google and AOL. Especially the edges.

It should start, this is the first of my 10+ scenarios.

.feature file

Feature: Signinin with third party service: Google, Aol, Facebook and Yahoo In order to use the site As a User I want to sign in using my Facebook or Gmail accounts Before do OmniAuth.config.test_mode = true end After do OmniAuth.config.test_mode = false end Scenario Outline: Sign with valid names and emails Given that I have a valid "<provider>" account with email "<email>" and name "<name>" And that I am not signed in And I go to the sign in page When I follow image link "<provider>" Then I should see "You signed in using your <provider> account (" And I should see "Welcome to Death Star" Examples: valid name and email variations | provider | email | name | | Google | lukeskywaler@gmail.com | luke skywlaker | | Facebook | darth.vader@aol.com | darth vader | 

my_step.rb helper:

 Given /^that I have a valid "([^"]*)" account with email "([^"]*)" and name "([^"]*)"$/ do |provider, email, name| OmniAuth.config.test_mode = true if provider.downcase == "yahoo" or provider.downcase == "google" or provider.downcase == "aol" # the symbol passed to mock_auth is the same as the name of the provider set up in the initializer OmniAuth.config.mock_auth[:open_id] = { 'provider' => "#{provider}", 'uid' => "#{provider}.com", 'user_info' => { 'email' => "#{email}", 'name' => "#{name}"} } else # the symbol passed to mock_auth is the same as the name of the provider set up in the initializer OmniAuth.config.mock_auth[:facebook] = { 'provider' => 'facebook', 'uid' => "531564247", 'credentials' => { 'token'=> "18915faketoken22|2.NKt21XnznTNEDTTERDGYXI2UUw__.3600.1302234329200-531564247|Mi0DhWREl6g-T9bMZnL82u7s4MI" }, 'user_info' => { 'nickname' => "profile.php?id=53232564247", 'email' => "#{email}", 'first_name' => "Luke", 'last_name' => "Skywalker", 'name' => "Luke Skywalker", 'image' => "http://graph.facebook.com/5asd54247/picture?type=square", 'urls' => { 'facebook' => "http://www.facebook.com/profile.php?id=5asd54247", 'website' => "" } }, 'extra' => { 'user_hash' => { 'id' => "5asd54247", 'name' => "#{name}", 'first_name' => "#{name.split(' ')[0]}", 'last_name' => "#{name.split(' ')[1]}", 'link' => "http://www.facebook.com/profile.php?id=5asd54247", 'birthday' => "12/7/1932", 'hometown' => { 'id' => "104048449631599", 'name' => "Menlo Park, California" }, 'location' => { 'id' => "104048449631599", 'name' => "Menlo Park, California" }, 'gender' => "male", 'email' => "#{email}", 'timezone' => "-7", 'locale' => "en_US", 'verified' => true } } } end end 

I hope for this help.

0
source

Source: https://habr.com/ru/post/1369404/


All Articles