[rspec-users] Where is current_user?

David Chelimsky dchelimsky at gmail.com
Mon Oct 20 09:52:06 EDT 2008

On Mon, Oct 20, 2008 at 8:29 AM, Harry Bishop <lists at ruby-forum.com> wrote:
> David Chelimsky wrote:
>> retrieve_user, the real method, sets an instance variable that other
>> methods expect to be set rather than returning a value. When this is
>> stubbed with a *return value* of the user, the instance variable never
>> gets set inside the controller.
>> I'd add a current_user method that returns @current_user, and then
>> stub *that* in the code examples:
>  Hi David,
> I understand your response now that its pointed out what is happening
> between controller and rspec, however, this means changing my code to
> test it.  This strikes me as backward.

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.

> Isn't there another way to get
> the @current_user "set" for use in the controller?

Sure, but it's fugly:

controller.instance_eval { @current_user = people(:someuser) }

> BTW - the actual code runs fine.

Since maintainability requires testability, just because it works
doesn't mean it's maintainable.


> HR
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list