Minor reformatting

This commit is contained in:
Mattt Thompson 2013-05-22 09:37:23 -07:00
parent f63a70fa27
commit 632ac765ee
6 changed files with 76 additions and 45 deletions

View file

@ -64,11 +64,12 @@
- (void)testJSONRequestOperationContruction { - (void)testJSONRequestOperationContruction {
NSMutableURLRequest *request = [self.client requestWithMethod:@"GET" path:@"/path" parameters:nil]; NSMutableURLRequest *request = [self.client requestWithMethod:@"GET" path:@"/path" parameters:nil];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
expect([AFJSONRequestOperation canProcessRequest:request]).to.beTruthy();
AFHTTPRequestOperation *operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL]; AFHTTPRequestOperation *operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL];
expect([operation class]).to.equal([AFHTTPRequestOperation class]); expect([operation class]).to.equal([AFHTTPRequestOperation class]);
expect([AFJSONRequestOperation canProcessRequest:request]).to.beTruthy();
[self.client registerHTTPOperationClass:[AFJSONRequestOperation class]]; [self.client registerHTTPOperationClass:[AFJSONRequestOperation class]];
operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL]; operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL];
expect([operation class]).to.equal([AFJSONRequestOperation class]); expect([operation class]).to.equal([AFJSONRequestOperation class]);
@ -81,11 +82,12 @@
- (void)testXMLRequestOperationContruction { - (void)testXMLRequestOperationContruction {
NSMutableURLRequest *request = [self.client requestWithMethod:@"GET" path:@"/path" parameters:nil]; NSMutableURLRequest *request = [self.client requestWithMethod:@"GET" path:@"/path" parameters:nil];
[request setValue:@"application/xml" forHTTPHeaderField:@"Accept"]; [request setValue:@"application/xml" forHTTPHeaderField:@"Accept"];
AFHTTPRequestOperation *operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL];
expect([operation class]).to.equal([AFHTTPRequestOperation class]);
expect([AFXMLRequestOperation canProcessRequest:request]).to.beTruthy(); expect([AFXMLRequestOperation canProcessRequest:request]).to.beTruthy();
AFHTTPRequestOperation *operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL];
expect([operation class]).to.equal([AFHTTPRequestOperation class]);
[self.client registerHTTPOperationClass:[AFXMLRequestOperation class]]; [self.client registerHTTPOperationClass:[AFXMLRequestOperation class]];
operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL]; operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL];
expect([operation class]).to.equal([AFXMLRequestOperation class]); expect([operation class]).to.equal([AFXMLRequestOperation class]);
@ -94,11 +96,12 @@
- (void)testImageRequestOperationContruction { - (void)testImageRequestOperationContruction {
NSMutableURLRequest *request = [self.client requestWithMethod:@"GET" path:@"/path" parameters:nil]; NSMutableURLRequest *request = [self.client requestWithMethod:@"GET" path:@"/path" parameters:nil];
[request setValue:@"image/png" forHTTPHeaderField:@"Accept"]; [request setValue:@"image/png" forHTTPHeaderField:@"Accept"];
expect([AFImageRequestOperation canProcessRequest:request]).to.beTruthy();
AFHTTPRequestOperation *operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL]; AFHTTPRequestOperation *operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL];
expect([operation class]).to.equal([AFHTTPRequestOperation class]); expect([operation class]).to.equal([AFHTTPRequestOperation class]);
expect([AFImageRequestOperation canProcessRequest:request]).to.beTruthy();
[self.client registerHTTPOperationClass:[AFImageRequestOperation class]]; [self.client registerHTTPOperationClass:[AFImageRequestOperation class]];
operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL]; operation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL];
expect([operation class]).to.equal([AFImageRequestOperation class]); expect([operation class]).to.equal([AFImageRequestOperation class]);
@ -123,10 +126,9 @@
batchCallbackTime = [NSDate date]; batchCallbackTime = [NSDate date];
}]; }];
expect(self.client.operationQueue.operationCount).to.equal(@3); expect(self.client.operationQueue.operationCount).to.equal(3);
expect(firstCallbackTime).willNot.beNil(); expect(firstCallbackTime).willNot.beNil();
expect(batchCallbackTime).willNot.beNil(); expect(batchCallbackTime).willNot.beNil();
expect(batchCallbackTime).beGreaterThan(firstCallbackTime); expect(batchCallbackTime).beGreaterThan(firstCallbackTime);
} }
@ -150,11 +152,11 @@
batchOperations = operations; batchOperations = operations;
}]; }];
expect(self.client.operationQueue.operationCount).to.equal(@3); expect(self.client.operationQueue.operationCount).to.equal(3);
expect(batchOperations).willNot.beNil(); expect(batchOperations).willNot.beNil();
expect(self.client.operationQueue.operationCount).to.equal(@0); expect(self.client.operationQueue.operationCount).to.equal(0);
expect(batchOperations.count).to.equal(@2); expect(batchOperations.count).to.equal(2);
expect([[batchOperations objectAtIndex:0] class]).to.equal([AFJSONRequestOperation class]); expect([[batchOperations objectAtIndex:0] class]).to.equal([AFJSONRequestOperation class]);
expect([[batchOperations objectAtIndex:1] class]).to.equal([AFImageRequestOperation class]); expect([[batchOperations objectAtIndex:1] class]).to.equal([AFImageRequestOperation class]);
@ -203,8 +205,7 @@
expect(responseDictionary[@"form"]).to.equal(@{ @"key": @"value" }); expect(responseDictionary[@"form"]).to.equal(@{ @"key": @"value" });
} }
- (void)testThatEnqueueBatchOfHTTPRequestOperationsConstructsOperationsWithAppropriateRegisteredHTTPRequestOperationClasses - (void)testThatEnqueueBatchOfHTTPRequestOperationsConstructsOperationsWithAppropriateRegisteredHTTPRequestOperationClasses {
{
[self.client registerHTTPOperationClass:[AFJSONRequestOperation class]]; [self.client registerHTTPOperationClass:[AFJSONRequestOperation class]];
[self.client registerHTTPOperationClass:[AFImageRequestOperation class]]; [self.client registerHTTPOperationClass:[AFImageRequestOperation class]];
@ -229,8 +230,7 @@
expect([operations[1] class]).to.equal([AFImageRequestOperation class]); expect([operations[1] class]).to.equal([AFImageRequestOperation class]);
} }
- (void)testThatEnqueueBatchOfHTTPRequestOperationsEnqueuesOperationsInTheCorrectOrder - (void)testThatEnqueueBatchOfHTTPRequestOperationsEnqueuesOperationsInTheCorrectOrder {
{
NSMutableURLRequest *request = [self.client requestWithMethod:@"GET" path:@"/" parameters:nil]; NSMutableURLRequest *request = [self.client requestWithMethod:@"GET" path:@"/" parameters:nil];
AFHTTPRequestOperation *firstOperation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL]; AFHTTPRequestOperation *firstOperation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL];
AFHTTPRequestOperation *secondOperation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL]; AFHTTPRequestOperation *secondOperation = [self.client HTTPRequestOperationWithRequest:request success:NULL failure:NULL];
@ -254,6 +254,7 @@
expect(operations[0]).to.equal(firstOperation); expect(operations[0]).to.equal(firstOperation);
expect(operations[1]).to.equal(secondOperation); expect(operations[1]).to.equal(secondOperation);
expect(batchedOperation).notTo.beNil(); expect(batchedOperation).notTo.beNil();
expect(batchedOperation).to.beKindOf([NSBlockOperation class]); expect(batchedOperation).to.beKindOf([NSBlockOperation class]);
} }
@ -265,6 +266,7 @@
[formData appendPartWithFileData:imageData name:@"item[photos_attributes][][photo]" fileName:@"item-image.png" mimeType:@"image/jpg"]; [formData appendPartWithFileData:imageData name:@"item[photos_attributes][][photo]" fileName:@"item-image.png" mimeType:@"image/jpg"];
}]; }];
AFHTTPRequestOperation *operation = [self.client HTTPRequestOperationWithRequest:request success:nil failure:nil]; AFHTTPRequestOperation *operation = [self.client HTTPRequestOperationWithRequest:request success:nil failure:nil];
[self.client enqueueHTTPRequestOperation:operation]; [self.client enqueueHTTPRequestOperation:operation];
expect(operation.isFinished).will.beTruthy(); expect(operation.isFinished).will.beTruthy();
expect(operation.error).notTo.equal(NSURLErrorTimedOut); expect(operation.error).notTo.equal(NSURLErrorTimedOut);

