Last active
January 9, 2016 20:20
-
-
Save kean/c7adb3a70de179e72557 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The MIT License (MIT) | |
// | |
// Copyright (c) 2015 Alexander Grebenyuk (github.com/kean). | |
import XCTest | |
import Foundation | |
extension XCTestCase { | |
public func expect(block: (fulfill: (Void) -> Void) -> Void) { | |
let expectation = self.expectation() | |
block(fulfill: { expectation.fulfill() }) | |
} | |
public func expectation() -> XCTestExpectation { | |
return self.expectationWithDescription("GenericExpectation") | |
} | |
public func expectNotification(name: String, object: AnyObject? = nil, handler: XCNotificationExpectationHandler? = nil) -> XCTestExpectation { | |
return self.expectationForNotification(name, object: object, handler: handler) | |
} | |
public func wait(timeout: NSTimeInterval = 2.0, handler: XCWaitCompletionHandler? = nil) { | |
self.waitForExpectationsWithTimeout(timeout, handler: handler) | |
} | |
} | |
// Usage: | |
func testThatDataTasksWithDifferentCachePolicyAreNotReused() { | |
let request1 = ImageRequest(URLRequest: NSURLRequest(URL: defaultURL, cachePolicy: .UseProtocolCachePolicy, timeoutInterval: 0)) | |
let request2 = ImageRequest(URLRequest: NSURLRequest(URL: defaultURL, cachePolicy: .ReturnCacheDataDontLoad, timeoutInterval: 0)) | |
self.expect { fulfill in | |
self.manager.taskWithRequest(request1) { _ in | |
fulfill() | |
}.resume() | |
} | |
self.expect { fulfill in | |
self.manager.taskWithRequest(request2) { _ in | |
fulfill() | |
}.resume() | |
} | |
self.wait { _ in | |
XCTAssertEqual(self.mockSessionManager.createdTaskCount, 2) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment