[rspec-users] Slides from "Uses & Abuses of Mocks & Stubs" at NWRUG

Ashley Moran ashley.moran at patchspace.co.uk
Wed Oct 21 09:26:38 EDT 2009

On 21 Oct 2009, at 09:46, Pat Maddox wrote:
> Response written as I go through the slides, and late at night under
> sleep deprivation ;)

Seems fitting, I wrote them under the exact same conditions =)

> * 57 juicy slides in half an hour?  Damn dude.

Well, might have had about 45-50 mins, but there were plenty of  
questions in the middle.  Didn't have time to prune the slides down  
before the presentation.  I was ready to collapse at the end :)

Would have had longer, but Boxedup.com sponsored free pizza at the bar  
opposite.  So literally before I'd shut my laptop lid, there was a  
mass stampede out of the building...

> * Not a fan of the "defining an interface" service example.  A single
> method named #query that accepts a string that appears to have the
> real command is not much of an interface.  What about something like
> service.should_receive(:store).with(:first_name => 'Fred', :last_name
> => 'Flintstone') ?

I think you're right.  Your example is better.

> * I dig the be_equivalent_xml_to matcher

Our implementation is a bit simplistic, but it's still useful.  I've  
put it up as a gist for it[1] in case anyone else finds it useful.

> * On the Simulating Situations slide I would stub the call to #save
> instead of expecting it.  You're just setting up context for the
> example to run in.

Ah, I just didn't know off the top of my head how to make a stub  
method raise an error.  You're right though, it would be much better  
if I had.

> * may be a style thing but in your Degrees of Freedom shapes examples
> I don't like creating the shapes in a before. Just inline it

It's funny you say that, when I wrote it I was thinking it was not  
necessary to use a before block, but "that's the style I like".  I  
almost always separate out the SUT from the examples.  I think it goes  
back to the days when I thought in rigid Given-When-Then terms.

> * the shape example where you pass in a mock is really weird to me.
> What are you trying to illustrate?  A different example might be more
> effective (or I just need to hear the commentary that goes with that
> slide)

Someone else raised an issue with the same slide, so it must really  
suck.  The fact the example is written around a getter should have  
raised an exception in my head (NotEnoughSleepError).  A much better  
example is slide 30 (Hiding Random Behaviour) where @first and @values  
are used in the same manner (to reduce the need to triangulate to  
prove the implementation is not degenerate).

> Over all it looks like a great introduction to the benefits, use, and
> pitfalls of mocks.  Thanks for sharing.

Thanks for the feedback!  It's the most detailed I've had so far.  If  
I repeat the presentation I'll make all the changes you suggested.   
Except for the liberal use of before blocks :)

Also I should probably add that at the end, when I was reading the  
references, one of the comments I made was along the lines of "I  
finally got round to reading the RSpec Book chapter on mocks the other  
day, and I was really disappointed.  It said everything I was trying  
to, really clearly, and I was tempted to just turn up and read it out  
loud.  So go look at that next."  I daren't read the rest of the new  
chapters in case it makes the rest of my job redundant =)


[1] http://gist.github.com/215089


More information about the rspec-users mailing list