I found an issue where OCMock would cause stack overflow and crash in certain situations. I have wrote an example test code to replicate the problem:
- Code: Select all
- (void)testRevertsMultipleExpectsOnStopMocking
{
id mock = [[OCClassMockObject alloc] initWithClass:[TestClassWithClassMethods class]];
[[[[mock expect] classMethod] andReturn:@"mocked-foo"] foo];
[[[[mock expect] classMethod] andReturn:@"mocked-foo2"] foo];
STAssertEqualObjects(@"mocked-foo", [TestClassWithClassMethods foo], @"Should have stubbed class method 'foo'.");
STAssertEqualObjects(@"mocked-foo2", [TestClassWithClassMethods foo], @"Should have stubbed class method 'foo2'.");
[mock stopMocking];
STAssertEqualObjects(@"Foo-ClassMethod", [TestClassWithClassMethods foo], @"Should have 'unstubbed' class method 'foo'.");
}
The above code performs expect twice on a class method, which is possible with instance methods. However, it seems to crash with stack overflow in this case. The same issue seems to exist for stubs too.
Is this an expected behaviour? If they are, I think it would be nice to have a little note on the documentation (I'm assuming that the only documentation is http://ocmock.org/features/ ), or have the OCMock print out errors in the console.