OCMockito: how do you express "any CGRect" when verifying a function call parameter?

100 Views Asked by At

Let's say that I have a method like this

[SomeObject someMethod:(id)object someRect:(CGRect)rect];

When doing unit test, I want to very that this function is called with a specific object and any rect, but this code doesn't work:

[verifyCount(mockObject, MKTTimes(1)) someMethod:HC_equalTo(message) someRect:HC_anything()];

Compiler would say that HC_anything is not a CGRect.

Is there any way to solve this?

1

There are 1 best solutions below

0
Jon Reid On
[[verify(mockObject) withMatcher:anything() forArgument:1]
    someMethod:message someRect:CGRectZero];

Basically, pass in a rect that will be ignored, because we've overridden the matching using withMatcher:forArgument:

…Note that verify is short for verifyCount with times(1). Also, passing message directly is short for equalTo(message).