[rspec-devel] stubbing/partial mocking

David Chelimsky dchelimsky at gmail.com
Tue Oct 3 20:30:11 EDT 2006


All,

Brian Takita has been contributing to a stubs branch to support
stubbing and partial mocking on Modules (and therefore classes). I
tweaked the syntax a bit and merged it into the trunk, so you can
update from the trunk and check out the new stubbing/mocking love. If
you prefer to wait for a release, there should be one coming soon-ish
(I'm aiming for later this week).

As Brian pointed out in an earlier email, partial mocking is generally
somewhat of a last resort, but it is very useful in some cases - like
spec'ing rails controllers that interact with rails model classes:

#stubbing - when you don't care about verification
Person.stub!(:find).and_return(@person)

#partial mocking: when you do care about verification
Person.should_receive(:find).with("1").and_return(@person)

This is not yet documented on the website - that will be happening
over the next few days.

Also, this does not preclude our slightly longer term goal of
supporting the integration of other mocking/stubbing frameworks. That
is in the works as well.

Enjoy! And thanks to Brian for the excellent contributions.

Cheers,
David


More information about the rspec-devel mailing list