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

Brian Takita brian.takita at gmail.com
Wed Oct 4 21:53:01 EDT 2006


I like the Object#stub! method because it's syntax is more focused and
clearer than using a mock for the purpose of stubbing a method.

obj.stub!(:foobar).with(true)
vs.
obj.should_receive(:foobar).and_return(true).any_number_of_times

The stub method also communicates my intention to stub out the method, just
as mocking the method communicates my intention to verify that a certain
message was passed to the object. I believe this makes my tests/specs
clearer.

Also, stub! is a method of Object. If we where to replace it with partial
mocking, we would have to move partial mocking to Object to replace this
behaviour.

On 10/4/06, aslak hellesoy <aslak.hellesoy at gmail.com> wrote:
>
> On 10/4/06, David Chelimsky <dchelimsky at gmail.com> wrote:
> > Hey all -
> >
> > The trunk currently supports three types of mocking/stubbing:
> >
> > Mock Objects (created dynamically at runtime)
> > Partial Mocking of methods on existing classes
> > Stubbing of methods on existing objects or classes
> >
> > The main difference between Partial Mocking and Stubbing is that Stubs
> > don't verify.
> >
> > I'm wondering if we really need the stubbing facility at all, given
> > that we can do the same thing using Partial Mocks. If we decided to
> > yank the Stubs, we could add Partial Mocks support to objects (right
> > now it only works on classes).
> >
>
> Sounds good to me.
>
> Just to be precise - one or more methods could be mocked on an
> individual *Object* (Class is an Object). So this would work for any
> Object, not just Class. Right?
>
> I don't see a lot of value in stubbing without verification if partial
> mocking (or should we call it "object method mocking" to be more
> precise?) can be used on *any* object.
>
> > Note that this functionality is not part of a release yet, so any such
> > changes would only affect the brave trunk-dwellers among you.
> >
> > Any thoughts on this? Can anyone explain to me why stubs are useful in
> > addition to partial mocks?
> >
>
> I can't think of a compelling reason.
>
> Cheers,
> Aslak
>
> > David
> > _______________________________________________
> > Rspec-users mailing list
> > Rspec-users at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> >
> _______________________________________________
> rspec-devel mailing list
> rspec-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-devel/attachments/20061004/2e40efb1/attachment.html 


More information about the rspec-devel mailing list