Lurking dependencies in test doubles

And so I find myself stroking my beard over an Object Mentor post again.

David Chelimsky points out that hand-rolled mocks create a dependency right in the test code. He relates a story similar to what I've experienced a few times, in which small test doubles became a whole parallel hierarchy of classes implementation-coupled to the classes. It hadn't occurred to me that auto-generated mocks, or other techniques to abstract the creation of test doubles, would help keep the dependency tree clean, but there it is.

The good news is this: the result of these observations has been that our service layer is morphing back to it's original form - very thin, simple APIs favoring dependency injection over service locator for both tests and the system under test.

More solid concepts to work with as I consider scope and strategy for a plugin to Needle-ize Rails.

By the by, I'm giving up on the 2-post-long "Rails contrarian" schtick, about 2 posts too late. Ron Jeffries quotes Ralph Waldo Emerson:

Speak the affirmative; emphasize your choice by utterly ignoring all that you reject.

So it's time to evangelize why Ruby systems do need dependency injection, or at least its full benefits. And try to ship some tools to help folks apply that advice easily.