[rspec-users] Four Question From an RSpec Baby - Give me something to chew

Mark Wilden mark at mwilden.com
Thu Sep 4 20:50:04 EDT 2008

On Thu, Sep 4, 2008 at 4:14 PM, Nick Hoffman <nick at deadorange.com> wrote:

> However, I'm not a fan of mocking and stubbing, primarily for two reasons:
> 1) I believe that specs should test behaviour, rather than a behaviour's
> implementation.

"Behavior" (to me) means "what it does." "What it does" means how it
interacts with other objects. If you make sure it interacts with other
objects properly (and you make sure those other objects also behave
correctly) you have a confidence-inspiring  spec.

The alternative is to test state, which could be termed "what it is." I
think you may be saying you prefer that approach, which is completely valid.
Martin Fowler wrote the canonical article on the difference between these
two approaches.

2) Using mocks and stubs causes your specs and implementation to be tightly
> coupled, which often forces you to modify your specs if changes occur in the
> implementation.

That's completely true. However, you are shielded from -other- classes'
implementation. With state-based testing, everything has to be correct all
the way down. With behavior-based testing, you're only testing one thing at
a time.

I haven't been working with mock objects all that long myself, so anything
I've said here is subject to contradiction by someone who really knows what
they're talking about. :)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080904/016e912d/attachment-0001.html>

More information about the rspec-users mailing list