-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathGTBlobSpec.m
More file actions
98 lines (80 loc) · 2.5 KB
/
GTBlobSpec.m
File metadata and controls
98 lines (80 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// GTBlobSpec.m
// ObjectiveGitFramework
//
// Created by Etienne Samson on 2013-11-07.
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
//
@import ObjectiveGit;
@import Nimble;
@import Quick;
#import "QuickSpec+GTFixtures.h"
QuickSpecBegin(GTBlobSpec)
__block GTRepository *repository;
__block NSString *blobSHA;
__block GTBlob *blob;
describe(@"blob properties can be accessed", ^{
beforeEach(^{
repository = self.bareFixtureRepository;
blobSHA = @"fa49b077972391ad58037050f2a75f74e3671e92";
blob = [repository lookUpObjectBySHA:blobSHA objectType:GTObjectTypeBlob error:NULL];
expect(blob).notTo(beNil());
});
it(@"has a size", ^{
expect(@(blob.size)).to(equal(@9));
});
it(@"has content", ^{
expect(blob.content).to(equal(@"new file\n"));
});
it(@"has type", ^{
expect(blob.type).to(equal(@"blob"));
});
it(@"has a SHA", ^{
expect(blob.SHA).to(equal(blobSHA));
});
});
describe(@"blobs can be created", ^{
beforeEach(^{
repository = self.testAppFixtureRepository;
});
describe(@"+blobWithString:inRepository:error", ^{
it(@"works with valid parameters", ^{
NSError *error = nil;
blob = [GTBlob blobWithString:@"a new blob content" inRepository:repository error:&error];
expect(error).to(beNil());
expect(blob).notTo(beNil());
expect(blob.SHA).notTo(beNil());
});
});
describe(@"+blobWithData:inRepository:error", ^{
it(@"works with valid parameters", ^{
char bytes[] = "100644 example_helper.rb\00\xD3\xD5\xED\x9D A4_\x00 40000 examples";
NSData *content = [NSData dataWithBytes:bytes length:sizeof(bytes)];
NSError *error = nil;
blob = [GTBlob blobWithData:content inRepository:repository error:&error];
expect(error).to(beNil());
expect(blob).notTo(beNil());
expect(blob.SHA).notTo(beNil());
});
});
describe(@"+blobWithFile:inRepository:error", ^{
it(@"works with valid parameters", ^{
NSString *fileContent = @"Test contents\n";
NSString *fileName = @"myfile.txt";
NSURL *fileURL = [repository.fileURL URLByAppendingPathComponent:fileName];
NSError *error = nil;
BOOL success = [fileContent writeToURL:fileURL atomically:YES encoding:NSUTF8StringEncoding error:&error];
expect(@(success)).to(beTruthy());
expect(error).to(beNil());
blob = [GTBlob blobWithFile:fileURL inRepository:repository error:&error];
expect(error).to(beNil());
expect(blob).notTo(beNil());
expect(blob.SHA).notTo(beNil());
expect(blob.content).to(equal(fileContent));
});
});
});
afterEach(^{
[self tearDown];
});
QuickSpecEnd