Created
May 20, 2016 19:54
-
-
Save Alexander-Ignition/9dde0e2ae254019a890f0395c1b47f46 to your computer and use it in GitHub Desktop.
XCTestCase+URLSessionDataTask
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
import XCTest | |
extension XCTestCase { | |
func expectationDataTask(dataTask: NSURLSessionDataTask) -> XCTestExpectation { | |
dataTask.resume() | |
let expectation = keyValueObservingExpectationForObject(dataTask, keyPath: "state") { _, _ in | |
return dataTask.state == .Completed || dataTask.state == .Canceling | |
} | |
return expectation | |
} | |
func waitForExpectationDataTask(dataTask: NSURLSessionDataTask) -> XCTestExpectation { | |
let expectation = expectationDataTask(dataTask) | |
let timeout = dataTask.currentRequest?.timeoutInterval ?? 65 | |
waitForExpectationsWithTimeout(timeout, handler: nil) | |
return expectation | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment