 
         let future = futures.all()
 
-        waitUntil { done in
-          future.fail { _ in
-            done()
-          }
-        }
-        
+        futures_wait {
+          [future.wrap()]
+        }
+
         it ("rejects the promise") {
           expect(future.state) == FutureState.Rejected
         }

          let future3 = future1.merge(future2)

          let error = NSError(domain: "", code: 42, userInfo: nil)
          
          future1.resolve(42)
          future2.reject(error)
          
          waitUntil { done in
            future3.fail { error in
              expect(error) == error
              done()
            }
          }
        }
      }
    }

import Nimble
import FutureSwift

func futures_wait(f: Void -> [Future<Void>]) {
  waitUntil(timeout: 10) { done in
    let futures = f()
    var x = futures.count
    futures.forEach {
      $0.finally {
        x -= 1
        if x == 0 {
          done()
        }
      }
    }
  }
}

class FutureSpec: QuickSpec {

  override func spec() {
    describe("Future") {

      it("can resolve") {
        var thenCalledWhenResolved = false
        var thenCalledDirectlyWhenAlreadyResolved = false
        var failCalled = false

        let future = Future<Void>()

        futures_wait() {
          let futures = [
            future.then { thenCalledWhenResolved = true },
            future.fail { _ in failCalled = true }
          ]

          future.resolve()

          return futures
        }

        expect(thenCalledWhenResolved) == true
        expect(future.state) == FutureState.Resolved
        expect(failCalled) == false

        futures_wait {
          [
            future.then { thenCalledDirectlyWhenAlreadyResolved = true }
          ]
        }

        expect(thenCalledDirectlyWhenAlreadyResolved) == true
      }

