Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8305295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:05:06+00:00 2026-06-08T18:05:06+00:00

This is an adopted rails app with no tests. I am trying to test

  • 0

This is an adopted rails app with no tests. I am trying to test omniauth in an integration test but am getting an error (edit I have based upon this: https://github.com/intridea/omniauth/wiki/Integration-Testing). This reflects my lack of understanding of Rspec. It would seem that the request object would be available by default.

I have in my spec/spec_helper.rb:

config.include IntegrationSpecHelper, :type => :request
Capybara.default_host = 'http://localhost:3000'

OmniAuth.config.test_mode = true
OmniAuth.config.add_mock(:facebook, {
  :uid => '12345'
})

and in my spec/integration/login_spec:

require 'spec_helper'

describe ServicesController, "OmniAuth" do
  before do
    puts OmniAuth.config.mock_auth[:facebook]
    puts request # comes back blank
    request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:facebook]
  end

  it "sets a session variable to the OmniAuth auth hash" do
    request.env["omniauth.auth"][:uid].should == '12345'
  end
end 

and I get the following error:

{“provider”=>”facebook”, “uid”=>”12345”, “user_info”=>{“name”=>”Bob
Example”}}

F

Failures:

1) ServicesController OmniAuth sets a session variable to the
OmniAuth auth hash
Failure/Error: request.env[“omniauth.auth”] = OmniAuth.config.mock_auth[:facebook]
NoMethodError:
undefined method env' for nil:NilClass
# ./login_spec.rb:8:in
block (2 levels) in ‘

Finished in 22.06 seconds 1 example, 1 failure

Failed examples:

rspec ./login_spec.rb:11 # ServicesController OmniAuth sets a session
variable to the OmniAuth auth hash

Should the request object be available here, by default? Does this error possibly mean something else?

thx

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:05:07+00:00Added an answer on June 8, 2026 at 6:05 pm

    You’re getting nil because you haven’t made any request yet.

    To make the test work, you have to do three things:

    1. Set up the mock
    2. Make the request
    3. Test whatever code is attached to the callback

    Here’s how I do it. First set up the mock in the before block, and then visit the URL corresponding to the provider (in this case facebook):

    before do
      OmniAuth.config.add_mock(:facebook, {:uid => '12345'})
      visit '/auth/facebook'
    end
    

    From the wiki:

    A request to /auth/provider will redirect immediately to /auth/provider/callback.

    So you have to have a route which matches ‘/auth/:provider/callback’. Whatever action you map that do has to perform the stuff in step 3 above.

    If you wanted to test that the session variable was set to the uid, you could do something like this (which works because you set the uid to ‘12345’ in the mock above):

    it "sets a session variable to the OmniAuth auth hash" do
      session['uid'].should == '12345'
    end
    

    And here’s a route and action that should make this pass:

    routes.rb

    match '/auth/:provider/callback' => 'sessions#callback'
    

    controllers/sessions_controller.rb

    def callback
      session['uid'] = request.env["omniauth.auth"][:uid]
    end
    

    That’s the gist of it. Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble getting JSON data from my Rails app to display on a
Noobie iOS developer with an adopted iOS app here. I have a settings piece
Following suggestions on this site, I have adopted SimpleXML from org.simpleframework.xml. I use this
I have wholly adopted the MVVM pattern for our silverlight app. However, some of
This might seem like a n00b question, but I am trying to break some
(This is not exactly the problem that I have, but it's isomorphic, and I
I have following JSON object. {feed:[ {news: {adopted_from:null,user_id:null,description:this is test,id:2} }, {news: {adopted_from:null,user_id:null,description:like unlike
Ok I have adopted a CodeIgniter Setup, My route.php in config looks like this:
Both C# and Scala have adopted frameworks for simplifying doing asynchronous/parallel computation, but in
I have recently set up a VPS and am trying to deploy a rails

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.