         suiteStub.afterAll.restore()
         mocha.Suite.create.restore()
         runner.mocha.run.restore()
+        runner = undefined
+        test = undefined
 
       it 'should run mocha', () ->
         assert.ok runner.mocha.run.called

            done()

      after () ->
        afterAllHook = undefined

      it 'should call afterAll hook', () ->
        afterAllHook.should.have.been.called


    describe 'when beforeAllHooks throws UncaughtError', () ->

      beforeAllHook = undefined
      afterAllHook = undefined

      before (done) ->
        testFactory = new TestFactory()
        test = testFactory.create()
        test.name = 'GET /machines -> 200'
        test.request.path = '/machines'
        test.request.method = 'GET'
        test.response.status = 200

        beforeAllHook = sinon.stub()
        beforeAllHook.throws('Error')
        afterAllHook = sinon.stub()
        afterAllHook.callsArg(0)

        hooksStub.beforeAllHooks = [beforeAllHook]
        hooksStub.afterAllHooks = [afterAllHook]

        options =
          server: "#{SERVER}"

        runner = new TestRunner options, ''
        sinon.stub test, 'run'
          .callsFake (callback) ->
            callback()

        # Mute stdout/stderr
        mute (unmute) ->

            done()

      after () ->
        afterAllHook = undefined
        runner = undefined
        test = undefined

      it 'should call afterAll hook', () ->
        afterAllHook.should.have.been.called


    describe 'when beforeAllHooks throws UncaughtError', () ->

      beforeAllHook = undefined
      afterAllHook = undefined

      before (done) ->
        test = createStdTest()
        test.response.status = 200

        beforeAllHook = sinon.stub()
        beforeAllHook.throws('Error')
        afterAllHook = sinon.stub()
        afterAllHook.callsArg(0)

        hooksStub.beforeAllHooks = [beforeAllHook]
        hooksStub.afterAllHooks = [afterAllHook]

        options =
          server: "#{SERVER}"

        runner = new TestRunner options, ''
        sinon.stub test, 'run'
          .callsFake (callback) ->
            callback()

        # Mute stdout/stderr
        mute (unmute) ->
