[rspec-users] Can't get running a simple rspec test: assigns is always nil

Alexander Seidl lists at ruby-forum.com
Mon Oct 26 04:43:10 EDT 2009

Hi Stephan,
thank you very much for this comprehensive answer. And thanks to all 
others participating at this thread. This will help me on my further 
attempts to write tests with rspec.


Stephen Eley wrote:
> On Wed, Oct 21, 2009 at 1:07 PM, Alexander Seidl <lists at ruby-forum.com> 
> wrote:
>> But why does this filter prevents the index action from being executed?
> Because returning 'false' from a filter does exactly that: it prevents
> the execution of the controller action.
> I'll bet I know what you're thinking -- you're thinking, "But I
> override @login_user in my example group's before(:each) code!"
> Yes, you did.  But you didn't prevent the filter from executing, and
> the first line of your logged_in? method sets the value of @login_user
> *again*, even if it was already set.  As you have it here, you'll be
> doing that database lookup every single time current_user is called or
> an action is called in this controller.
> I would suggest changing that first line of the filter from
> "@login_user = " to "@login_user ||= " -- which sets the value only if
> it was previously false or nil.  Not only will this make your testing
> code work, but it'll eliminate any lookup redundancy.
> --
> Have Fun,
>    Steve Eley (sfeley at gmail.com)
>    ESCAPE POD - The Science Fiction Podcast Magazine
>    http://www.escapepod.org

Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list