View file

@ -149,7 +149,7 @@
#pragma mark - Pause #pragma mark - Pause
- (void)testThatOperationCanBePaused{ - (void)testThatOperationCanBePaused {
[Expecta setAsynchronousTestTimeout:3.0]; [Expecta setAsynchronousTestTimeout:3.0];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/delay/1" relativeToURL:self.baseURL]]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/delay/1" relativeToURL:self.baseURL]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
@ -162,7 +162,7 @@
[operation cancel]; [operation cancel];
} }
- (void)testThatPausedOperationCanBeResumed{ - (void)testThatPausedOperationCanBeResumed {
[Expecta setAsynchronousTestTimeout:3.0]; [Expecta setAsynchronousTestTimeout:3.0];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/delay/1" relativeToURL:self.baseURL]]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/delay/1" relativeToURL:self.baseURL]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
@ -172,12 +172,14 @@
[operation pause]; [operation pause];
expect([operation isPaused]).will.beTruthy(); expect([operation isPaused]).will.beTruthy();
[operation resume]; [operation resume];
expect([operation isExecuting]).will.beTruthy(); expect([operation isExecuting]).will.beTruthy();
[operation cancel]; [operation cancel];
} }
- (void)testThatPausedOperationCanBeCompleted{ - (void)testThatPausedOperationCanBeCompleted {
[Expecta setAsynchronousTestTimeout:3.0]; [Expecta setAsynchronousTestTimeout:3.0];
__block id blockResponseObject = nil; __block id blockResponseObject = nil;
@ -187,6 +189,7 @@
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
blockResponseObject = responseObject; blockResponseObject = responseObject;
} failure:nil]; } failure:nil];
[operation start]; [operation start];
expect([operation isExecuting]).will.beTruthy(); expect([operation isExecuting]).will.beTruthy();
@ -201,33 +204,37 @@
#pragma mark - Response String Encoding #pragma mark - Response String Encoding
- (void) testThatTextStringEncodingIsISOLatin1WhenNoCharsetParameterIsProvided { - (void)testThatTextStringEncodingIsISOLatin1WhenNoCharsetParameterIsProvided {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=text/plain" relativeToURL:self.baseURL]]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=text/plain" relativeToURL:self.baseURL]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation start]; [operation start];
expect([operation isFinished]).will.beTruthy(); expect([operation isFinished]).will.beTruthy();
expect(operation.responseStringEncoding).will.equal(NSISOLatin1StringEncoding); expect(operation.responseStringEncoding).will.equal(NSISOLatin1StringEncoding);
} }
- (void) testThatTextStringEncodingIsShiftJISWhenShiftJISCharsetParameterIsProvided { - (void)testThatTextStringEncodingIsShiftJISWhenShiftJISCharsetParameterIsProvided {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=text/plain;%20charset=%22Shift_JIS%22" relativeToURL:self.baseURL]]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=text/plain;%20charset=%22Shift_JIS%22" relativeToURL:self.baseURL]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation start]; [operation start];
expect([operation isFinished]).will.beTruthy(); expect([operation isFinished]).will.beTruthy();
expect(operation.responseStringEncoding).will.equal(NSShiftJISStringEncoding); expect(operation.responseStringEncoding).will.equal(NSShiftJISStringEncoding);
} }
- (void) testThatTextStringEncodingIsUTF8WhenInvalidCharsetParameterIsProvided { - (void)testThatTextStringEncodingIsUTF8WhenInvalidCharsetParameterIsProvided {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=text/plain;%20charset=%22invalid%22" relativeToURL:self.baseURL]]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=text/plain;%20charset=%22invalid%22" relativeToURL:self.baseURL]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation start]; [operation start];
expect([operation isFinished]).will.beTruthy(); expect([operation isFinished]).will.beTruthy();
expect(operation.responseStringEncoding).will.equal(NSUTF8StringEncoding); expect(operation.responseStringEncoding).will.equal(NSUTF8StringEncoding);
} }
- (void) testThatTextStringEncodingIsUTF8WhenUTF8CharsetParameterIsProvided { - (void)testThatTextStringEncodingIsUTF8WhenUTF8CharsetParameterIsProvided {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=text/plain;%20charset=%22UTF-8%22" relativeToURL:self.baseURL]]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=text/plain;%20charset=%22UTF-8%22" relativeToURL:self.baseURL]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation start]; [operation start];
expect([operation isFinished]).will.beTruthy(); expect([operation isFinished]).will.beTruthy();
expect(operation.responseStringEncoding).will.equal(NSUTF8StringEncoding); expect(operation.responseStringEncoding).will.equal(NSUTF8StringEncoding);

