OCMock does not drown the NSBundle method

I have been using OCMock recently for my unit testing. I need to objectForInfoDictionaryKey: from NSBundle . I have done the following:

 self.bundleMock = OCMClassMock([NSBundle class]); OCMStub([self.bundleMock objectForInfoDictionaryKey:@"GITHash"]).andReturn(@"c424242"); ; 

Here is the call I want to drown out:

 NSString * appHashString = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"GITHash"]; 

But nothing seems to have sharpened, at runtime I still have the “correct” meaning.

What have I done wrong?

+5
source share
1 answer

I might be wrong, but I think you need to use partialMockForObject to make fun of the instance returned by [NSBundle mainBundle] , instead of taunting the NSBundle class, because objectForInfoDictionaryKey is an instance method, not a class method.

+5
source

All Articles