I wrote the following Unit Test in OCMockObjectTests.m:
- (void)testNSPredicateBug
{
id mock1 = [OCMockObject mockForClass:[TestClass class]];
[[[mock1 stub] andReturn:@"match"] uid];
[[[mock1 stub] andReturn:@"match"] valueForKey:@"uid"];
id mock2 = [OCMockObject mockForClass:[TestClass class]];
[[[mock2 stub] andReturn:@"not"] uid];
[[[mock2 stub] andReturn:@"not"] valueForKey:@"uid"];
NSArray *array = [NSArray arrayWithObjects:mock1, mock2, nil];
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"uid = %@", "match"];
NSArray *matchArray = [array filteredArrayUsingPredicate:predicate];
STAssertTrue([matchArray count] == 1, @"");
}
It looks that NSPredicate converts the @"uid = "match"" such that uid becomes NSString. However the valueForKey=@"uid" converts @"uid" into NSConstantString. When OCMockRecorder is checked to see if the invocation works it checks to see if the classes are the same, however these two dont match classes.
A workaround is to use the [OCMArg checkWithSelector:@selector(isEqualToString:) onObject:@"uid"]
I wasnt sure if this is a place to log this bug, but figured others might run into this same problem.