ocmock: OCMVerify causing EXC_BAD_ACESS
I’ve been using OCMock 2 for many months along side Specta without issue. Recently I upgraded to 3 and began using the OCMVerify macro for verify-after-running. In certain instances I am receiving EXC_BAD_ACCESS when the invocation matcher is matching arguments, specifically if(([recordedArg isEqual:passedArg] == NO)
. It seems the the passedArg is released by ARC at some point and by the time it is pulled out of the invocation it is gone.
I’m not 100% where the issue lies and I can’t seem to be able to replicate this is a sample project to provide as an example for this issue. It seems to happen more on iOS 64bit simulator than 32bit, but it isn’t everytime.
The layout of my tests look something like this:
SpecBegin(Spec)
describe(@"Spec", ^{
__block TestSubject *subject;
__block id mockObject;
beforeAll(^{
mockObject = OCMClassMock([MyObject class]);
subject = [[TestSubject alloc] initWithObject:mockObject];
});
describe(@"when something happens", ^{
beforeAll(^{
MyInvocation successfulInvocation = [ArrangeInvocation successfulInvocation];
OCMStub([mockObject anotherMethod]);
.andDo(successfulInvocation);
[subject doSomething];
});
it(@"does something", ^{
OCMVerify([mockObject methodCalledWithParam:[SomeParam param]
completionHandler:OCMOCK_ANY]);
});
});
});
SpecEnd
I have been able to work around this issue by moving the expectation to before the tests run but ideally would like to use the new features of OCMock 3. I’m just not sure where to start diagnosing this and as I said can’t seem to replicate the issue outside of my main codebase.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 1
- Comments: 17 (4 by maintainers)
Just to throw my hat into the ring, I believe I’m seeing the same issue in 3.2. The argument for the invocation, which is an NSString, is not retained by the object being partially mocked. This causes a crash most of the time.
When I retain the argument in a contrived way – by adding the argument to a mutable array that’s retained by the object – it no longer crashes.