Browse Source

- Removed Expecta
Removed Expecta from AFHTTPRequestSerializationTests
Removed Expecta from AFURLSessionManagerTests
Removed Expecta from AFHTTPSessionManagerTests
Removed Expecta from AFNetworkActivityIndicatorManager
Removed Expecta from test target

Kevin Harwood 10 years ago
parent
commit
aed204a5e9

+ 0 - 1
Tests/Podfile

@@ -6,7 +6,6 @@ inhibit_all_warnings!
 
 def import_pods
   pod 'OCMock', '~> 2.1.1'
-  pod 'Expecta', '~> 0.2.1'
   pod 'AFNetworking', :path => '../'
 end
 

+ 4 - 7
Tests/Tests/AFHTTPRequestSerializationTests.m

@@ -121,14 +121,12 @@
 - (void)testThatValueForHTTPHeaderFieldReturnsSetValue {
     [self.requestSerializer setValue:@"Actual Value" forHTTPHeaderField:@"Set-Header"];
     NSString *value = [self.requestSerializer valueForHTTPHeaderField:@"Set-Header"];
-
-    expect(value).to.equal(@"Actual Value");
+    XCTAssertTrue([value isEqualToString:@"Actual Value"]);
 }
 
 - (void)testThatValueForHTTPHeaderFieldReturnsNilForUnsetHeader {
     NSString *value = [self.requestSerializer valueForHTTPHeaderField:@"Unset-Header"];
-
-    expect(value).to.beNil();
+    XCTAssertNil(value);
 }
 
 - (void)testQueryStringSerializationCanFailWithError {
@@ -143,9 +141,8 @@
 
     NSError *error;
     NSURLRequest *request = [serializer requestWithMethod:@"GET" URLString:@"url" parameters:@{} error:&error];
-
-    expect(request).to.beNil();
-    expect(error).to.equal(serializerError);
+    XCTAssertNil(request);
+    XCTAssertEqual(error, serializerError);
 }
 
 @end

+ 36 - 14
Tests/Tests/AFHTTPSessionManagerTests.m

@@ -43,40 +43,53 @@
     __block id blockResponseObject = nil;
     __block id blockError = nil;
 
+    XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
+
     NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/get" relativeToURL:self.baseURL]];
     NSURLSessionDataTask *task = [self.manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
         blockResponseObject = responseObject;
         blockError = error;
+        [expectation fulfill];
     }];
 
     [task resume];
 
-    expect(task.state).will.equal(NSURLSessionTaskStateCompleted);
-    expect(blockError).will.beNil();
-    expect(blockResponseObject).willNot.beNil();
+    [self waitForExpectationsWithTimeout:10.0 handler:nil];
+
+    XCTAssertTrue(task.state == NSURLSessionTaskStateCompleted);
+    XCTAssertNil(blockError);
+    XCTAssertNotNil(blockResponseObject);
 }
 
 - (void)testThatOperationInvokesFailureCompletionBlockWithErrorOnFailure {
     __block id blockError = nil;
 
+    XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
+
     NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/status/404" relativeToURL:self.baseURL]];
     NSURLSessionDataTask *task = [self.manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
         blockError = error;
+        [expectation fulfill];
     }];
 
     [task resume];
 
