ios 7 issues with OCMBlockConstraint/OCMAnyConstraint

Discussion of the OCMock framework. If you have patches we would prefer you to send them to the mailing list, but attaching them to a topic is possible, too.

ios 7 issues with OCMBlockConstraint/OCMAnyConstraint

Postby xneem » 01 Oct 2013, 23:37

All of our tests run correctly in ios 6. However, when we switch to ios 7, we get failed tests with the error message:

[OCMBlockConstraint copyWithZone:]: unrecognized selector sent to instance

or

[OCMAnyConstraint copyWithZone:]: unrecognized selector sent to instance

Example code:

- (void)testWhenSyncUsersIsFinishedThenDaoIsCalled {
[[mockServiceHandler expect] performRequestWithEndpoint:@"users.json"
method:@"GET"
finishedBlock:OCMOCK_ANY];

[testSubject syncUsersDidFinishWithSHA:OCMOCK_ANY];
IMAssertMockVerify(mockServiceHandler);
}

We verified that it works in ios 6, but we can't get the tests to work in ios 7. Thoughts?
xneem
 

Re: ios 7 issues with OCMBlockConstraint/OCMAnyConstraint

Postby lindberg » 04 Oct 2013, 07:17

The problem is this line:

[testSubject syncUsersDidFinishWithSHA:OCMOCK_ANY];

OCMOCK_ANY is used as an indicator with expect/reject/stub methods (that the expectation should match any argument value), but should not be used as arguments in actual calls to real code. It is an instance of a specific subclass of OCMConstraint that will never be the right class in real code. You may have have gotten away with it in iOS6, but it would appear the argument is being stored in a property which is now "copy" on iOS7, used as a key in a dictionary, or something along those lines. OCMConstraint does not implement NSCopying.

I would use either nil, or a dummy value of the appropriate class as the argument on that line.
lindberg
 
Posts: 8
Joined: 04 Oct 2013, 07:05

Re: ios 7 issues with OCMBlockConstraint/OCMAnyConstraint

Postby Vector » 27 Feb 2014, 19:44

I'm using OCMock 2.2.3 and I have the same issue, actually I think the problem is in this line:

finishedBlock:OCMOCK_ANY

When I used OCMOCK_ANY as a parameter in a method that receive a block I got this error "[OCMAnyConstraint copyWithZone:]: unrecognized selector sent to instance"

Example

[[mock expect] someMethod:OCMOCK_ANY successBlock:OCMOCK_ANY];

how can I fix it?
Vector
 

Re: ios 7 issues with OCMBlockConstraint/OCMAnyConstraint

Postby lindberg » 06 Mar 2014, 09:51

Could you break on the exception, and post the backtrace? I'm pretty sure I've used OCMOCK_ANY with block arguments before without issue. It's also possible it's an architecture issue... are you using iOS or MacOS, and which version? If iOS, are you running this on a device, or the simulator? Is it 64-bit or not?
lindberg
 
Posts: 8
Joined: 04 Oct 2013, 07:05


Return to OCMock



cron