I'm experimenting with using OCMock but so far my simple experiment is failing. Given this experimental class that I want to mock:
@interface HTTPConnection : NSObject <NSURLConnectionDelegate>
@property (strong, nonatomic) NSURLConnection *connection;
-(int) makeConnection:(NSString*) url; // implementation returns 5
@end
When I invoke the following test case, the result variable contains 5 not 15 thus the real object method got invoked and not the mock one:
- (void)testExample
{
id connection = [OCMockObject mockForClass:[HTTPConnection class]];
[[[connection stub] andReturn: [NSNumber numberWithInt: 15]] makeConnection:[OCMArg any]];
HTTPConnection* realConnection = [[HTTPConnection alloc] init];
int result = [realConnection makeConnection:@"http://www.anything.com"];
}