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

98 views
Skip to first unread message

Jakob Hilden

unread,
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}"
end
end

MyObject.stubs("my_method").with("A").returns("bar")

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,

--Jakob
Reply all
Reply to author
Forward
0 new messages