-(void)testNSObjectCancelPreviousPerformRequestsExpectationMock
{
XCTestExpectation *cancelExpectation = [self expectationWithDescription:@"cancel callback"];
id objectMock = OCMClassMock([NSObject class]);
[[[objectMock stub] andDo:^(NSInvocation *invocation)
{
NSLog(@"Reached!");
[cancelExpectation fulfill];
}] cancelPreviousPerformRequestsWithTarget:self
selector:@selector(startWriteSettingsLogFileOperationForAccountId:)
object:nil];
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(startWriteSettingsLogFileOperationForAccountId:) object:nil];
[self waitForExpectationsWithTimeout:10 handler:nil];
}
如上述测试用例所示,对NSObject的cancelPreviousPerformRequestsWithTarget进行存根时,会间歇性地导致“无类的元类”错误。