[rspec-users] Where is current_user?

Zach Dennis zach.dennis at gmail.com
Mon Oct 20 10:44:29 EDT 2008

On Mon, Oct 20, 2008 at 10:09 AM, Harry Bishop <lists at ruby-forum.com> wrote:
> David Chelimsky wrote:
>> When things are hard to test they are hard to maintain, so
>> maintainability requires testability. When a simple change makes
>> something easier to test, that change brings a lot of value. That's
>> the spirit of rspec, BDD and even TDD.
> Thanks David,
> I am new to rspec and am enjoying the interchange between build a test
> then build the code.  In this case I'm late to the party.  This
> particular setup for @current_user makes sense to me but I understand
> your point about maintainability.
> In trying to understand what rspec is doing, my thinking was that since
> MotionsController is a subclass of ApplicationController any instance
> variable set in ApplicationController was available to
> MotionsController. I think you are telling me that rspec doesn't invoke
> this. So I need to think about the implications here.

The @current_user instance variable was being set by the
ApplicationController#retrieve_user method, but your spec was stubbing
out the #retrieve_user method. This means that the original
ApplicationController#retreieve_user method is not going to get called
because you have explicitly told RSpec to stub out that method and
return the current user from your spec. Since the original method is
not going to get called the @current_user instance variable in the
controller never gets set.

Zach Dennis

More information about the rspec-users mailing list