       return name: 'not staging'
   )
 
-  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.strictEqual updateCodeStub.callCount, 0,
-        "Expected CommandRunner.spawn to not be called once"
+    assert.strictEqual updateCodeStub.callCount, 0,
+      "Expected CommandRunner.spawn to not be called once"
 
-      assert.equal res.statusCode, 500
-      done()
-    catch e
-      done(e)
-    finally
-      sandbox.restore()
+    assert.equal res.statusCode, 500
 
-  ).fail( (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)
  )

  )

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

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

    assert.equal res.statusCode, 200,
      "Expected the request to succeed"

    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"

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