[rspec-users] Mocking: brittle specs and tight coupling?

David Chelimsky dchelimsky at gmail.com
Sun Apr 12 17:20:11 EDT 2009

On Sun, Apr 12, 2009 at 12:32 PM, Phlip <phlip2005 at gmail.com> wrote:
>> The third alternative is you never _need_ to mock, yet both your tests and
>> target code are highly decoupled. _That_ is the goal.
> Another tip: To TDD a new feature, don't clone a high-level test which calls
> code which calls code which calls the code you need to change.

FWIW, what you propose is the exact opposite of BDD, which suggests we
start at the highest levels and work our way in.

How can you know what the lowest level code is supposed to do before
you have higher level code invoking it? You can certainly make good
guesses, and they might end up being good choices in the end, but they
tend to bind you to a pre-determined design.

Your recommendation also starts with cloning a pre-existing example,
so I'm assuming this is a very specific sort of situation, where you
have a certain amount of code in place. What about when you are
starting a project for the first time?


> Start by cloning the lowest level test possible. If there is none, write
> one. And if the test still wouldn't be low level enough, start by
> refactoring the line you need to change, to pull it out into a method you
> can test directly.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list