[rspec-users] Rails sessions in plain text stories

David Chelimsky dchelimsky at gmail.com
Sun Nov 25 13:21:42 EST 2007


On Nov 25, 2007 11:41 AM, Daniel Tenner <daniel.ruby at tenner.org> wrote:
> 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?

You are trying to access something to which you have no direct access.

RailsStory wraps rails integration tests. You can read more about them
here: http://weblog.jamisbuck.org/2006/3/9/integration-testing-in-rails-1-1.

>
> 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
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list