Yep. That's why most people who are uncomfortable with mocks are
uncomfortable with mocks.

In my experience mocks work best at well-defined, relatively stable
interfaces to external(ish) services. Otherwise you're testing the
implementation, which makes refactoring difficult. But there are lots
of people who use mocks all the time, so I'll let them make the
arguments in favor...

Stubs and Fakes, however, can be more robust. Don't paint all Test
Doubles with the same brush! :-)

---
Alex Chaffee - a...@stinky.com - http://alexch.github.com
Stalk me: http://friendfeed.com/alexch | http://twitter.com/alexch |
http://alexch.tumblr.com



On Tue, Aug 25, 2009 at 10:12 AM, Denis Haskin<de...@haskinferguson.net> wrote:
> This isn't really an rspec question, but about mocks and stubs in general,
> and maybe I'm looking for some best practices with rspec.
>
> I like mocks and stubs until code starts to change, and then I always get
> frustrated because examples then seem so brittle and sensitive to
> implementation details, which feels wrong to me.
>
> So a small example: this is in an example for a Discount model:
>       @order.should_receive(:line_items).and_return(mock_model(LineItem,
> :size => 2))
> (@order is a mock; I realize it maybe should just be a stub)
>
> The key expectation in this example is:
>       @discount.should_not be_available(@order)
>
> But I changed the implementation of Discount#available? so that it calls
> Order#num_products instead of Order#line_items.  My examples now fail.
>
> Why am I having trouble getting comfortable with this?
>
> Thanks,
>
> dwh
>
>
>
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to