[rspec-users] Adding Test Spy into Rspec mocking framework

Joseph Wilk josephwilk at joesniff.co.uk
Wed Oct 8 05:05:10 EDT 2008

Brian Takita wrote:
> On Sun, Sep 21, 2008 at 11:17 AM, Joseph Wilk <lists at ruby-forum.com> wrote:
>> I've been doing further work on adding the Test Spy to the RR mocking
>> framework.
> Awesome! Do you have a clone available?
I'm not quite ready to push my work up to Github. I've been trying lots 
of spikes experimenting with what a spy means in RR. I'll let you know 
as soon as I push my work up to github.

I'll share my thoughts so far on what I think RR's interpretation of a 
Spy could be. In the traditional sense a spy is a stub object that 
records method invocations.

But RR is all about taking real objects and using double injection. It 
feels out of place to introduce a stub object as a spy. So the direction 
I've been leaning towards is a spy should be a real object that logs its 
calls. Those calls follow the real implementation. You can still stub 
the spy.

This feels like the most natural solution for RR, though its much harder 
to implement than just a stub object :)

class Example
  def shout(words)

example = Example.new

 >> "monkeys!"


Whats your opinion Brian? Anyone else?

Oh, I've really enjoyed going through RR's source and I've learnt a lot 
from it, thanks!
Joseph Wilk

More information about the rspec-users mailing list