I created the following class:
@implementation BCGlobalConstantBox
+ (instancetype)sharedInstance {
static BCGlobalConstantBox *instance = nil;
static dispatch_once_t predicate;
dispatch_once( &predicate, ^{
instance = [[self alloc] init];
});
return instance;
}
- (NSString *)someMethod {
return nil;
}
@end
Then I added OCMock via sources (simply added files to my project). I use it not for testing but as temp data in usual debug target.
The following code works:
id goalObj = [BCGlobalConstantBox class];
id mock = [OCMockObject niceMockForClass:goalObj];
// id mock = [OCMockObject partialMockForObject:[goalObj sharedInstance]];
NSArray *arr = @[@1, @2, @3];
[[[mock stub] andReturn:@"123"] someMethod];
id obj = [[BCGlobalConstantBox sharedInstance] someMethod];
But if I uncomment the line with "mock" initialization instead of the working one then the whole code doesn't work properly (obj must be equal @"123").
I want to add the functionality for the whole class, not one object only. What is incorrect in my code?
P.S. mockForClass:
and niceMockForClass:
both don't work.