View file

@ -1,16 +1,28 @@
// AFJSONRequestOperationTests.m
// //
// AFJSONRequestOperationTests.m // Copyright (c) 2013 AFNetworking (http://afnetworking.com)
// AFNetworking Tests
// //
// Created by Kevin Harwood on 5/16/13. // Permission is hereby granted, free of charge, to any person obtaining a copy
// Copyright (c) 2013 AFNetworking. All rights reserved. // of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import "AFNetworkingTests.h" #import "AFNetworkingTests.h"
#import "AFJSONRequestOperation.h"
@interface AFJSONRequestOperationTests : SenTestCase @interface AFJSONRequestOperationTests : SenTestCase
@property (readwrite, nonatomic, strong) NSURL *baseURL; @property (readwrite, nonatomic, strong) NSURL *baseURL;
@end @end
@ -21,58 +33,65 @@
self.baseURL = [NSURL URLWithString:AFNetworkingTestsBaseURLString]; self.baseURL = [NSURL URLWithString:AFNetworkingTestsBaseURLString];
} }
- (void)testThatJSONRequestOperationAcceptsApplicationJSON{ - (void)testThatJSONRequestOperationAcceptsApplicationJSON {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=application/json" relativeToURL:self.baseURL]]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=application/json" relativeToURL:self.baseURL]];
AFJSONRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:request]; AFJSONRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:request];
[operation start]; [operation start];
expect([operation isFinished]).will.beTruthy(); expect([operation isFinished]).will.beTruthy();
expect(operation.error).will.beNil(); expect(operation.error).will.beNil();
} }
- (void)testThatJSONRequestOperationAcceptsTextJSON{ - (void)testThatJSONRequestOperationAcceptsTextJSON {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=text/json" relativeToURL:self.baseURL]]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=text/json" relativeToURL:self.baseURL]];
AFJSONRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:request]; AFJSONRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:request];
[operation start]; [operation start];
expect([operation isFinished]).will.beTruthy(); expect([operation isFinished]).will.beTruthy();
expect(operation.error).will.beNil(); expect(operation.error).will.beNil();
} }
- (void)testThatJSONRequestOperationAcceptsTextJavascript{ - (void)testThatJSONRequestOperationAcceptsTextJavascript {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=text/javascript" relativeToURL:self.baseURL]]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=text/javascript" relativeToURL:self.baseURL]];
AFJSONRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:request]; AFJSONRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:request];
[operation start]; [operation start];
expect([operation isFinished]).will.beTruthy(); expect([operation isFinished]).will.beTruthy();
expect(operation.error).will.beNil(); expect(operation.error).will.beNil();
} }
- (void)testThatJSONRequestOperationAcceptsCustomContentType{ - (void)testThatJSONRequestOperationAcceptsCustomContentType {
[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"application/customjson"]]; [AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"application/customjson"]];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=application/customjson" relativeToURL:self.baseURL]]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=application/customjson" relativeToURL:self.baseURL]];
AFJSONRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:request]; AFJSONRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:request];
[operation start]; [operation start];
expect([operation isFinished]).will.beTruthy(); expect([operation isFinished]).will.beTruthy();
expect(operation.error).will.beNil(); expect(operation.error).will.beNil();
} }
- (void)testThatJSONRequestOperationDoesNotAcceptInvalidContentType{ - (void)testThatJSONRequestOperationDoesNotAcceptInvalidContentType {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=application/no-json" relativeToURL:self.baseURL]]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=application/no-json" relativeToURL:self.baseURL]];
AFJSONRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:request]; AFJSONRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:request];
[operation start]; [operation start];
expect([operation isFinished]).will.beTruthy(); expect([operation isFinished]).will.beTruthy();
expect(operation.error).willNot.beNil(); expect(operation.error).willNot.beNil();
} }
- (void)testThatJSONResponseObjectIsNotNilWhenValidJSONIsReturned{ - (void)testThatJSONResponseObjectIsNotNilWhenValidJSONIsReturned {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=application/json" relativeToURL:self.baseURL]]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/response-headers?Content-Type=application/json" relativeToURL:self.baseURL]];
AFJSONRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:request]; AFJSONRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:request];
[operation start]; [operation start];
expect([operation isFinished]).will.beTruthy(); expect([operation isFinished]).will.beTruthy();
expect(operation.responseJSON).willNot.beNil(); expect(operation.responseJSON).willNot.beNil();
} }
- (void)testThatJSONResponseObjectIsNilWhenErrorOccurs{ - (void)testThatJSONResponseObjectIsNilWhenErrorOccurs {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/status/404" relativeToURL:self.baseURL]]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/status/404" relativeToURL:self.baseURL]];
AFJSONRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:request]; AFJSONRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:request];
[operation start]; [operation start];
expect([operation isFinished]).will.beTruthy(); expect([operation isFinished]).will.beTruthy();
expect(operation.responseJSON).will.beNil(); expect(operation.responseJSON).will.beNil();

