From: Eric Hodel Date: 2006-05-17T03:36:00+09:00 Subject: Re: BDD and mocking objects On May 15, 2006, at 3:42 PM, Pat Maddox wrote: > The way I've done things though requires me to write the Movie > class before I even begin working on the Rental's behavior. First > of all that sidetracks me for a bit while I write Movie and its > tests, and in general I think it leads to me writing more tightly > coupled code. How does it make your code more coupled? > It seems obvious to me now that when writing a unit test, I should > mock out any relationships, so basically any object that's not the one > I'm explicitly testing. I'm sure there are exceptions, but does that > seem like a good guideline to follow? I typically only stub methods, typically overriding superclass methods in a subclass. For example, I'll be using open-uri (which overrides Kernel#open) in my implementation then add a MyClass#open stub that allows me to provide the open behavior that open-uri gives. I've done the same with #system and #`. For me, mocks feel like a lot of typing for something I can achieve more simply by exploiting Ruby's dynamic language features. -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com