Skip to content

Convert Tests to Specs. #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Nov 18, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
618570b
Rewrite tests for GTBlob.
tiennou Nov 7, 2013
ed0a2a8
Use `git_blob_create_fromdisk` instead of going through the `fromwork…
tiennou Nov 7, 2013
b7f671f
Asserts.
tiennou Nov 7, 2013
709c2b3
Move the contents of `GTBranchTest` where they belong.
tiennou Nov 7, 2013
9e69d7c
Remove `GTBranchTest`.
tiennou Nov 7, 2013
04fd3e7
Convert `GTCommitTest` to Expecta.
tiennou Nov 7, 2013
f578c4c
Convert `GTReferenceTest`.
tiennou Nov 7, 2013
9c2c3e2
Convert `GTRepositoryTest`.
tiennou Nov 7, 2013
f655dec
Cleanup `GTBlob`'s header.
tiennou Nov 9, 2013
1ea8499
Make `error` a local variable.
tiennou Nov 9, 2013
49ed41f
Expect errors to be nil here.
tiennou Nov 9, 2013
9b1bd6c
Reindent commented test.
tiennou Nov 9, 2013
8346974
Rename test.
tiennou Nov 9, 2013
bc98f3c
Cruft--;
tiennou Nov 9, 2013
86d4f7b
Dot-syntaxify.
tiennou Nov 9, 2013
173e177
Rename `isValidReference` and define it at declaration time.
tiennou Nov 9, 2013
5246535
Make `error` a local variable.
tiennou Nov 9, 2013
79fcc2d
Fix the `lookupObjectByRefspec:error:` name.
tiennou Nov 9, 2013
d4a1ae8
Whitespace.
tiennou Nov 9, 2013
e09ebb5
Test that the returned branches are the expected ones.
tiennou Nov 9, 2013
d07941e
Test the complete reference array in one step.
tiennou Nov 9, 2013
8f47b33
Clarify comment.
tiennou Nov 9, 2013
9bc13e2
Test the actual error domain & code.
tiennou Nov 9, 2013
b88903d
Convert local `file:` URLs to paths before handing over to `git_clone`.
tiennou Oct 24, 2013
2b2be90
Dot-syntaxify.
tiennou Oct 29, 2013
8265839
Use `-fileSystemRepresentation` here.
tiennou Oct 29, 2013
bcdd927
File reference URLs are file URLs; no need for a separate test.
tiennou Oct 29, 2013
aa510a6
Useless call; file reference URLs know how to path-ify themselves.
tiennou Oct 29, 2013
7f7cb21
Test that the remote set by `+clone…` looks fine to libgit2.
tiennou Oct 29, 2013
2986a6b
De-oneline-ify.
tiennou Nov 9, 2013
cff180a
Make `error` a local.
tiennou Nov 9, 2013
cbe71f8
Add methods to create new bare and non-bare repositories to `GTTestCa…
tiennou Nov 9, 2013
c43cad5
Test that new repos have unborn HEADs.
tiennou Nov 9, 2013
3dd9c70
Define `expectSHAForRevspec` inline.
tiennou Nov 9, 2013
378b31d
Use the clone tests from #280.
tiennou Nov 9, 2013
87efa74
Put the newly-cloned repo in the test-case managed temporary directory.
tiennou Nov 9, 2013
87fff3b
Huh, bare clones don't checkout...
tiennou Nov 9, 2013
c6720b3
Merge branch 'master' into tests-to-specs
tiennou Nov 11, 2013
9936d06
Rename `…Revspec:` => `…RevParse:`.
tiennou Nov 13, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions Classes/GTBlob.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,37 @@
#import "GTObject.h"


@interface GTBlob : GTObject {}
@interface GTBlob : GTObject

+ (id)blobWithString:(NSString *)string inRepository:(GTRepository *)repository error:(NSError **)error;
+ (id)blobWithData:(NSData *)data inRepository:(GTRepository *)repository error:(NSError **)error;
+ (id)blobWithFile:(NSURL *)file inRepository:(GTRepository *)repository error:(NSError **)error;
// Convenience class methods
+ (instancetype)blobWithString:(NSString *)string inRepository:(GTRepository *)repository error:(NSError **)error;
+ (instancetype)blobWithData:(NSData *)data inRepository:(GTRepository *)repository error:(NSError **)error;
+ (instancetype)blobWithFile:(NSURL *)file inRepository:(GTRepository *)repository error:(NSError **)error;

