[rspec-users] Collection proxies need to be stubbed ?
dchelimsky at gmail.com
Sun Jan 21 06:46:13 EST 2007
On 1/21/07, Tobias Grimm <listaccount at e-tobi.net> wrote:
> Francois Beausoleil wrote:
> > My question really boils down to:
> > def index
> > @projects = current_user.projects.active
> > end
> > My spec needs to return the proxy, no ? Here's my code:
> >From a RSpec-newbie's point of view:
> Looks like current_user is a method of the controller, that selects the
> user from the request params, right? Mocking this means, current_user()
> will not be covered by the specs. Normally I avoid mocking/stubbing
> members of a class under test or private and protected members of any
> class. You could instead mock the User class directly to return the User
If the current_user is actually coming from request params I agree w/
this. If it's a user stored in the session, I don't agree that it
should come from the User class. I would probably stick the mock user
in the session though, rather than stub the method.
> But why not use fixtures and let it run with real data instead of
> mocking the database away?
Because specs run faster when you don't rely on the database. You're
going to be spec'ing all the same stuff in your model specs, so why
hit the database more than you need to?
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users