[rspec-users] [Stories] Login and subdomain

Pat Maddox pergesu at gmail.com
Thu Mar 6 10:27:00 EST 2008


On Thu, Mar 6, 2008 at 7:23 AM, Pat Maddox <pergesu at gmail.com> wrote:
> On Thu, Mar 6, 2008 at 7:12 AM, Bastien <bastien.vaucher at gmail.com> wrote:
>  > Thanks David, this works just fine. I would rather do some stubbing
>  >  there if it's possible though. I tried :
>  >
>  >  ApplicationController.stub!
>  >  (:user_authentication_required).and_return(true)
>
>  try
>  controller.stub!(....)

Perhaps I should explain why this is.  stub! adds a stubbed method to
an object.  In Ruby, classes are objects as well, so what you've done
is to stub a method on the ApplicationController class object itself -
effectively creating a class method.  When you override the method
yourself, you're overriding an instance method.  So in order to stub
out the method for a request, you want to stub it on the _instance_ of
the controller being used in the test.  That controller instance is
made available to you through a method named "controller".

Pat


More information about the rspec-users mailing list