View file

@ -191,8 +191,8 @@
2580153E173EB3A70026AA6E /* AFNetworkingTests.h */, 2580153E173EB3A70026AA6E /* AFNetworkingTests.h */,
2580153F173EB3A70026AA6E /* AFNetworkingTests.m */, 2580153F173EB3A70026AA6E /* AFNetworkingTests.m */,
2580153B173EB3A70026AA6E /* AFHTTPRequestOperationTests.m */, 2580153B173EB3A70026AA6E /* AFHTTPRequestOperationTests.m */,
2580153A173EB3A70026AA6E /* AFHTTPClientTests.m */,
29A9CE2017456336002360C8 /* AFJSONRequestOperationTests.m */, 29A9CE2017456336002360C8 /* AFJSONRequestOperationTests.m */,
2580153A173EB3A70026AA6E /* AFHTTPClientTests.m */,
); );
name = Tests; name = Tests;
sourceTree = "<group>"; sourceTree = "<group>";

View file

@ -28,3 +28,6 @@
#import "OCMock.h" #import "OCMock.h"
extern NSString * const AFNetworkingTestsBaseURLString; extern NSString * const AFNetworkingTestsBaseURLString;
@interface AFNetworkingTests : NSObject
@end

View file

@ -20,17 +20,17 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
#import "AFNetworkingTests.h"
#import "AFHTTPRequestOperationLogger.h" #import "AFHTTPRequestOperationLogger.h"
NSString * const AFNetworkingTestsBaseURLString = @"http://httpbin.org/"; NSString * const AFNetworkingTestsBaseURLString = @"http://httpbin.org/";
@interface AFNetworkingTests : NSObject
@end
@implementation AFNetworkingTests @implementation AFNetworkingTests
+ (void)load
{ + (void)load {
NSString *loggingEnabled = [[[NSProcessInfo processInfo] environment][@"AFTestsLoggingEnabled"] uppercaseString]; if ([[[[NSProcessInfo processInfo] environment][@"AFTestsLoggingEnabled"] uppercaseString] isEqualToString:@"YES"]) {
if ([loggingEnabled isEqualToString:@"YES"]) [[AFHTTPRequestOperationLogger sharedLogger] startLogging]; [[AFHTTPRequestOperationLogger sharedLogger] startLogging];
}
} }
@end @end