[rspec-users] Mocking User.find( :all, :limit => 10 )
johan at johansorensen.com
Mon Jul 9 13:41:18 EDT 2007
On Jul 9, 2007, at 5:42 PM, David Chelimsky wrote:
>> As opposed to getting into complicated mocking scenarios, consider
>> abstracting this logic into your model:
> Agreed that this is a good approach in terms of dealing w/ rails
I generally agree with this, no doubt. But when the it comes to big
apps and bigger test/spec suites, all that database communication
(and fixtures creation/teardown), slows testruns downs and that
lowers the chances of people running them regularly.
There's of course many different ways of dealing with this (another
I'm doing is reworking the way fixtures work), but in a way I see it
the same way as I do with, say, XML-RPC models (or REST, or other
networking related models) that I maybe I don't really need to test
communication with the network backend all the time, but more
interested in that my model implementation behave like I expect them
to when it comes to sending data to the client. Of course this starts
to turn into a slightly slippery slope when it comes to rails since
it relies so much its direct database mapping.
I'm still trying this approach out along with other things to cut
down specs runtime , and I eagerly await the day it bites me in the
> As for the question of isolating specific key/value pairs in a
> hash, you could do this:
> obj.should_receive(:message) do |*args|
> hash = args.pop
> hash[interesting_key].should == expected_value
> It's not pretty, but it works.
> The other thing you might consider is a custom matcher. Something
> obj.should_receive(:message).with(has_key_value(key, value))
> The mock framework can use these just as the expectation framework -
> though mocks rely on == instead of matches.
Cheers, I didn't know that you could do custom matchers for those
kind of expectations too.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rspec-users