- (id)initWithString:(NSString *)string inRepository:(GTRepository *)repository error:(NSError **)error;
- (id)initWithData:(NSData *)data inRepository:(GTRepository *)repository error:(NSError **)error;
- (id)initWithFile:(NSURL *)file inRepository:(GTRepository *)repository error:(NSError **)error;
// Convenience wrapper around `-initWithData:inRepository:error` that converts the string to UTF8 data
- (instancetype)initWithString:(NSString *)string inRepository:(GTRepository *)repository error:(NSError **)error;

// Creates a new blob from the passed data.
//
// This writes data to the repository's object database.
//
// data - The data to write.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May not be nil.

// repository - The repository to put the object in.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May not be nil.

// error - Will be set if an error occurs.
//
// Returns a newly created blob object, or nil if an error occurs.
- (instancetype)initWithData:(NSData *)data inRepository:(GTRepository *)repository error:(NSError **)error;

// Creates a new blob from the specified file.
//
// This copies the data from the file to the repository's object database.
//
// data - The file to copy contents from.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May not be nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, how about we agree on defaulting to "unspecified" => "mandatory argument" ? I'm not fond of having to go through every docblock out there and add that info, and the "optional" argument case is much less frequent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are actually relatively few methods which assert paramaters as not being nil, throughout the codebase.

If something will throw an exception if you pass in nil it should absolutely be documented.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see both sides of this argument, but ObjectiveGit is probably the wrong example to look at here, since it's kinda crufty in many places.

I'm 👍 on @tiennou's suggestion (for all our OSS), though it'll take some time before ObjectiveGit's documentation actually gets to a state where it matches our expectations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I'm fine with that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems incredibly backwards to me that we wouldn't document something which throws an exception.

// repository - The repository to put the object in.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May not be nil.

// error - Will be set if an error occurs.
//
// Returns a newly created blob object, or nil if an error occurs.
- (instancetype)initWithFile:(NSURL *)file inRepository:(GTRepository *)repository error:(NSError **)error;

// The underlying `git_object` as a `git_blob` object.
- (git_blob *)git_blob __attribute__((objc_returns_inner_pointer));
Expand Down
11 changes: 10 additions & 1 deletion Classes/GTBlob.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ + (id)blobWithFile:(NSURL *)file inRepository:(GTRepository *)repository error:(
}

