[rspec-users] Stubbing authentication across multiple controllers

Blake Pettersson blake.pettersson at hotmail.com
Fri May 18 13:24:17 EDT 2007

> Leave your detailed spec as it is for SessionController, but abstract
> the functionality out - and stub it - for everyone else. It's your
> choice as to where you place the stubs; personally I make the controller
> call the before_filter but return immediately by stubbing #logged_in?
> and #authorized? as above. This means I can run specs to ensure my
> controllers do the right thing if the user is not logged in (the stub
> returns false) and/or is not authorized(*). You may also need to stub
> methods to return the current_user (etc) as required. Put them in
> helper methods as you are doing and use in setup/before blocks as
> required. YMMV.
> Best wishes,
> Jerry

That does indeed sound like the best solution. Thanks!


Discover the new Windows Vista

More information about the rspec-users mailing list