Created
May 21, 2015 16:34
-
-
Save benvium/d3e377b368689684c1e0 to your computer and use it in GitHub Desktop.
Inherit from this to automatically create and delete [RLMRealm defaultRealm] files between tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <XCTest/XCTest.h> | |
| // Inherit from this to automatically create and delete [RLMRealm defaultRealm] files between tests | |
| @interface RealmTestCase : XCTestCase | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import "RealmTestCase.h" | |
| #import "RLMRealm.h" | |
| @interface RealmTestCase () | |
| @property(nonatomic, copy) NSString *testRealmPath; | |
| @end | |
| @implementation RealmTestCase | |
| - (void)RLMDeleteRealmFilesAtPath:(NSString *)path { | |
| NSFileManager *fileManager = [NSFileManager defaultManager]; | |
| [fileManager removeItemAtPath:path error:nil]; | |
| NSString *lockPath = [path stringByAppendingString:@".lock"]; | |
| [fileManager removeItemAtPath:lockPath error:nil]; | |
| } | |
| - (void)setUp { | |
| [super setUp]; | |
| self.testRealmPath = [NSString stringWithFormat:@"%@/Library/Caches/test.realm", NSHomeDirectory()]; | |
| [self RLMDeleteRealmFilesAtPath:self.testRealmPath]; | |
| // Optionally override the default realm path. | |
| [RLMRealm setDefaultRealmPath:self.testRealmPath]; | |
| } | |
| - (void)tearDown { | |
| [super tearDown]; | |
| [self RLMDeleteRealmFilesAtPath:self.testRealmPath]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment