Skip to content

Commit

Permalink
Remove verify-after-running of class methods.
Browse files Browse the repository at this point in the history
Since iOS 9, class_addMethod and class_replaceMethod flush ObjC cache
unconditionally, which makes testing slow by a huge factor. Removing
this code avoids many such calls, and still enables mocking and stubbing
of class method, but it requires them to happen before running.
  • Loading branch information
StatusReport committed Oct 20, 2015
1 parent a3e1580 commit 6d8f2c5
Showing 1 changed file with 0 additions and 24 deletions.
24 changes: 0 additions & 24 deletions Source/OCMock/OCClassMockObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,30 +106,6 @@ - (void)prepareClassForClassMethodMocking
Method myForwardMethod = class_getInstanceMethod([self mockObjectClass], @selector(forwardInvocationForClassObject:));
IMP myForwardIMP = method_getImplementation(myForwardMethod);
class_addMethod(newMetaClass, @selector(forwardInvocation:), myForwardIMP, method_getTypeEncoding(myForwardMethod));


/* adding forwarder for most class methods (instance methods on meta class) to allow for verify after run */
NSArray *methodBlackList = @[@"class", @"forwardingTargetForSelector:", @"methodSignatureForSelector:", @"forwardInvocation:", @"isBlock",
@"instanceMethodForwarderForSelector:", @"instanceMethodSignatureForSelector:"];
[NSObject enumerateMethodsInClass:originalMetaClass usingBlock:^(Class cls, SEL sel) {
if((cls == object_getClass([NSObject class])) || (cls == [NSObject class]) || (cls == object_getClass(cls)))
return;
NSString *className = NSStringFromClass(cls);
NSString *selName = NSStringFromSelector(sel);
if(([className hasPrefix:@"NS"] || [className hasPrefix:@"UI"]) &&
([selName hasPrefix:@"_"] || [selName hasSuffix:@"_"]))
return;
if([methodBlackList containsObject:selName])
return;
@try
{
[self setupForwarderForClassMethodSelector:sel];
}
@catch(NSException *e)
{
// ignore for now
}
}];
}

- (void)setupForwarderForClassMethodSelector:(SEL)selector
Expand Down

0 comments on commit 6d8f2c5

Please sign in to comment.