Pull in a few more basic request/response tests from @kcharwood
This commit is contained in:
parent
6e57c377f1
commit
4d8faf8a23
1 changed files with 52 additions and 1 deletions
|
|
@ -29,7 +29,7 @@
|
||||||
- (void)testThatOperationInvokesFailureCompletionBlockWithErrorOnFailure
|
- (void)testThatOperationInvokesFailureCompletionBlockWithErrorOnFailure
|
||||||
{
|
{
|
||||||
__block NSError *blockError = nil;
|
__block NSError *blockError = nil;
|
||||||
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/404" relativeToURL:AFNetworkingTestsBaseURL()]];
|
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/status/404" relativeToURL:AFNetworkingTestsBaseURL()]];
|
||||||
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
|
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
|
||||||
[operation setCompletionBlockWithSuccess:nil failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
[operation setCompletionBlockWithSuccess:nil failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
||||||
blockError = error;
|
blockError = error;
|
||||||
|
|
@ -65,4 +65,55 @@
|
||||||
expect(blockError.code).to.equal(NSURLErrorCancelled);
|
expect(blockError.code).to.equal(NSURLErrorCancelled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)testThat500StatusCodeInvokesFailureCompletionBlockWithErrorOnFailure
|
||||||
|
{
|
||||||
|
__block NSError *blockError = nil;
|
||||||
|
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/status/500" relativeToURL:AFNetworkingTestsBaseURL()]];
|
||||||
|
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
|
||||||
|
[operation setCompletionBlockWithSuccess:nil failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
||||||
|
blockError = error;
|
||||||
|
}];
|
||||||
|
[operation start];
|
||||||
|
expect([operation isFinished]).will.beTruthy();
|
||||||
|
expect(blockError).willNot.beNil();
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testThatRedirectBlockIsCalledWhen302IsEncountered
|
||||||
|
{
|
||||||
|
__block BOOL success;
|
||||||
|
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/redirect/1" relativeToURL:AFNetworkingTestsBaseURL()]];
|
||||||
|
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
|
||||||
|
[operation setCompletionBlockWithSuccess:nil
|
||||||
|
failure:nil];
|
||||||
|
[operation
|
||||||
|
setRedirectResponseBlock:^NSURLRequest *(NSURLConnection *connection, NSURLRequest *request, NSURLResponse *redirectResponse) {
|
||||||
|
if(redirectResponse){
|
||||||
|
success = YES;
|
||||||
|
}
|
||||||
|
return request;
|
||||||
|
}];
|
||||||
|
[operation start];
|
||||||
|
expect([operation isFinished]).will.beTruthy();
|
||||||
|
expect(success).will.beTruthy();
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)testThatRedirectBlockIsCalledMultipleTimesWhen302IsEncountered
|
||||||
|
{
|
||||||
|
__block NSInteger numberOfRedirects = 0;
|
||||||
|
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/redirect/5" relativeToURL:AFNetworkingTestsBaseURL()]];
|
||||||
|
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
|
||||||
|
[operation setCompletionBlockWithSuccess:nil
|
||||||
|
failure:nil];
|
||||||
|
[operation
|
||||||
|
setRedirectResponseBlock:^NSURLRequest *(NSURLConnection *connection, NSURLRequest *request, NSURLResponse *redirectResponse) {
|
||||||
|
if(redirectResponse){
|
||||||
|
numberOfRedirects++;
|
||||||
|
}
|
||||||
|
return request;
|
||||||
|
}];
|
||||||
|
[operation start];
|
||||||
|
expect([operation isFinished]).will.beTruthy();
|
||||||
|
expect(numberOfRedirects).will.equal(5);
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue