On 7/9/07, Johan Sørensen <[EMAIL PROTECTED]> wrote: > > > 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: > > http://blog.caboo.se/articles/2007/6/19/rspec-notes-from-the-trenches-2 > > > > > Agreed that this is a good approach in terms of dealing w/ rails > > models. > > 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 arse. :) > > > 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 > > end > > > > > It's not pretty, but it works. > > > > > The other thing you might consider is a custom matcher. Something like: > > > > > 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.
It's not exactly widely publicized :) But that's how rspec's own anything, numeric, etc mock argument matchers work. > > JS > > > > _______________________________________________ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users