[rspec-devel] [Rspec-users] do we need stubbing?

David Goodlad dgoodlad at gmail.com
Thu Oct 5 15:44:55 EDT 2006

I'm joining this conversation late (and adding yet another 'David' to
the list of participants!), but I just thought I'd chime in...

On 10/5/06, David Chelimsky <dchelimsky at gmail.com> wrote:
> On 10/5/06, Brian Takita <brian.takita at gmail.com> wrote:
> > I talked with David last night. We agreed to make the stub! method quivalent
> > to the expectation:
> > obj.should_receive(:foobar).any_number_of_times
> >
> > So instead of:
> > obj.stub!(:foobar).with(true)
> >
> > one would use:
> > obj.stub!(:foobar).and_return(true)

+1; Why have the duplicated code, when the stub really ends up meaning
an unverified mock...  Looks great to me.

> >
> > Does adding the stub! method to Mock sound good?
> >
> > class Mock
> >   def stub!(method_name)
> >     return should_receive(method_name).any_number_of_times
> >   end
> > end
> That's more or less what I did. Basically there is a
> MockInstanceMethods module with should_receive, should_not_receive and
> stub!. This gets included in Mock and Object and becomes the entry
> point for all mocking (complete, partial) and stubbing.
> It's committed to the trunk, so please check it out and have a look.
> I'm pretty psyched about it.

I love what I'm seeing in the stub-/mock-ing department in rspec.
It's making my specs so much clearer and easier to work with.


Dave Goodlad
dgoodlad at gmail.com or dave at goodlad.ca

More information about the rspec-devel mailing list