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
On 25.11.2007, at 19.41, Daniel Tenner wrote:> ... 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?)Why through the whole process, wouldn''t logging in be enough, since you create the user in the story code? I currently do that, because I want to test the whole stack in my stories, including the login process. //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi
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 >