[rspec-users] Stubbing Login Stuff

Pat Maddox pergesu at gmail.com
Sun Apr 15 14:22:38 EDT 2007

On 4/15/07, s.ross <cwdinfo at gmail.com> wrote:
> For some reason, I'm completely blanking on how to do this... Sorry
> for the lots-o-code example.
> What I'm trying to do: stub the validate_login method in
> application_controller so it returns true (user is logged in).
> What happens: validate_login method in application_controller.rb is
> called instead of my stub.

In your setup (or wherever), do

controller.stub!(:validate_login).and_return true

When you called stub! without an explicit receiver, the message gets
sent to self, which is a context.  Then when you called stub! on
ApplicationController, it created a class-level method.  In Rails,
each request creates a new controller instance, so you need to call
stub! on that instance.


More information about the rspec-users mailing list