views:

55

answers:

2

I have seen a lot of outdated podcasts that mention mocha as a gem I would want to install because it does mocking better then rspec. I have a feeling that the rspec developers have caught on to this and have improved their mocking since then. However, in the default spec_helper.rb file I see some commented out code stubs for three mocking frameworks

  • mocha
  • flexmock
  • rr

Upvote to anyone who can give me a decent answer as far as pros and cons on at least one of these frameworks versus rspec's own mocking framework.

I'll accept an answer if you can give me a break down on all three versus rpsec

+1  A: 

Really, it's just a matter of taste. Take a look at the syntax and play around with the mocking frameworks to see what suits you best. Of course, it's quickest and easiest to roll with RSpec's built-in mocking. And, as you mentioned, the developers of RSpec have taken cues from the other frameworks... You'll find a lot of similarities between them.

This question's been asked before: see the details there to get an idea of some of the differences (at least between RSpec::Mock and Mocha).

oddlyzen
+1  A: 

We were using the built-in rspec mocking, until recently when we switched to mocha. My colleague wrote up a blog post about the gotchas and a bit about the reasoning:
http://developer.newsdesk.se/2010/05/29/migrating-rspec-to-mocha/

Basically, we wanted mocha's any_instance method, which is useful if you can't get to the instance you want to mock. Not a huge advantage, but enough to make it worth our while.

Martin Svalin