Refactoring-friendly stubbing

87 views
Skip to first unread message

Ryan Hanks

unread,
Dec 11, 2012, 11:47:07 AM12/11/12
to mock...@googlegroups.com
Hi,

I prefer the refactoring-friendly approach to setting expectations. Could Mockolate take a similar approach when stubbing? For example:

stub(subject.property_a).returns(nice_a);

as opposed to:

stub(subject).getter("property_a").returns(nice_a);

Or, is there a way of doing this in a refactoring-friendly manner?

Thanks.


Hob Spillane

unread,
Dec 11, 2012, 11:52:59 AM12/11/12
to mock...@googlegroups.com

Yes.  You can use

expect(subject.doSomething(arg(someValue))).returns(someOptionalValue);

Note the "arg()" in the middle.  Wrap that around ant arguments passed to your expected method.

expect() is the equivalent of mock() and allow() replaces stub().

-Hob

Drew Bourne

unread,
Dec 11, 2012, 12:33:11 PM12/11/12
to mock...@googlegroups.com
Use allow() instead of expect() to set stub expectations. 

    allow(subject.property_a).returns(nice_a);

HTH, 
Drew

Ryan Hanks

unread,
Dec 12, 2012, 9:47:30 PM12/12/12
to mock...@googlegroups.com
Thanks!
Reply all
Reply to author
Forward
0 new messages