Possible to only stub method call with a specific parameter and leave other calls alone?

Skip to first unread message

Jakob Hilden

Jul 26, 2011, 7:13:11 PM7/26/11
to mocha-developer
Hi everybody,

does anybody know whether it is possible with Mocha to stub a method
call only with a specific paramter and to let all other method calls
go through and return the regular value?

Here is some code to further explain the problem

class MyObject
def my_method(parameter)
return "foo-#{parameter}"


What I would like to have is that MyObject.my_method("A") should
return "bar" and all other invocations of that method (e.g.
MyObject.my_method("B")) should return the regular "foo-B", and so
on. But what happens with only the stub above is that I get an
"unexpected invocation: MyObject.my_method("B")" error :(

Does anybody have an idea?

Thank you,

Reply all
Reply to author
0 new messages