- (void)testStringExample {
// Given
NSString *testString = @"Test";
id mock = OCMClassMock([NSString class]);
OCMStub([mock stringWithContentsOfFile:OCMOCK_ANY
encoding:NSUTF8StringEncoding
error:nil]).andReturn(testString);
// When
NSString *result = [NSString stringWithContentsOfFile:@"SomeFilePath"
encoding:NSUTF8StringEncoding
error:nil];
// Then
XCTAssertEqualObjects(result, testString);
}
As you can see I've been trying to stub an NSString class method using OCMock but don't seem to be having any luck. The test fails indicating that "(null)" is not equal to "Test" but I'm not sure why the mocked method isn't being called correctly. I'm using OCMock 3.1.2 on iOS. Any help greatly appreciated.