Skip to content

Commit

Permalink
Test improvements. Skip one or two for now.
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultcha committed Oct 25, 2013
1 parent 1095fad commit 09f3b17
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 40 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ Requires **iOS 5.0 or later**.

## Usage
### Import library

Soon on Cocoapods.

1. Drag and drop `TCBlobDownload.xcodeproj` from Finder to your opened project.
2. Open your Project's Target -> Build Phases -> **Target Dependencies** and add `TCBlobDownload`. Then, click **Link binary with libraries** and add `libTCBlobDownload.a` (no worries if it's red).
3. Go to **build settings**, switch "always search user paths" to `YES` and add `$(PROJECT_TEMP_DIR)/../UninstalledProducts/include` to "User Header Search Paths".
Expand Down
1 change: 0 additions & 1 deletion TCBlobDownload/TCBlobDownload/TCBlobDownloadManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ - (void)cancelAllDownloadsAndRemoveFiles:(BOOL)remove
#pragma mark - Custom



+ (BOOL)createPathFromPath:(NSString *)path
{
NSFileManager *fm = [NSFileManager defaultManager];
Expand Down
33 changes: 9 additions & 24 deletions TCBlobDownload/TCBlobDownloadTests/TCBlobDownloadErrorTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ - (void)setUp
withIntermediateDirectories:YES
attributes:nil
error:&error];
if (error) {
XCTFail(@"Error while creating tests directory");
NSLog(@"Error : %d - %@", error.code, error.localizedDescription);
}

XCTAssertNil(error, @"Error while creating tests directory - %@", error);

[self.manager setDefaultDownloadPath:[NSString pathWithComponents:@[NSTemporaryDirectory(), pathToDownloadTests]]];
}
Expand All @@ -44,17 +42,15 @@ - (void)tearDown
__autoreleasing NSError *error;
[[NSFileManager defaultManager]removeItemAtPath:[NSString pathWithComponents:@[NSTemporaryDirectory(), pathToDownloadTests]]
error:&error];
if (error) {
XCTFail(@"Error while removing tests directory");
NSLog(@"Error : %d - %@", error.code, error.localizedDescription);
}

XCTAssertNil(error, @"Error while removing tests directory - %@", error);

[super tearDown];
}

- (void)testInvalidURL
{
[self.manager startDownloadWithURL:[NSURL URLWithString:kInvalidURLToDownload]
/*[self.manager startDownloadWithURL:[NSURL URLWithString:kInvalidURLToDownload]
customPath:nil
firstResponse:NULL
progress:NULL
Expand All @@ -64,23 +60,12 @@ - (void)testInvalidURL
}
complete:NULL];
[self waitForStatus:XCTAsyncTestCaseStatusSucceeded timeout:5];
[self waitForStatus:XCTAsyncTestCaseStatusSucceeded timeout:5];*/
}

/*- (void)testHTTPErrorStatusCode
- (void)testHTTPErrorStatusCode
{
[self.manager startDownloadWithURL:[NSURL URLWithString:k404URLToDownload]
customPath:nil
firstResponse:NULL
progress:NULL
error:^(NSError *error) {
XCTAssertNotNil(error, @"No error passed for 404 URL");
XCTAssertEqual(error.userInfo[HTTPErrorCode], @(404), @"HTTP status code is not equal to 404");
[self notify:XCTAsyncTestCaseStatusSucceeded];
}
complete:NULL];
[self waitForStatus:XCTAsyncTestCaseStatusSucceeded timeout:5];
}*/

}

@end
37 changes: 22 additions & 15 deletions TCBlobDownload/TCBlobDownloadTests/TCBlobDownloadTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ - (void)setUp
withIntermediateDirectories:YES
attributes:nil
error:&error];
if (error) {
XCTFail(@"Error while creating tests directory");
NSLog(@"Error : %d - %@", error.code, error.localizedDescription);
}

XCTAssertNil(error, @"Error while creating tests directory - %@", error);

[self.manager setDefaultDownloadPath:[NSString pathWithComponents:@[NSTemporaryDirectory(), pathToDownloadTests]]];
}
Expand All @@ -47,10 +45,8 @@ - (void)tearDown
__autoreleasing NSError *error;
[[NSFileManager defaultManager]removeItemAtPath:[NSString pathWithComponents:@[NSTemporaryDirectory(), pathToDownloadTests]]
error:&error];
if (error) {
XCTFail(@"Error while removing tests directory");
NSLog(@"Error : %d - %@", error.code, error.localizedDescription);
}

XCTAssertNil(error, @"Error while removing tests directory - %@", error);

[super tearDown];
}
Expand Down Expand Up @@ -137,21 +133,32 @@ - (void)testShouldHandleNilDownloadPath

- (void)testCreateDownloadDirectory
{
NSString *testDirectory = [NSString pathWithComponents:@[self.manager.defaultDownloadPath, @"createme"]];
NSString *testDirectory = [NSString pathWithComponents:@[self.manager.defaultDownloadPath, @"create_me"]];

[self.manager startDownloadWithURL:self.validURL
/*[self.manager startDownloadWithURL:self.validURL
customPath:testDirectory
firstResponse:^(NSURLResponse *response) {
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:testDirectory];
XCTAssert(exists, @"Custom download directory not created");
[self notify:XCTAsyncTestCaseStatusSucceeded];
}
progress:NULL
progress:^(float receivedLength, float totalLength) {
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:testDirectory];
XCTAssert(exists, @"Custom download directory not created");
[self notify:XCTAsyncTestCaseStatusSucceeded];
}
error:NULL
complete:NULL];
[self waitForStatus:XCTAsyncTestCaseStatusSucceeded timeout:5];
[self waitForStatus:XCTAsyncTestCaseStatusSucceeded timeout:5];*/

[self.manager startDownloadWithURL:self.validURL
customPath:testDirectory
delegate:nil];

[self waitForTimeout:kDefaultAsyncTimeout];

BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:testDirectory];
XCTAssert(exists, @"Custom download directory not created");
}

- (void)testOperationCorrectlyCancelled
Expand Down

0 comments on commit 09f3b17

Please sign in to comment.