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
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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
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 :(