[Rspec-devel] Mock feature thoughts

Judson Lester nyarly-rspec at redfivellc.com
Mon Aug 28 18:46:58 EDT 2006


David Astels wrote:
>
> That might be your problem.  You're not mocking objects.. or even  
> classes.. you're mocking interfaces (whether literally as in Java, or  
> conceptually in a real.. ahem dynamic language
Certainly.  But the fact is that implicitly when I add #method to the
interface of a class, the #respond_to? method changes.  Unless I rewrite
it.  This is a Good Thing.
> >> Specifically, if I write something like
> >>
> >> thing_mock=mock("thing")
> >> thing_mock.should_receive(:a_message).and_return("message received")
> >>
> >> I'd love to have thing_mock implicitly do something like
> >> thing_mock.should_receive(:respond_to?).with(:a_message).and_return
> >> (true).any_number_of_times
> >>
> >> Unless, of course I were to explicitly specify some other behavior for
> >> #respond_to?>> thing_mock=mock("thing")
> >> thing_mock.mock_ancestors(["Object", "MyParentClass", "MyClass"])
>
> part of the joy of dynamic languages is that that stuff doesn't  
> matter 99% of the time.  You focus should be "what it does" not "what  
> it is"
Certainly.  But there are cases, and I'd argue closer to 10% of the
time, where checking up front that an object does what it needs to do
before you need it to do it (in other words: duck typing) is amazingly
useful.  But not especially part of the behavior of the object.

The place I'm arguing from, (and one might notice a theme in my
suggestions on this note) is one which I picked up from Martin Fowler's
Refactoring book.  Which is basically laziness.  I know that the easier
it is for me to write specs, and to use them, and the more I get out of
using them, the more I _will_ use them.

In that vein (and apologies for the misplaced praise) the recent rewrite
of the Stack example is a real boon.  It's an excellent direction on how
convention can save effort.

But, I'd like to see _implementation_ save effort as well, if that makes
sense.  For the same reason that we do spec specs/*.  Because it's
easy.  You don't think about it.

I'm all for building levees across Bad Directions, but I'm more for
digging the river deeper under Good Directions.

Judson






More information about the Rspec-devel mailing list