erikdoe / ocmock

Mock objects for Objective-C
http://ocmock.org
Apache License 2.0
2.16k stars 606 forks source link

OCMVerify() on Partial Mocks does not work with selectors implemented by NSObject/NSProxy #408

Closed dmaclach closed 4 years ago

dmaclach commented 4 years ago
    UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
    id mock = [OCMockObject partialMockForObject:view];
    [realObject accessibilityLabel];
    OCMVerify([mock accessibilityLabel]);

reports Method accessibilityLabel was not invoked; but was expected at least once.

This is a very confusing error because it's obviously being called. The problem is that OCMPartialMock does not set itself up to handle any methods implemented by NSObject or NSProxy. All of the accessibility methods are informal protocols (i.e. categories) on NSObject. This can be done by using OCMExpect([mock accessibilityLabel]) and OCMVerifyAll(mock).

dmaclach commented 4 years ago

Thanks for the merge.