@@ -1258,22 +1258,19 @@ - (void)testSerialStoreWithLockDoesntIncrementRefCount
12581258 XCTAssertEqual (header.refCount , 0u , @" refCount must match" );
12591259}
12601260
1261- - (void )testInitNilWhenCannotCreateCacheDirectory
1261+ - (void )testInitSucceedsWhenCannotCreateCacheDirectory
12621262{
12631263 SPTPersistentCacheOptions *options = [SPTPersistentCacheOptions new ];
1264- options.cachePath = [NSTemporaryDirectory () stringByAppendingPathComponent: @" /com.spotify.temppersistent.image.cache" ];
1264+ NSString *filePathBlockingCacheDirectoryCreation = [NSTemporaryDirectory () stringByAppendingPathComponent: @" /com.spotify.temppersistent.image.cache" ];
1265+ options.cachePath = filePathBlockingCacheDirectoryCreation;
12651266 options.cacheIdentifier = @" test" ;
12661267
1267- Method originalMethod = class_getClassMethod (NSFileManager .class , @selector (defaultManager ));
1268- IMP originalMethodImplementation = method_getImplementation (originalMethod);
1269- IMP fakeMethodImplementation = imp_implementationWithBlock (^ {
1270- return nil ;
1271- });
1272- method_setImplementation (originalMethod, fakeMethodImplementation);
1268+ BOOL didCreateBlockingFile = [[NSFileManager defaultManager ] createFileAtPath: filePathBlockingCacheDirectoryCreation contents: nil attributes: nil ];
1269+ XCTAssertTrue (didCreateBlockingFile);
12731270 SPTPersistentCache *cache = [[SPTPersistentCache alloc ] initWithOptions: options];
1274- method_setImplementation (originalMethod, originalMethodImplementation) ;
1271+ [[ NSFileManager defaultManager ] removeItemAtPath: filePathBlockingCacheDirectoryCreation error: nil ] ;
12751272
1276- XCTAssertNil (cache, @" The cache should be nil if it could not create the directory" );
1273+ XCTAssertNotNil (cache, @" The cache should initialise even if it could not create the directory" );
12771274}
12781275
12791276- (void )testFailToLoadDataWhenCallbackAbsent
0 commit comments