[rspec-users] Rails sessions in plain text stories

Daniel Tenner daniel.ruby at tenner.org
Sun Nov 25 12:41:38 EST 2007


Ok, maybe I'm being particularly thick, but I've been trying to find  
the solution to this for a couple of hours now and I just can't seem  
to be able to do it...

I'm trying to write a step as such:

   Given("user $email is logged in") do |email|
     user = User.find_by_email(email)
     session[:user_id] = user.id
   end

This is the way it would look in specs... but all I seem to be  
getting, depending on whether I write it as @session,  
@controller.session, session, request.session, @request.session,  
etc... is errors like:

     NoMethodError: You have a nil object when you didn't expect it!
The error occurred while evaluating nil.session
     ./matchers/navigation_steps.rb:4:in `user $email is logged in'

Or variations such as:

     NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]=
     ./matchers/navigation_steps.rb:4:in `user $email is logged in'

... What am I doing wrong?

I've for the time being gotten around this problem (thanks to pd's  
suggestion on #rspec) by making the spec run through the sign up and  
email confirmation process, which does sign in the user into the  
session... but that seems a little over-verbose?)

Any help would be most welcome.

Daniel


More information about the rspec-users mailing list