Rick DeNatale
2009-Oct-04 00:09 UTC
[rspec-users] Is there a good (non-judgemental) comparison of Rspec mocking vs Mocha?
I''ve just picked up a project which has been using test/spec and mocha. We''re in the process of switching over to rspec for the testing framework, and will probably just continue to use mocha for the mocks, although I''m certainly more fluent in Rspec. 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 this. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale
Stephen Eley
2009-Oct-04 03:51 UTC
[rspec-users] Is there a good (non-judgemental) comparison of Rspec mocking vs Mocha?
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 > this.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. >8-> 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. -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org