   )
 
   updateCodeStub = sandbox.stub(Deploy, 'deploy', ->
-    new Promise(()->)
+    new Promise(() ->)
   )
 
-  Q.nfcall(
-    request.post, {
-      url: helpers.appurl('/deploy')
-      json: true
-      body: commitHookPayload
-    }
-  ).spread( (res, body) ->
+  Promise.promisify(request.post, request)({
+    url: helpers.appurl('/deploy')
+    json: true
+    body: commitHookPayload
+  }).spread( (res, body) ->
 
-    try
-      assert.equal res.statusCode, 200,
-        "Expected the request to succeed"
+    assert.equal res.statusCode, 200,
+      "Expected the request to succeed"
 
-      assert.strictEqual updateCodeStub.callCount, 1,
-        "Expected Deploy.deploy to be called once"
+    assert.strictEqual updateCodeStub.callCount, 1,
+      "Expected Deploy.deploy to be called once"
 
-      assert.isTrue updateCodeStub.calledWith(tagName),
-        "Expected Deploy.deploy to be called with the tag name"
+    assert.isTrue updateCodeStub.calledWith(tagName),
+      "Expected Deploy.deploy to be called with the tag name"
 
-      done()
-    catch e
-      done(e)
-    finally
-      sandbox.restore()
-
-  ).fail( (err) ->
-    console.error err
+    sandbox.restore()
+    done()
+  ).catch( (err) ->
     sandbox.restore()
     done(err)
   )


  updateCodeStub = sandbox.stub(Deploy, 'deploy', ->)

  Q.nfcall(
    request.post, {
      url: helpers.appurl('/deploy')
      json: true
      body: {}
    }
  ).spread( (res, body) ->

    try
      console.log body
      assert.equal res.statusCode, 401

      assert.isFalse updateCodeStub.calledOnce,
        "Expected CommandRunner.spawn not to be called"

      done()
    catch err
      done(err)
    finally
      sandbox.restore()

  ).fail( (err) ->
    sandbox.restore()
    done(err)
  )

      return name: 'not staging'
  )

  Promise.promisify(request.post, request)({
    url: helpers.appurl('/deploy')
    json: true
    body: commitHookPayload
  }).spread( (res, body) ->

    assert.strictEqual updateCodeStub.callCount, 0,
      "Expected CommandRunner.spawn to not be called once"

    assert.equal res.statusCode, 500

    sandbox.restore()
    done()

  ).catch( (err) ->
    sandbox.restore()
    done(err)
  )
