[mocha-developer] how does Mocha compare in terms of classical vs mock-based testing, and stubbing???

David Chelimsky dchelimsky at gmail.com
Mon Feb 5 08:28:48 EST 2007

On 2/5/07, James Mead <jamesmead44 at gmail.com> wrote:
> On 05/02/07, Greg Hauptmann <greg.hauptmann.ruby at gmail.com> wrote:
> >
> > I've just been reading Martin Fowler's article re mock versus
> > stubbing<http://martinfowler.com/articles/mocksArentStubs.html>where
> > he compares traditional TDD testing techniques with mock based
> > testing. I'd be interested in comments from a ruby on rails perspective in
> > terms of this and Mocha?  For example:
> >
> > a) Do you see Mocha as a robust way to test Ruby on Rails based apps?
> >
> > b) Why would one use Mocha over traditional non-mock object based testing
> > for Ruby on Rails?
> >
> > c) Is Mocha a good choice for stubbing out other components that the rails
> > app may interact with, for the purpose of testing?
> Hi Greg,
> Some great questions!
> The team at reevoo.com has been using Mocha and its earlier incarnations to
> help us test drive Rails applications over the last 18 months or so. We find
> it useful to be able to do interaction-based testing as well as traditional
> state-based testing. But you could use any mocking library to achieve the
> same effect. In general terms, I think doing interaction-based TDD can help
> you write more cohesive, less coupled code, although of course it's not a
> silver bullet. You will still need higher level functional/integration tests
> which check that the real objects are all wired up correctly. I would say
> you will see more benefits of using an interaction-based approach, the
> bigger your application gets - mainly due to the reduction in coupling and
> hence the reduction in brittleness of tests.

Very well put!

> There are some great resources on the JMock & MockObjects websites (see
> http://www.jmock.org/docs.html and http://www.mockobjects.com/) which
> although they give examples in Java, are just as applicable in Ruby. In
> particular the "Mock Roles, Not Objects" paper (
> http://www.jmock.org/oopsla2004.pdf) is well worth a read.
> I'm not sure I've completely answered your questions, but please feel free
> to ask more questions like this on the mailing list. I find it's often
> easier to talk about specific examples rather than generalities, so why not
> have a go with Mocha in a Rails app and drop us a line if you have any
> questions.
> --
> James.
> http://blog.floehopper.org
> _______________________________________________
> mocha-developer mailing list
> mocha-developer at rubyforge.org
> http://rubyforge.org/mailman/listinfo/mocha-developer

More information about the mocha-developer mailing list