Skip to content

Commit cbe71f8

Browse files
committed
Add methods to create new bare and non-bare repositories to GTTestCase.
1 parent cff180a commit cbe71f8

File tree

3 files changed

+33
-25
lines changed

3 files changed

+33
-25
lines changed

ObjectiveGitTests/GTRepositorySpec.m

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,22 @@
1919
});
2020

2121
describe(@"+initializeEmptyRepositoryAtFileURL:bare:error:", ^{
22-
__block GTRepository * (^createRepository)(BOOL bare);
23-
24-
beforeEach(^{
25-
createRepository = ^(BOOL bare) {
26-
NSURL *newRepoURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"unit_test"]];
27-
[NSFileManager.defaultManager removeItemAtURL:newRepoURL error:NULL];
28-
29-
GTRepository *repository = [GTRepository initializeEmptyRepositoryAtFileURL:newRepoURL bare:bare error:NULL];
30-
expect(repository).notTo.beNil();
31-
expect(repository.gitDirectoryURL).notTo.beNil();
32-
return repository;
33-
};
34-
});
35-
3622
it(@"should initialize a repository with a working directory by default", ^{
37-
GTRepository *repository = createRepository(NO);
23+
NSURL *newRepoURL = [self.tempDirectoryFileURL URLByAppendingPathComponent:@"init-repo"];
24+
25+
GTRepository *repository = [GTRepository initializeEmptyRepositoryAtFileURL:newRepoURL bare:NO error:NULL];
26+
expect(repository).notTo.beNil();
27+
expect(repository.gitDirectoryURL).notTo.beNil();
3828
expect(repository.bare).to.beFalsy();
3929
});
4030

4131
it(@"should initialize a bare repository", ^{
42-
GTRepository *repository = createRepository(YES);
32+
NSURL *newRepoURL = [self.tempDirectoryFileURL URLByAppendingPathComponent:@"init-repo.git"];
33+
34+
GTRepository *repository = [GTRepository initializeEmptyRepositoryAtFileURL:newRepoURL bare:YES error:NULL];
35+
expect(repository).notTo.beNil();
36+
expect(repository.gitDirectoryURL).notTo.beNil();
37+
return repository;
4338
expect(repository.bare).to.beTruthy();
4439
});
4540
});
@@ -79,15 +74,6 @@
7974
workdirURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"unit_test"]];
8075
});
8176

82-
afterEach(^{
83-
if ([NSFileManager.defaultManager fileExistsAtPath:workdirURL.path isDirectory:NULL]) {
84-
NSError *error = nil;
85-
BOOL success = [NSFileManager.defaultManager removeItemAtURL:workdirURL error:&error];
86-
expect(success).to.beTruthy();
87-
expect(error).to.beNil();
88-
}
89-
});
90-
9177
it(@"should handle normal clones", ^{
9278
NSError *error = nil;
9379
repository = [GTRepository cloneFromURL:originURL toWorkingDirectory:workdirURL options:nil error:&error transferProgressBlock:transferProgressBlock checkoutProgressBlock:checkoutProgressBlock];

ObjectiveGitTests/GTTestCase.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,10 @@
2929
// A repository containing conflicts.
3030
- (GTRepository *)conflictedFixtureRepository;
3131

32+
// A pristine repository (bare).
33+
- (GTRepository *)blankBareFixtureRepository;
34+
35+
// A pristine repository.
36+
- (GTRepository *)blankFixtureRepository;
37+
3238
@end

ObjectiveGitTests/GTTestCase.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,22 @@ - (GTRepository *)conflictedFixtureRepository {
114114
return [self fixtureRepositoryNamed:@"conflicted-repo"];
115115
}
116116

117+
- (GTRepository *)blankFixtureRepository {
118+
NSURL *repoURL = [self.tempDirectoryFileURL URLByAppendingPathComponent:@"blank-repo"];
119+
120+
GTRepository *repository = [GTRepository initializeEmptyRepositoryAtFileURL:repoURL bare:NO error:NULL];
121+
STAssertNotNil(repository, @"Couldn't create a blank repository");
122+
return repository;
123+
}
124+
125+
- (GTRepository *)blankBareFixtureRepository {
126+
NSURL *repoURL = [self.tempDirectoryFileURL URLByAppendingPathComponent:@"blank-repo.git"];
127+
128+
GTRepository *repository = [GTRepository initializeEmptyRepositoryAtFileURL:repoURL bare:YES error:NULL];
129+
STAssertNotNil(repository, @"Couldn't create a blank repository");
130+
return repository;
131+
}
132+
117133
#pragma mark Properties
118134

119135
- (NSBundle *)mainTestBundle {

0 commit comments

Comments
 (0)