-    expect(task.state).will.equal(NSURLSessionTaskStateCompleted);
-    expect(blockError).willNot.beNil();
+    [self waitForExpectationsWithTimeout:10.0 handler:nil];
+
+    XCTAssertTrue(task.state == NSURLSessionTaskStateCompleted);
+    XCTAssertNotNil(blockError);
 }
 
 - (void)testThatRedirectBlockIsCalledWhen302IsEncountered {
     __block BOOL success;
     __block NSError *blockError = nil;
 
+    XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
+
     NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/redirect/1" relativeToURL:self.baseURL]];
     NSURLSessionDataTask *task = [self.manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
         blockError = error;
+        [expectation fulfill];
     }];
 
     [self.manager setTaskWillPerformHTTPRedirectionBlock:^NSURLRequest *(NSURLSession *session, NSURLSessionTask *task, NSURLResponse *response, NSURLRequest *request) {
@@ -89,15 +102,19 @@
 
     [task resume];
 
-    expect(task.state).will.equal(NSURLSessionTaskStateCompleted);
-    expect(blockError).will.beNil();
-    expect(success).will.beTruthy();
+    [self waitForExpectationsWithTimeout:10.0 handler:nil];
+
+    XCTAssertTrue(task.state == NSURLSessionTaskStateCompleted);
+    XCTAssertNil(blockError);
+    XCTAssertTrue(success);
 }
 
 - (void)testDownloadFileCompletionSpecifiesURLInCompletionWithManagerDidFinishBlock {
     __block BOOL managerDownloadFinishedBlockExecuted = NO;
     __block BOOL completionBlockExecuted = NO;
     __block NSURL *downloadFilePath = nil;
+    XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
+
     [self.manager setDownloadTaskDidFinishDownloadingBlock:^NSURL *(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, NSURL *location) {
         managerDownloadFinishedBlockExecuted = YES;
         NSURL *dirURL  = [[[NSFileManager defaultManager] URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] lastObject];
@@ -110,17 +127,20 @@
                                                                  completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
                                                                      downloadFilePath = filePath;
                                                                      completionBlockExecuted = YES;
+                                                                     [expectation fulfill];
                                                                  }];
     [downloadTask resume];
-    expect(completionBlockExecuted).will.equal(YES);
-    expect(managerDownloadFinishedBlockExecuted).will.equal(YES);
-    expect(downloadFilePath).willNot.beNil();
+    [self waitForExpectationsWithTimeout:10.0 handler:nil];
+    XCTAssertTrue(completionBlockExecuted);
+    XCTAssertTrue(managerDownloadFinishedBlockExecuted);
+    XCTAssertNotNil(downloadFilePath);
 }
 
 - (void)testDownloadFileCompletionSpecifiesURLInCompletionBlock {
     __block BOOL destinationBlockExecuted = NO;
     __block BOOL completionBlockExecuted = NO;
     __block NSURL *downloadFilePath = nil;
+    XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];
 
     NSURLSessionDownloadTask *downloadTask = [self.manager downloadTaskWithRequest:[NSURLRequest requestWithURL:self.baseURL]
                                                                           progress:nil
@@ -132,11 +152,13 @@
                                                                  completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
                                                                      downloadFilePath = filePath;
                                                                      completionBlockExecuted = YES;
+                                                                     [expectation fulfill];
                                                                  }];
     [downloadTask resume];
-    expect(completionBlockExecuted).will.equal(YES);
-    expect(destinationBlockExecuted).will.equal(YES);
-    expect(downloadFilePath).willNot.beNil();
+    [self waitForExpectationsWithTimeout:10.0 handler:nil];
+    XCTAssertTrue(completionBlockExecuted);
+    XCTAssertTrue(destinationBlockExecuted);
+    XCTAssertNotNil(downloadFilePath);
 }
 
 

+ 29 - 42
Tests/Tests/AFNetworkActivityManagerTests.m

@@ -26,10 +26,7 @@
 
 @interface AFNetworkActivityManagerTests : AFTestCase
 @property (nonatomic, strong) AFNetworkActivityIndicatorManager *networkActivityIndicatorManager;
-@property (nonatomic, assign) BOOL isNetworkActivityIndicatorVisible;
-@property (nonatomic, strong) id mockApplication;
 @property (nonatomic, strong) AFHTTPSessionManager *sessionManager;
-
 @end
 
 #pragma mark -
@@ -43,24 +40,10 @@
 
     self.networkActivityIndicatorManager = [[AFNetworkActivityIndicatorManager alloc] init];
     self.networkActivityIndicatorManager.enabled = YES;
