Skip to content

Instantly share code, notes, and snippets.

@ncreated
Created September 5, 2017 21:10
Show Gist options
  • Save ncreated/b4f751555f79ae54cf929dc6d742f643 to your computer and use it in GitHub Desktop.
Save ncreated/b4f751555f79ae54cf929dc6d742f643 to your computer and use it in GitHub Desktop.
Medium blogpost snippet
func test_givenTask_whenExecuted_itUpdatesStatusInSpecificOrder() {
let task = Task()
let mockDelegate = MockTaskStatusDelegate()
task.statusDelegate = mockDelegate
let downloadingExpectation = self.expectation(description: "status changes to .downloading")
let processingExpectation = self.expectation(description: "status changes to .processing")
let finishedExpectation = self.expectation(description: "status changes to .finished")
mockDelegate.didCall_taskDidChangeStatus = { (_, status) in
switch status {
case .downloading:
downloadingExpectation.fulfill()
case .processing:
processingExpectation.fulfill()
case .finished:
finishedExpectation.fulfill()
default:
XCTFail()
}
}
task.execute()
wait(for: [downloadingExpectation, processingExpectation, finishedExpectation],
timeout: 0.5,
enforceOrder: true)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment