I'm trying to create a mock for AFNetworking's AFHTTPRequestOperationManager using OCMock
This is what I've got:
id mockRequestManager = OCMClassMock([AFHTTPRequestOperationManager class]);
OCMStub([mockRequestManager manager]).andReturn(mockRequestManager);
[myObject methodThatUsesAFHTTPRequestOperationManager];
I've done this exact thing before for other singletons ([NSNotificationCenter defaultCenter]
for example), but with AFHTTPRequestOperationManager, I'm not getting back the mocked object when [AFHTTPRequestOperationManager manager]
is called from [myObject methodThatUsesAFHTTPRequestOperationManager]
. I always get back the AFHTTPRequestOperationManager instance object.
Am I missing something? Is there some implementation detail of AFHTTPRequestOperationManager that's preventing this from working?
EDIT
So, after looking through the AFHTTPRequestOperationManager code, it turns out it's not actually a singleton, just a class method that returns a new AFHTTPRequestOperationManager object. However, I still don't understand why stubbing the class method isn't returning the my mock object instead of creating a new one.