 
     func testThatItCallsDieOnThrow() {
         // when
-        dispatch {
+        dispatchAndWaitForDie(timeout: 2) {
             dieOnThrow {
                 throw "Error"
             }
         }
-
-        spinMainQueue(1)
 
         // then
         XCTAssertEqual(callCount, 1)

        let queue = dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0)
        dispatch_async(queue, block)
    }
}

    var exitStatus: Int32?
    var printHistory: [[Any]] = []
    let spinMainQueue = NSThread.sleepForTimeInterval
    var expectation: XCTestExpectation?

    // MARK: - Mocking

    @noreturn private func mockExit(status: Int32) {
        exitStatus = status
        callCount++
        expectation?.fulfill()
        repeat { NSRunLoop.currentRunLoop().run() } while (true)
    }

