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 8074285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:36:15+00:00 2026-06-05T14:36:15+00:00

I am developing an API and wanted to test the login method. The spec

  • 0

I am developing an API and wanted to test the login method. The spec for the API located in spec/api/ instead of spec/controller. I am using rspec-rails. Now I have a spec like this:

describe "/api/login.json", :type => :api do
  let(:user) { FactoryGirl.create(:user) }

  context "when called with correct credentials" do
    before(:all) do
      post "/api/v1/passenger/login.json",:email => user.email, :password => user.password
    end

    it "responds with HTTP 200" do
      last_response.status.should == 200
    end

    it "sets the session correctly" do
      session[:user_id].should == user.id # <-- ### Here ###
    end
  end
end

It fails. session is nil. How do I access the session variable?

I guess I have to include some stuff in my RSpec.configure block?

  • 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-05T14:36:17+00:00Added an answer on June 5, 2026 at 2:36 pm

    After approx. 200 hours of googling, I found an answer myself.

    It boils down to these magic words:

    module FoobarHelper
      def session
        last_request.env['rack.session']
      end
    end
    
    RSpec.configure do |c|
      c.include FoobarHelper, :type => :api
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Ruby on Rails 3 and I am developing API for my
I am developing an REST API using Codeigniter. I need to have all error
I am developing a REST API layer for my application using Zend_Rest_Controller. I have
I'm developing an API using close to the latest bits from the aspnetwebstack Codeplex
I'm developing a API that uses lambda expressions to specify properties. I'm using this
I'm developing an API using Luracast Restler library. All I'm looking for is to
I'm developing a REST api. To simplify my question, I have an API that
Developing iphone application using makkit framework. I have got the map view integrated in
I insist on using lex and not the flex. am developing an API in
I am developing an API using Codeigniter and MongoDB. I am not sure what

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.