2

I am trying to just test omniauth. I have put in config/environments/test.rb

OmniAuth.config.test_mode = true

and in my spec_helper.rb

OmniAuth.config.add_mock(:facebook,
                             { :provider => 'facebook',
                               :uid => '1234567',
                               :info => { :first_name => 'Jonathan', :name=> 'Jonathan', :email => 'jon@jak.com', :image => 'http://graph.facebook.com/1234567/picture?type=square'},
                               :credentials => {
                                 :expires_at => 1351270850,
                                 :token=> 'AAADzk0b791YBAHCNhBI3n6ScmWvuXTY4yIUqXr9WiZCg1R808RYzaHxsHnrbn62IwrIgZCfSBZAVIP6ptF41nm8YtRtZCeBbxbbz1mF8RQZDZD'
                                } })

and then in my request controller:

it "testing omniauth hash" do
  visit '/auth/facebook'
  request.env["omniauth.auth"][:uid].should == '1234567'
end

and get:

Failures:

  1) Login logins with the OmniAuth auth hash
     Failure/Error: request.env["omniauth.auth"][:uid].should == '1234567'
     NoMethodError:
       undefined method `env' for nil:NilClass
     # ./spec/requests/login_spec.rb:38:in `block (2 levels) in <top (required)>'

Finished in 2.4 seconds
9 examples, 1 failure

Any idea what is going on? thx in advance

edit 1 enter image description here

timpone
  • 19,235
  • 36
  • 121
  • 211

1 Answers1

2

EDIT: Actually, I reproduced the error and the problem seems to be that the request object doesn't get instantiated unless you issue a native request using [http_verb] [url]. So it should work if you use get '/auth/facebook' instead of visit '/auth/facebook'.

cdesrosiers
  • 8,862
  • 2
  • 28
  • 33
  • thx, but ... hmm... same error. Should OmniAuth.config.test_mode = true be in the environment file or spec_helper.rb? – timpone Sep 25 '12 at 03:16
  • hmmm... still getting the same error. I've added a screenshot above. Not sure but thx for help – timpone Sep 25 '12 at 03:51
  • I'm not too familiar with omniauth, but just looking at the railscast on it, it seems that "omniauth.auth" only gets set when the application returns from authenticating, which would explain why `request.env['omniauth.auth']` is coming up nil. Do you try to get around that anywhere else in your code? – cdesrosiers Sep 25 '12 at 04:40