[rspec-users] Collection proxies need to be stubbed ?
listaccount at e-tobi.net
Sun Jan 21 07:24:07 EST 2007
David Chelimsky wrote:
> 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.
Agreed - if it's in the session, this should be the preferred way.
> 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?
I don't have any experience with RSpec/Rails using a database - my
current Rails project is DB-less :-) But on a recent C# project (with
NUnit) I've chosen to just use a database in my tests. It wasn't even an
in-memory database (embedded Firebird) but it was still fast enough with
several hundred tests hitting the database. Rails with SQLite in memory
should even be faster. So speed isn't really much of an issue in my
But you're right that stubbing database access should be preferred.
Sometimes it's just easier to put complex data into a fixture and
retrieve it from the database. Maybe that's a design smell - I'll keep
this in mind when I run into this situation the next time.
More information about the rspec-users