Mocking a call out, matching specific parameters but not others

Skip to first unread message

Grant Schoep

Nov 9, 2018, 9:59:22 PM11/9/18
to mocha-developer
Ok  I've been banging away it this problem for hours.

I am trying to mock out a call to a class and verify certain parameters match exactly, but not care about the others

So the class I am testing, lets call it SomethingElse

class SomethingElse
  def blah'SomeKey', 1234, 

So I have been doing this.

object = mock

test_obj =

This works fine, but I want my test to verify those first two parameters on I know what they must be, the third can be anything(just picking to make that clear)

I tried something like this, of course anything didn;'t work there. 

MyClass.expects(:new).with("SomeKey", 1234, anything).returns(object)

Reading more, I thought includes might help. I tried

MyClass.expects(:new).with(includes("SomeKey", 1234)).returns(object)

But I got some error on converting integer to string. I've dug and tried all sorts of other things. I figure I am missing some simple aspect of this I am missing.

I am still pretty new to Mocha, so this is probably something dead simple...


Nov 10, 2018, 4:27:09 AM11/10/18
to mocha-developer
Hi Grant,

I hope you don't mind, but I've opened a new issue [1] on the Mocha GitHub repo to capture this.

Regards, James.

Reply all
Reply to author
0 new messages