 
   updateCodeStub = sandbox.stub(Deploy, 'deploy', ->)
 
-  Q.nfcall(
-    request.post, {
-      url: helpers.appurl('/deploy')
-      json: true
-      body: {}
-    }
-  ).spread( (res, body) ->
+  Promise.promisify(request.post, request)({
+    url: helpers.appurl('/deploy')
+    json: true
+    body: {}
+  }).spread( (res, body) ->
 
-    try
-      console.log body
-      assert.equal res.statusCode, 401
+    console.log body
+    assert.equal res.statusCode, 401
 
-      assert.isFalse updateCodeStub.calledOnce,
-        "Expected CommandRunner.spawn not to be called"
+    assert.isFalse updateCodeStub.calledOnce,
+      "Expected CommandRunner.spawn not to be called"
 
-      done()
-    catch err
-      done(err)
-    finally
-      sandbox.restore()
+    sandbox.restore()
+    done()
 
-  ).fail( (err) ->
+  ).catch( (err) ->
     sandbox.restore()
     done(err)
   )

      return name: 'not staging'
  )

  Q.nfcall(
    request.post, {
      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.equal res.statusCode, 500
      done()
    catch e
      done(e)
    finally
      sandbox.restore()

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

request = require('request')
fs = require('fs')
sinon = require('sinon')
Promise = require('bluebird')

CommandRunner = require('../../lib/command_runner')
