diff --git a/asjon-testing.coffee b/asjon-testing.coffee index ebd05b4..9638f0f 100644 --- a/asjon-testing.coffee +++ b/asjon-testing.coffee @@ -14,13 +14,6 @@ before = (done) -> receive = (f) -> robot.adapter.on 'send', f after = -> robot.shutdown() clear = -> robot.adapter.removeAllListeners(); robot.httpListener = -> - # Intercept hubot's http calls - robot.onHttp = (f) -> robot.httpListener = f - robot.http = (addr) -> - get: -> - (cb) -> robot.httpListener 'GET', addr, cb - post: -> - (cb) -> robot.httpListener 'POST', addr, cb # Done done robot: robot, user: user, send: send, receive: receive diff --git a/package.json b/package.json index 4020c4b..f732399 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ }, "devDependencies": { "chai": "^2.3.0", - "hubot-mock-adapter": "^1.0.0" + "hubot-mock-adapter": "^1.0.0", + "nock": "^1.7.1" } } diff --git a/scripts/shell.coffee b/scripts/shell.coffee index 762ebae..d06684f 100644 --- a/scripts/shell.coffee +++ b/scripts/shell.coffee @@ -29,18 +29,28 @@ runCmd = (cmd,res,cb) -> module.exports = (robot) -> robot.respond /aggiornati|scarica (?:gli )?aggiornamenti/i, (res) -> - runCmd 'git pull && npm install', res + runCmd 'git pull && npm install && npm install --dev', res robot.respond /(?:controlla gli )?aggiornamenti/i, (res) -> runCmd 'git fetch && git status', res robot.respond /(?:installa (?:le )?)dipendenze/i, (res) -> - runCmd 'npm install', res + runCmd 'npm install && npm install --dev', res + + # Run tests on boot and report to ADMIN + if process.env.AUTO_RUN_TESTS and process.env.ADMIN_ROOM + dest = room: process.env.ADMIN_ROOM.replace(':','#') + robot.send dest, 'Operazione in corso: npm test' + runCmd 'npm test', null, (err,stdout,stderr) -> + if err + robot.send dest, 'ATTENZIONE: TEST FAILURE\n'+stdout+stderr + else + robot.send dest, 'Test superati con successo:\n'+stdout robot.on 'githubhook', (data,params) -> if data.ref is 'refs/heads/master' and process.env.AUTO_KILL_ON_UPDATE - runCmd 'git pull & npm install', null, -> - dest = name: params.name, room: params.room.replace(':','#') + runCmd 'git pull && npm install && npm install --dev', null, -> + dest = name: params.name, room: params.room.replace(':','#') robot.send dest, 'riavvio in 5 SECONDI' reboot = -> console.log 'AUTO IMPICCAGIONE IN CORSO!' diff --git a/test/asjon-mock.coffee b/test/asjon-mock.coffee index c6d2653..0070b2f 100644 --- a/test/asjon-mock.coffee +++ b/test/asjon-mock.coffee @@ -1,3 +1,4 @@ +nock = require 'nock' expect = require("chai").should() Asjon = require '../asjon-testing.coffee' @@ -14,14 +15,10 @@ describe 'hubot mock', -> done() it 'should intercept hubot\'s HTTP calls', (done) -> - asjon.robot.onHttp (method, addr, cb) -> - addr.should.equal 'http://ddg.gg' - method.should.equal 'GET' - cb null, 200, 'mock body' + nock('http://ddg.gg').get('/').reply 200, 'nocked' asjon.robot.http('http://ddg.gg') .get() (err, res, body) -> - if err then throw err - res.should.equal 200 - body.should.equal 'mock body' + res.statusCode.should.equal 200 + body.should.equal 'nocked' done()