@@ -29,7 +29,7 @@ - (void)testThatOperationInvokesSuccessCompletionBlockWithResponseObjectOnSucces
29
29
- (void )testThatOperationInvokesFailureCompletionBlockWithErrorOnFailure
30
30
{
31
31
__block NSError *blockError = nil ;
32
- NSURLRequest *request = [NSURLRequest requestWithURL: [NSURL URLWithString: @" /404" relativeToURL: AFNetworkingTestsBaseURL ()]];
32
+ NSURLRequest *request = [NSURLRequest requestWithURL: [NSURL URLWithString: @" /status/ 404" relativeToURL: AFNetworkingTestsBaseURL ()]];
33
33
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc ] initWithRequest: request];
34
34
[operation setCompletionBlockWithSuccess: nil failure: ^(AFHTTPRequestOperation *operation, NSError *error) {
35
35
blockError = error;
@@ -65,4 +65,55 @@ - (void)testThatCancellationOfRequestOperationInvokesFailureCompletionBlock
65
65
expect (blockError.code ).to .equal (NSURLErrorCancelled);
66
66
}
67
67
68
+ - (void )testThat500StatusCodeInvokesFailureCompletionBlockWithErrorOnFailure
69
+ {
70
+ __block NSError *blockError = nil ;
71
+ NSURLRequest *request = [NSURLRequest requestWithURL: [NSURL URLWithString: @" /status/500" relativeToURL: AFNetworkingTestsBaseURL ()]];
72
+ AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc ] initWithRequest: request];
73
+ [operation setCompletionBlockWithSuccess: nil failure: ^(AFHTTPRequestOperation *operation, NSError *error) {
74
+ blockError = error;
75
+ }];
76
+ [operation start ];
77
+ expect ([operation isFinished ]).will .beTruthy ();
78
+ expect (blockError).willNot .beNil ();
79
+ }
80
+
81
+ - (void )testThatRedirectBlockIsCalledWhen302IsEncountered
82
+ {
83
+ __block BOOL success;
84
+ NSURLRequest *request = [NSURLRequest requestWithURL: [NSURL URLWithString: @" /redirect/1" relativeToURL: AFNetworkingTestsBaseURL ()]];
85
+ AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc ] initWithRequest: request];
86
+ [operation setCompletionBlockWithSuccess: nil
87
+ failure: nil ];
88
+ [operation
89
+ setRedirectResponseBlock: ^NSURLRequest *(NSURLConnection *connection, NSURLRequest *request, NSURLResponse *redirectResponse) {
90
+ if (redirectResponse){
91
+ success = YES ;
92
+ }
93
+ return request;
94
+ }];
95
+ [operation start ];
96
+ expect ([operation isFinished ]).will .beTruthy ();
97
+ expect (success).will .beTruthy ();
98
+ }
99
+
100
+ - (void )testThatRedirectBlockIsCalledMultipleTimesWhen302IsEncountered
101
+ {
102
+ __block NSInteger numberOfRedirects = 0 ;
103
+ NSURLRequest *request = [NSURLRequest requestWithURL: [NSURL URLWithString: @" /redirect/5" relativeToURL: AFNetworkingTestsBaseURL ()]];
104
+ AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc ] initWithRequest: request];
105
+ [operation setCompletionBlockWithSuccess: nil
106
+ failure: nil ];
107
+ [operation
108
+ setRedirectResponseBlock: ^NSURLRequest *(NSURLConnection *connection, NSURLRequest *request, NSURLResponse *redirectResponse) {
109
+ if (redirectResponse){
110
+ numberOfRedirects++;
111
+ }
112
+ return request;
113
+ }];
114
+ [operation start ];
115
+ expect ([operation isFinished ]).will .beTruthy ();
116
+ expect (numberOfRedirects).will .equal (5 );
117
+ }
118
+
68
119
@end
0 commit comments