[mocha-developer] Stubbing objects and calling to_json on them errors (circular reference)

James Mead jamesmead44 at gmail.com
Sun Oct 26 15:22:14 EDT 2008


2008/10/24 John D. Hume <duelin.markers at gmail.com>

> Bill,
> I realize it's been a few days and apologize for the late response,
> but I just saw this. I hate to be the guy on the mailing list saying
> "you shouldn't be trying to do what you're trying to do," but that's
> sort of where I'm headed. I hope it's helpful anyway.
>
> When adopting a codebase that wasn't developed test-driven, I'd
> strongly recommend focusing on Rails-style functional tests rather
> than introducing mock-based testing of the current design. The biggest
> downside to mocking is that it ties you to certain interactions
> between objects. When you're using it to determine what those
> interactions should be, that's ok. When you already know you're not
> happy with the way those interactions work and intend to clean them
> up, what you really need is tests that give you a safety net to enable
> refactoring (a green bar that you can keep green as you improve the
> design). Mock-based tests aren't likely to give you that. Rather
> they're probably going to mean that as you skinny down your
> controllers, you'll have to change everything in at least two places
> instead of just one, and meanwhile the suite won't tell you whether
> things are still working.
>
> Mock-based tests are a useful design tool, and can (in some cases) be
> useful documentation of design, but they don't usually make for a good
> regression suite. All three of those are important when developing
> from scratch. But when taking on legacy code whose design you intend
> to change, the first two goals are off the table. The third is better
> served with higher-level tests.
>
> It's definitely worth your time to read the 12-page version of Michael
> Feathers' Working Effectively With Legacy Code.
>
> www.objectmentor.com/resources/articles/WorkingEffectivelyWithLegacyCode.pdf
>

Hi John,

Thanks for that excellent constructive response. Sorry I haven't been active
on the list for a while - I really appreciate you taking the time to help
Bill.

Thanks also for the pointer to that shortened version of Michael Feathers'
book.
-- 
James.
http://blog.floehopper.org


More information about the mocha-developer mailing list