- (id)initWithOid:(const git_oid *)oid inRepository:(GTRepository *)repository error:(NSError **)error {
NSParameterAssert(oid != NULL);
NSParameterAssert(repository != nil);

git_object *obj;
int gitError = git_object_lookup(&obj, repository.git_repository, oid, (git_otype) GTObjectTypeBlob);
if (gitError < GIT_OK) {
Expand All @@ -73,6 +76,9 @@ - (id)initWithString:(NSString *)string inRepository:(GTRepository *)repository
}

- (id)initWithData:(NSData *)data inRepository:(GTRepository *)repository error:(NSError **)error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also document the header for this method? We should specify that data and repository may not be nil

NSParameterAssert(data != nil);
NSParameterAssert(repository != nil);

git_oid oid;
int gitError = git_blob_create_frombuffer(&oid, repository.git_repository, [data bytes], data.length);
if(gitError < GIT_OK) {
Expand All @@ -86,8 +92,11 @@ - (id)initWithData:(NSData *)data inRepository:(GTRepository *)repository error:
}

- (id)initWithFile:(NSURL *)file inRepository:(GTRepository *)repository error:(NSError **)error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

NSParameterAssert(file != nil);
NSParameterAssert(repository != nil);

git_oid oid;
int gitError = git_blob_create_fromworkdir(&oid, repository.git_repository, [[file path] UTF8String]);
int gitError = git_blob_create_fromdisk(&oid, repository.git_repository, [[file path] fileSystemRepresentation]);
if(gitError < GIT_OK) {
if(error != NULL) {
*error = [NSError git_errorFor:gitError description:@"Failed to create blob from NSURL"];
Expand Down
2 changes: 1 addition & 1 deletion Classes/GTRepository.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ extern NSString *const GTRepositoryCloneOptionsCredentialProvider;
- (id)lookupObjectBySHA:(NSString *)sha error:(NSError **)error;

// Lookup an object in the repo using a revparse spec
- (id)lookupObjectByRefspec:(NSString *)spec error:(NSError **)error;
- (id)lookupObjectByRevParse:(NSString *)spec error:(NSError **)error;

// List all references in the repository
//
Expand Down
18 changes: 12 additions & 6 deletions Classes/GTRepository.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ + (instancetype)initializeEmptyRepositoryAtFileURL:(NSURL *)localFileURL error:(
}

+ (instancetype)initializeEmptyRepositoryAtFileURL:(NSURL *)localFileURL bare:(BOOL)bare error:(NSError **)error {
if (![localFileURL isFileURL] || localFileURL.path == nil) {
if (!localFileURL.isFileURL || localFileURL.path == nil) {
if (error != NULL) *error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnsupportedSchemeError userInfo:@{ NSLocalizedDescriptionKey: NSLocalizedString(@"Invalid file path URL to initialize repository.", @"") }];
return NO;
}
Expand Down Expand Up @@ -151,7 +151,7 @@ - (id)initWithURL:(NSURL *)localFileURL error:(NSError **)error {
}

git_repository *r;
int gitError = git_repository_open(&r, localFileURL.path.UTF8String);
int gitError = git_repository_open(&r, localFileURL.path.fileSystemRepresentation);
if (gitError < GIT_OK) {
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to open repository at URL %@.", localFileURL];
return nil;
Expand Down Expand Up @@ -219,8 +219,14 @@ + (id)cloneFromURL:(NSURL *)originURL toWorkingDirectory:(NSURL *)workdirURL opt
cloneOptions.remote_callbacks.transfer_progress = transferProgressCallback;
cloneOptions.remote_callbacks.payload = &payload;

const char *remoteURL = originURL.absoluteString.UTF8String;
const char *workingDirectoryPath = workdirURL.path.UTF8String;
// If our originURL is local, convert to a path before handing down.
const char *remoteURL = NULL;
if (originURL.isFileURL) {
remoteURL = originURL.path.fileSystemRepresentation;
} else {
remoteURL = originURL.absoluteString.UTF8String;
}
const char *workingDirectoryPath = workdirURL.path.fileSystemRepresentation;
git_repository *repository;
int gitError = git_clone(&repository, remoteURL, workingDirectoryPath, &cloneOptions);
if (gitError < GIT_OK) {
Expand Down Expand Up @@ -270,11 +276,11 @@ - (id)lookupObjectBySHA:(NSString *)sha error:(NSError **)error {
return [self lookupObjectBySHA:sha objectType:GTObjectTypeAny error:error];
}

- (id)lookupObjectByRefspec:(NSString *)spec error:(NSError **)error {
- (id)lookupObjectByRevParse:(NSString *)spec error:(NSError **)error {
git_object *obj;
int gitError = git_revparse_single(&obj, self.git_repository, spec.UTF8String);
if (gitError < GIT_OK) {
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Failed to lookup object by refspec %@.", spec];
if (error != NULL) *error = [NSError git_errorFor:gitError description:@"Revision specifier lookup failed." failureReason:@"The revision specifier \"%@\" couldn't be parsed.", spec];
return nil;
}
return [GTObject objectWithObj:obj inRepository:self];
Expand Down
28 changes: 8 additions & 20 deletions ObjectiveGitFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
3E0A23E5159E0FDB00A6068F /* GTObjectDatabase.h in Headers */ = {isa = PBXBuildFile; fileRef = 55C8054C13861F34004DCB0F /* GTObjectDatabase.h */; settings = {ATTRIBUTES = (Public, ); }; };
4D103ADD1819CFAA0029DB24 /* libiconv.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D103ADC1819CFAA0029DB24 /* libiconv.dylib */; };
4D123240178E009E0048F785 /* GTRepositoryCommittingSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D12323F178E009E0048F785 /* GTRepositoryCommittingSpec.m */; };
4D1C40D8182C006D00BE2960 /* GTBlobSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D1C40D7182C006D00BE2960 /* GTBlobSpec.m */; };
4D26799F178DAF31002A2795 /* GTTreeEntry+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D26799D178DAF31002A2795 /* GTTreeEntry+Private.h */; settings = {ATTRIBUTES = (Private, ); }; };
4D79C0EE17DF9F4D00997DE4 /* GTCredential.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D79C0EC17DF9F4D00997DE4 /* GTCredential.h */; settings = {ATTRIBUTES = (Public, ); }; };
4D79C0EF17DF9F4D00997DE4 /* GTCredential.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D79C0ED17DF9F4D00997DE4 /* GTCredential.m */; };
Expand Down Expand Up @@ -199,12 +200,8 @@
88EB7E4E14AEBA600046FEA4 /* GTConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 88EB7E4C14AEBA600046FEA4 /* GTConfiguration.m */; };
88F05A9D16011F6A00B7AD1D /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 88F05A9C16011F6A00B7AD1D /* SenTestingKit.framework */; };
88F05A9E16011F6E00B7AD1D /* ObjectiveGit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* ObjectiveGit.framework */; };
88F05AB316011FFD00B7AD1D /* GTBlobTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AA216011FFD00B7AD1D /* GTBlobTest.m */; };
88F05AB416011FFD00B7AD1D /* GTBranchTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AA316011FFD00B7AD1D /* GTBranchTest.m */; };
88F05AB516011FFD00B7AD1D /* GTCommitTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AA416011FFD00B7AD1D /* GTCommitTest.m */; };
88F05AB516011FFD00B7AD1D /* GTCommitSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AA416011FFD00B7AD1D /* GTCommitSpec.m */; };
88F05AB916011FFD00B7AD1D /* GTObjectTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AA816011FFD00B7AD1D /* GTObjectTest.m */; };
88F05ABA16011FFD00B7AD1D /* GTReferenceTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AA916011FFD00B7AD1D /* GTReferenceTest.m */; };
88F05ABC16011FFD00B7AD1D /* GTRepositoryTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AAB16011FFD00B7AD1D /* GTRepositoryTest.m */; };
88F05AC41601204200B7AD1D /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 88F05A7816011E5400B7AD1D /* InfoPlist.strings */; };
88F05AC61601209A00B7AD1D /* ObjectiveGit.m in Sources */ = {isa = PBXBuildFile; fileRef = 88F05AC51601209A00B7AD1D /* ObjectiveGit.m */; };
88F05AC716012CE500B7AD1D /* NSString+Git.m in Sources */ = {isa = PBXBuildFile; fileRef = 55C8057313874CDF004DCB0F /* NSString+Git.m */; };
Expand Down Expand Up @@ -515,6 +512,7 @@
32DBCF5E0370ADEE00C91783 /* ObjectiveGitFramework_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjectiveGitFramework_Prefix.pch; sourceTree = "<group>"; };
4D103ADC1819CFAA0029DB24 /* libiconv.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libiconv.dylib; path = usr/lib/libiconv.dylib; sourceTree = SDKROOT; };
4D12323F178E009E0048F785 /* GTRepositoryCommittingSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTRepositoryCommittingSpec.m; sourceTree = "<group>"; };
4D1C40D7182C006D00BE2960 /* GTBlobSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTBlobSpec.m; sourceTree = "<group>"; };
4D26799D178DAF31002A2795 /* GTTreeEntry+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GTTreeEntry+Private.h"; sourceTree = "<group>"; };
4D79C0EC17DF9F4D00997DE4 /* GTCredential.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTCredential.h; sourceTree = "<group>"; };
4D79C0ED17DF9F4D00997DE4 /* GTCredential.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTCredential.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -566,12 +564,8 @@
88F05A7916011E5400B7AD1D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
88F05A7E16011E5400B7AD1D /* ObjectiveGitTests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ObjectiveGitTests-Prefix.pch"; sourceTree = "<group>"; };
88F05A9C16011F6A00B7AD1D /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; };
88F05AA216011FFD00B7AD1D /* GTBlobTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTBlobTest.m; sourceTree = "<group>"; };
88F05AA316011FFD00B7AD1D /* GTBranchTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTBranchTest.m; sourceTree = "<group>"; };
88F05AA416011FFD00B7AD1D /* GTCommitTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTCommitTest.m; sourceTree = "<group>"; };
88F05AA416011FFD00B7AD1D /* GTCommitSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTCommitSpec.m; sourceTree = "<group>"; };
88F05AA816011FFD00B7AD1D /* GTObjectTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTObjectTest.m; sourceTree = "<group>"; };
88F05AA916011FFD00B7AD1D /* GTReferenceTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTReferenceTest.m; sourceTree = "<group>"; };
88F05AAB16011FFD00B7AD1D /* GTRepositoryTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTRepositoryTest.m; sourceTree = "<group>"; };
88F05AAF16011FFD00B7AD1D /* ObjectiveGitTests-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "ObjectiveGitTests-Info.plist"; sourceTree = "<group>"; };
88F05AC51601209A00B7AD1D /* ObjectiveGit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ObjectiveGit.m; path = Classes/ObjectiveGit.m; sourceTree = "<group>"; };
88F05AC91601335C00B7AD1D /* Specta.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Specta.xcodeproj; path = specta/Specta.xcodeproj; sourceTree = "<group>"; };
Expand Down Expand Up @@ -821,22 +815,19 @@
isa = PBXGroup;
children = (
88F05A7616011E5400B7AD1D /* Supporting Files */,
88F05AA216011FFD00B7AD1D /* GTBlobTest.m */,
4D1C40D7182C006D00BE2960 /* GTBlobSpec.m */,
88A994B916FCE7D400402C7B /* GTBranchSpec.m */,
88F05AA316011FFD00B7AD1D /* GTBranchTest.m */,
88F05AA416011FFD00B7AD1D /* GTCommitTest.m */,
88F05AA416011FFD00B7AD1D /* GTCommitSpec.m */,
88C0BC5817038CF3009E99AA /* GTConfigurationSpec.m */,
30865A90167F503400B1AB6E /* GTDiffSpec.m */,
D06D9E001755D10000558C17 /* GTEnumeratorSpec.m */,
8832811E173D8816006D7DCF /* GTIndexSpec.m */,
88F05AA816011FFD00B7AD1D /* GTObjectTest.m */,
D00F6815175D373C004DB9D6 /* GTReferenceSpec.m */,
88F05AA916011FFD00B7AD1D /* GTReferenceTest.m */,
88215482171499BE00D76B76 /* GTReflogSpec.m */,
D0AC906B172F941F00347DC4 /* GTRepositorySpec.m */,
F6ED8DA0180E713200A32D40 /* GTRemoteSpec.m */,
4D12323F178E009E0048F785 /* GTRepositoryCommittingSpec.m */,
88F05AAB16011FFD00B7AD1D /* GTRepositoryTest.m */,
D03B7C401756AB370034A610 /* GTSubmoduleSpec.m */,
2089E43B17D9A58000F451DA /* GTTagSpec.m */,
30B1E7FF1703871900D0814D /* GTTimeAdditionsSpec.m */,
Expand Down Expand Up @@ -1523,12 +1514,9 @@
files = (
88F05AC816012CEE00B7AD1D /* NSData+Git.m in Sources */,
88F05AC716012CE500B7AD1D /* NSString+Git.m in Sources */,
88F05AB316011FFD00B7AD1D /* GTBlobTest.m in Sources */,
88F05AB416011FFD00B7AD1D /* GTBranchTest.m in Sources */,
88F05AB516011FFD00B7AD1D /* GTCommitTest.m in Sources */,
4D1C40D8182C006D00BE2960 /* GTBlobSpec.m in Sources */,
88F05AB516011FFD00B7AD1D /* GTCommitSpec.m in Sources */,
88F05AB916011FFD00B7AD1D /* GTObjectTest.m in Sources */,
88F05ABA16011FFD00B7AD1D /* GTReferenceTest.m in Sources */,
88F05ABC16011FFD00B7AD1D /* GTRepositoryTest.m in Sources */,
30865A91167F503400B1AB6E /* GTDiffSpec.m in Sources */,
88A994BA16FCE7D400402C7B /* GTBranchSpec.m in Sources */,
2089E43C17D9A58000F451DA /* GTTagSpec.m in Sources */,
Expand Down
90 changes: 90 additions & 0 deletions ObjectiveGitTests/GTBlobSpec.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// GTBlobSpec.m
// ObjectiveGitFramework
//
// Created by Etienne Samson on 2013-11-07.
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
//

#import "GTBlob.h"

SpecBegin(GTBlob)

__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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We tend to prefer toNot over notTo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A quick fgrep shows the reverse is true :trollface:. I have no hard opinion on that actually, I just think it makes more sense grammatically when you read it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard to see how you have fgrepd through GitHub for Mac's source :trollface:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL yeah, it looks like we're actually 50/50 on this even in the GitHub for Mac codebase.

});

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be written in one line. Avoiding the need for the success temporary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to keep this temporary for 3 reasons : it's cleaner to read, it makes the actual result appear when running under the debugger, and I'm pretty sure the style guide agrees with me ;-). But I can change it if it's really bothersome.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 to temporaries, it's the style we've been preferring.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dannygreg is it? I've only seen us do this when we're passing the BOOL by reference to -asynchronousFirstOrDefault:success:error:

@jspahrsummers @joshaber have an opinion on this?

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);
});
});
});

SpecEnd
Loading