Mock with ARC enabled

Discussion of the OCMock framework. If you have patches we would prefer you to send them to the mailing list, but attaching them to a topic is possible, too.

Mock with ARC enabled

Postby Steven31 » 22 Jul 2011, 01:45

Im trying to mock a NSFilemanager with ARC enabled however i can't get the mock to not throw an exception for the following lines

Code: Select all
- (void)testFileCopiedIntoDocumentsDir
    id mockManager = [OCMockObject mockForClass:[NSFileManager class]];
    // the following two lines are what are causing problems
    NSError *error = (__bridge NSError *)[OCMArg anyPointer];
    [[mockManager expect] copyItemAtURL:[OCMArg any] toURL:[OCMArg any] error:&error];
    BOOL success = [fileImporter importFileAtURL:src withFileManger:mockManager];
    STAssertEquals(YES, success, @"The file should return that it has been successfully imported");
    [mockManager verify];

// implementation of importFileAtURL:withFileManager:
- (BOOL)importFileAtURL:(NSURL *)url withFileManger:(NSFileManager *)fileManger
    NSURL *toURL = [self createDocumentURLfromSrcURL:url];
    NSError *error = nil;
    [fileManger copyItemAtURL:url toURL:toURL error:&error];
    if (error)
        return NO;
    return YES;

- (NSURL *)createDocumentURLfromSrcURL:(NSURL *)srcURL
    NSURL *destURL = [[myMusicStandAppDelegate sharedInstance] applicationDocumentsDirectory];
    return [destURL URLByAppendingPathComponent:[srcURL lastPathComponent] isDirectory:NO];
Posts: 1
Joined: 22 Jul 2011, 01:35

Return to OCMock