[rspec-users] Is there a good (non-judgemental) comparison of Rspec mocking vs Mocha?
sfeley at gmail.com
Sat Oct 3 23:51:48 EDT 2009
On Sat, Oct 3, 2009 at 8:09 PM, Rick DeNatale <rick.denatale at gmail.com> wrote:
> I was thinking that there must be a comparison/conversion chart
> somewhere, like the Test:Unit => RSpec translation guide in the RSpec
> docs, but my usually awesome google skills seem to be failing me on
Major differences off the top of my head:
* RSpec's mocking framework has 'mock_model' and 'stub_model' for
Rails testing. There's some controversy about them, but many people
find them convenient.
* Mocha offers the 'any_instance' class method, which makes it easy to
inject mock or stub behavior into objects that aren't created yet.
There's some controversy about it, but many people find it convenient.
But personal or "judgmental" preferences aside, I don't think one is
head-and-shoulders above the other. Many of the differences are
purely on the surface, and no one will call you wrong for using either
one. I use Mocha mostly out of an aesthetic preference for its
syntax. I don't think it makes me a better human being. (And I try
not to mock when I can help it these days anyway.)*
As for your current project -- if it's already fairly deeply invested
in Mocha, my advice would be to keep it there. I once did convert a
project from one to the other for inconsequential reasons. It wasn't
_hard_ to do; it was mostly just "start with a passing test suite, and
find-and-replace and fix specific lines until it passes again." But I
realized at the end that I hadn't really _gained_ anything. It wasn't
even a useful refactoring. I could've spent that time adding
something to my application instead.
Steve Eley (sfeley at gmail.com)
ESCAPE POD - The Science Fiction Podcast Magazine
More information about the rspec-users