Skip to content

Instantly share code, notes, and snippets.

@ncreated
Created September 5, 2017 21:10
Show Gist options
  • Select an option

  • Save ncreated/b4f751555f79ae54cf929dc6d742f643 to your computer and use it in GitHub Desktop.

Select an option

Save ncreated/b4f751555f79ae54cf929dc6d742f643 to your computer and use it in GitHub Desktop.

Revisions

  1. ncreated created this gist Sep 5, 2017.
    28 changes: 28 additions & 0 deletions TestTask.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    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)
    }