Thanks to a pointer from lizkeogh.com site I've been discovering the joy of the Mockito (http://mockito.org/) mocking framework for Java. It verifies behaviour after the action. It struck me how this matched the format I use in my Ruby cucumber features. Within Rspec if we could use post behaviour verifications I could unify the format of my specs with my features. Specs could look like:
--- it "should make verfication of behaviour after action" #Given setup some mock/stubs #When perform action #Then Check whether the behaviour was as expected. end --- While we can do this with output checks in Rspec we cannot do such a thing with 'should_receive'. Having a consistent format for specs and stories sounds like a great idea to me. Also the separation of the verification from the Given set-up is nice. So I'm proposing the idea of adding 'should_have_received' and test_spy in Rspec: --- x = test_spy('like a mock but more into espionage') #Action which does not fail on unexpected method but just records calls. some.action(x) x.should_have_received(:method).and_returned_with('some string') --- What I'm still looking at is if the idea of post validation is possible in the Rspec framework mocking framework. I know RR (http://github.com/btakita/rr/tree/master) is looking at implementing the Spy pattern which will enable this sort of testing. Do people think this would be a good addition to Rspec? ((I'm really excited with the idea and I have started playing around with some code for a prototype. If its not for Rspec I can always look at it for RR.)) I've added a issue in lighthouse (though its behaving very strangely at the moment not picking my ticket up in searches/tags) http://rspec.lighthouseapp.com/projects/5645/tickets/527-adding-spy-to-rspecs-mocking-framework -- Joseph Wilk http://www.joesniff.co.uk -- Posted via http://www.ruby-forum.com/. _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users