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?
After approx. 200 hours of googling, I found an answer myself.
It boils down to these magic words: