OCMock offers a nice syntax to mock class methods, but can class method calls be forwarded to the real class object?
self.connectionMock = [OCMockObject mockForClass:NSURLConnection.class];
[[[[self.connectionMock stub] andDo:^(NSInvocation *invocation) {
NSURL *url = [invocation getArgumentAtIndexAsObject:2];
NSLog(@"Passing through mock: %@", url);
} ] andForwardToRealObject] connectionWithRequest:OCMOCK_ANY delegate:OCMOCK_ANY];
The problem is andForwardToRealObject
only works for partials. I could do the method swizzling myself, but is there an easy way for me to call the original class method using OCMock?
Class
is not anNSObject
so you can't create a partial mock on it. If you try to create a partial mock on an instance, it won't be able to forward the class method because it is not searching the class method selectors. – Macdougall