Skip to content

Instantly share code, notes, and snippets.

@sisoje
Last active February 14, 2019 14:53
Show Gist options
  • Save sisoje/ae9eef2294ecb2e312448c5813730de0 to your computer and use it in GitHub Desktop.
Save sisoje/ae9eef2294ecb2e312448c5813730de0 to your computer and use it in GitHub Desktop.
extension XCTestExpectation {
var fulfiller: DeinitBlock {
return DeinitBlock {
print("Fulfill \(self.description)")
self.fulfill()
}
}
}
class FillfilerTests: XCTestCase {
func testFulfillWithDispatchQueue() {
let queue = DispatchQueue(label: #function)
(0..<10).forEach { index in
let fulfiller = expectation(description: "\(#function) \(index)").fulfiller
if index.isMultiple(of: 2) {
// automatically fulfilled on exiting scope
return
}
queue.async {
// fullfiled when closure is released
print("Retaining: \(fulfiller)")
}
}
waitForExpectations(timeout: 1, handler: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment