I have a class method which I would like to mock and return one of the arguments that was passed in. Something like this in my code:
converted_data = Myclass.convert(arg, some_other_arg, data)
And in my test I would like to be able to do the following (although this doesn’t work).
Myclass.should_receive(:convert).with(*args).and_return(args[2])
So the method doesn’t actually do anything! If I run as written above, I get an error that it doesn’t know what args is to return it.
I found the answer:
To return a specific argument, pick it from the array within the
and_returnblock! So for your example, it would be:You likely want to do this on an instance of
Myclass.