Take the 2-minute tour ×

Rails noob here. I'm having trouble understanding how/what to test for regarding authentication with Omniauth-Facebook. Pretty much have a similar setup to the relevant railscast. And have the test environment set up similarly to what's described in previous questions and on the Gem wiki.

Couple of questions. When you create a User factory how do you get resulting object to mock an authentication.

Also what goes on when the following code is run?

before do 
  request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:facebook]
  visit '/auth/facebook'

Is an object saved in a database?

Ive added some sample specs below and the Factory spec. Again the spec_helper set up file has the config to test mode set to true in addition the add_mock set up as so:

                         { :provider => 'facebook',
                           :uid => '1234567',
                           :info => { :name => 'Jonathan', :image => 'http://graph.facebook.com/1234567/picture?type=square'},
                           :credentials => {
                             :expires_at => 1351270850,
                             :token=> 'AAADzk0b791YBAHCNhBI3n6ScmWvuXTY4yIUqXr9WiZCg1R808RYzaHxsHnrbn62IwrIgZCfSBZAVIP6ptF41nm8YtRtZCeBbxbbz1mF8RQZDZD'
                            } })  


describe "user pages" do

  let(:user) { Factory.create(:user) }

  describe "sign_in" do
    before { visit '/' }

    it "should add a user to the User model" do 
      expect { click_link "sign_in" }.to change(User, :count).by(1) 

    it "should route to the appropriate page if email is nil" do
      click_link "sign_in"
      page.should have_selector('h5', text: 'Edit Email')

    it "should redirect to the show page upon" do
      user.email = 'example@stanford.edu'
      click_link 'sign_in'
      page.should have_selector('div', text: user.name)


FactoryGirl.define do
  factory :user do
    provider  "facebook"
    uid       '1234567'
    name      'Jonathan'
share|improve this question
Were you able to solve this? –  Mohamad Feb 22 '13 at 15:37
Nope. Still having trouble understanding the substance behind what's going on –  rssathe Feb 23 '13 at 2:22

1 Answer 1

Here is a simple OmniAuth specs taken from my example project https://github.com/lucassus/locomotive/blob/9cd7dfd365469fc70fc367f29705a56df9730f6f/spec/features/user_facebook_sign_in_spec.rb I hope it will help you

share|improve this answer

Your Answer


