[Rspec-devel] rails_plugin_fix merged to trunk

James Mead jamesmead44 at gmail.com
Tue Aug 1 09:41:55 EDT 2006

Hi Aslak,

On 8/1/06, aslak hellesoy <aslak.hellesoy at gmail.com> wrote:
> Didn't we work together a couple of years ago? Or am I getting senile :-)

No, you're not going senile - we did work together at ThoughtWorks.

> Anyway - Mocha/Stubba looks very interesting. I like the way it can
> get rid of trips to the database. A couple of questions:
> 1) When you do Product.stubs(:find) - I would assume that this has a
> sideeffect by forever changing the find class method? If that's so,
> how do you avoid interdependencies between tests/specs? If I'm
> mistaken - how does it *not* have a sideeffect?

It does change the class method, but not forever - it puts the
original method to one side and re-instates it on teardown of the

> 2) Product.stubs(:find) use define_method or method_missing?

The :stubs method is added to Object, but only in the test
environment. Obviously there is scope for a name clash, but we haven't
hit that problem yet and we're using it quite extensively on a couple
of Rails projects at Reevoo (http://www.reevoo.com). The :stubs method
delegates to an instance of a Mocha Mock which is stored against the
Product class.

Does that make any sense? You can stub not only at the class method
level, but also against an instance or even all instances of a class.
There are some more examples at


More information about the Rspec-devel mailing list