[rspec-users] How to mock a logged in user

Robert Dober robert.dober at gmail.com
Tue Nov 23 10:14:43 EST 2010


On Tue, Nov 23, 2010 at 1:04 PM, Raghu Somaraju <somaraju at gmail.com> wrote:
>
> Thank you Robert. That works. I should have used the "current_user" instead
> of @_current_user in the first place.
>
> But, if I do want to use @_current_user, how do I pass on that instance
> variable to the controller from spec?

Short answer: Do not do it: Mocking is here to simulate behavior and
ivars are here to implement state. (caching state in our case)

Long answer: Although I believe that the above said is often true
there must be exceptions, I adapted a relish test to show you how it
works:
https://gist.github.com/711904

Cheers
Robert


More information about the rspec-users mailing list