-
-    self.mockApplication = [OCMockObject mockForClass:[UIApplication class]];
-    [[[self.mockApplication stub] andReturn:self.mockApplication] sharedApplication];
-
-    [[[self.mockApplication stub] andDo:^(NSInvocation *invocation) {
-        [invocation setReturnValue:(void *)&_isNetworkActivityIndicatorVisible];
-    }] isNetworkActivityIndicatorVisible];
-
-    [[[self.mockApplication stub] andDo:^(NSInvocation *invocation) {
-        [invocation getArgument:&_isNetworkActivityIndicatorVisible atIndex:2];
-    }] setNetworkActivityIndicatorVisible:YES];
 }
 
 - (void)tearDown {
     [super tearDown];
-    [self.mockApplication stopMocking];
-    
-    self.mockApplication = nil;
     self.networkActivityIndicatorManager = nil;
 
     [self.sessionManager invalidateSessionCancelingTasks:YES];
@@ -69,43 +52,47 @@
 #pragma mark -
 
 - (void)testThatNetworkActivityIndicatorTurnsOffIndicatorWhenRequestSucceeds {
+    XCTestExpectation *requestCompleteExpectation = [self expectationWithDescription:@"Request should succeed"];
     [self.sessionManager
-     GET:@"/get"
+     GET:@"/delay/1"
      parameters:nil
      success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
-         expect([self.mockApplication isNetworkActivityIndicatorVisible]).will.beFalsy();
+         [requestCompleteExpectation fulfill];
      }
      failure:nil];
-    expect([self.mockApplication isNetworkActivityIndicatorVisible]).will.beTruthy();
+    [self expectationForPredicate:[NSPredicate predicateWithFormat:@"isNetworkActivityIndicatorVisible == YES"]
+                                               evaluatedWithObject:self.networkActivityIndicatorManager
+                                                           handler:nil];
+    [self waitForExpectationsWithTimeout:10.0 handler:nil];
+
+    [self expectationForPredicate:[NSPredicate predicateWithFormat:@"isNetworkActivityIndicatorVisible == NO"]
+              evaluatedWithObject:self.networkActivityIndicatorManager
+                          handler:nil];
+    [self waitForExpectationsWithTimeout:5.0 handler:nil];
 }
 
 - (void)testThatNetworkActivityIndicatorTurnsOffIndicatorWhenRequestFails {
+    XCTestExpectation *requestCompleteExpectation = [self expectationWithDescription:@"Request should succeed"];
     [self.sessionManager
      GET:@"/status/500"
      parameters:nil
-     success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
-         expect([self.mockApplication isNetworkActivityIndicatorVisible]).will.beFalsy();
-     }
-     failure:nil];
-    expect([self.mockApplication isNetworkActivityIndicatorVisible]).will.beTruthy();
-}
-
-- (void)testThatNetworkActivityIsUnchangedWhenManagerIsDisabled {
-    self.networkActivityIndicatorManager.enabled = NO;
-
-    __block BOOL didChangeNetworkActivityIndicatorVisible = NO;
-
-    [[[self.mockApplication stub] andDo:^(NSInvocation *invocation) {
-        didChangeNetworkActivityIndicatorVisible = YES;
-    }] setNetworkActivityIndicatorVisible:YES];
-
-    [self.sessionManager
-     GET:@"/get"
-     parameters:nil
      success:nil
-     failure:nil];
-
-    expect(didChangeNetworkActivityIndicatorVisible).will.beFalsy();
+     failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
+         [requestCompleteExpectation fulfill];
+     }];
+
+    [self
+     keyValueObservingExpectationForObject:self.networkActivityIndicatorManager
+     keyPath:@"isNetworkActivityIndicatorVisible"
+     handler:^BOOL(AFNetworkActivityIndicatorManager * observedObject, NSDictionary * _Nonnull change) {
+         return observedObject.isNetworkActivityIndicatorVisible;
+     }];
+    [self waitForExpectationsWithTimeout:5.0 handler:nil];
+
+    [self expectationForPredicate:[NSPredicate predicateWithFormat:@"isNetworkActivityIndicatorVisible == NO"]
+              evaluatedWithObject:self.networkActivityIndicatorManager
+                          handler:nil];
+    [self waitForExpectationsWithTimeout:5.0 handler:nil];
 }
 
 @end

+ 0 - 2
Tests/Tests/AFTestCase.h

@@ -21,8 +21,6 @@
 
 #import <XCTest/XCTest.h>
 
-#define EXP_SHORTHAND YES
-#import "Expecta.h"
 #import "OCMock.h"
 
 extern NSString * const AFNetworkingTestsBaseURLString;

+ 0 - 2
Tests/Tests/AFTestCase.m

@@ -27,8 +27,6 @@ NSString * const AFNetworkingTestsBaseURLString = @"https://httpbin.org/";
 
 - (void)setUp {
     [super setUp];
-
-    [Expecta setAsynchronousTestTimeout:5.0];
 }
 
 - (void)tearDown {

+ 4 - 6
Tests/Tests/AFURLSessionManagerTests.m

@@ -72,13 +72,12 @@
                         completionHandler:nil];
     [overallProgress resignCurrent];
 
-    expect(overallProgress.fractionCompleted).to.equal(0);
+    XCTAssertTrue(overallProgress.fractionCompleted == 0);
 
     uploadProgress.totalUnitCount = 1;
     uploadProgress.completedUnitCount = 1;
 
-
-    expect(overallProgress.fractionCompleted).to.equal(0.8);
+    XCTAssertTrue(overallProgress.fractionCompleted == 0.8);
 }
 
 - (void)testDownloadTasksProgressBecomesPartOfCurrentProgress {
@@ -93,13 +92,12 @@
                         completionHandler:nil];
     [overallProgress resignCurrent];
 
-    expect(overallProgress.fractionCompleted).to.equal(0);
+    XCTAssertTrue(overallProgress.fractionCompleted == 0.0);
 
     downloadProgress.totalUnitCount = 1;
     downloadProgress.completedUnitCount = 1;
 
-
-    expect(overallProgress.fractionCompleted).to.equal(0.8);
+    XCTAssertTrue(overallProgress.fractionCompleted == 0.8);
 }
 
 #pragma mark - Issue #2702 Tests