Sometimes I get a EXC_BAD_ACCESS when running this test:
- (void)testThatItDoesNotSaveLoadedImageIfNotIntializedWithModifiesFileCacheOption {
id cacheMock = OCMClassMock([BEImageCache class]);
id imageLoaderMock = OCMClassMock([BEImageLoader class]);
BETwoLayerCacheImageProvider *imageProvider = [[BETwoLayerCacheImageProvider alloc] initWithCache:cacheMock imageLoader:imageLoaderMock options:0 scale:2.f];
UIImage *expectedImage = [UIImage new];
[[cacheMock reject] saveImageAtURLInFileCache:[OCMArg any] forURL:[OCMArg any]];
[[cacheMock reject] saveImageInFileCache:[OCMArg any] forURL:[OCMArg any]];
__block NSURL *URL = [NSURL fileURLWithPath:@"/file:///fixtureURL"];
__block typeof(self) welf = self;
OCMStub([imageLoaderMock downloadImageWithURL:[OCMArg any] completionCallback:[OCMArg any]]).andDo(^(NSInvocation *invocation) {
///[invocation retainArguments];
void (^callback)(UIImage *image, NSError *error, NSString *imageURL, NSURL *temporaryImageURL) = nil;
[invocation getArgument:&callback atIndex:3];
callback(expectedImage, nil, welf.smallImageURL, URL);
});
[imageProvider fetchImageForImageData:self.imageData size:self.smallImageSize withCompletionCallback:^(UIImage *anImage, id<BEImageAware> imageData, CGSize requestedSize) {
OCMVerifyAll(cacheMock);
}];
}
EXC_BAD_ACCESS happens here:
- (void)forwardInvocationForClassObject:(NSInvocation *)anInvocation
{
// in here "self" is a reference to the real class, not the mock
OCClassMockObject *mock = OCMGetAssociatedMockForClass((Class) self, YES);
if(mock == nil)
{
[NSException raise:NSInternalInconsistencyException format:@"No mock for class %@", NSStringFromClass((Class)self)];
}
if([mock handleInvocation:anInvocation] == NO)
{
[anInvocation setSelector:OCMAliasForOriginalSelector([anInvocation selector])];
[anInvocation invoke]; /// EXC_BAD_ACCESS
}
}
The weird thing is that it never crashes when I run only this one test, but I crashes almost always when I tun all my tests (with cmd+u).
I tried to add [invocation retainArguments]
, it did not help, and I think should not be here.
Anyone had such problems?