     func testInDispatchGroup() {
         let expectedValue = 3
 
-        var taskWasRun = false
+        let taskCalled = expectationWithDescription("Task was called")
         let promise = Promise<Int> { fulfill in
-            taskWasRun = true
+            taskCalled.fulfill()
 
             XCTAssertTrue(NSThread.isMainThread(), "Expected the task to run on the main thread.")
 


        let group = dispatch_group_create()

        var promiseCompletionWasRun = false
        let groupCompletionExpectation = expectationWithDescription("Dispatch group completed.")

        dispatch_group_notify(group, dispatch_get_main_queue()) {
            XCTAssertTrue(taskWasRun, "Expected the task closure to be called.")
            XCTAssertTrue(promiseCompletionWasRun, "Expected the promise completion block to be called before the group completion block.")

            groupCompletionExpectation.fulfill()
        }

        promise.inDispatchGroup(group).call { result in

            }

            let attemptCount = 3
            let completionCalled = expectationWithDescription("Completion was called")
            promise.retry(attemptCount).call { result in
                completionCalled.fulfill()
                TestHelpers.expectSuccess(expectedValue, result: result, message: "Expected the given success value.")
            }

            XCTAssertEqual(1, taskRunCount, "Expected the task to succeed on the first try.")
            waitForExpectationsWithTimeout(1.0, handler: nil)
        }
        
        // Succeed on the second try
