auto run test, aggiornamento http mock

This commit is contained in:
Enrico Fasoli 2015-04-28 10:11:01 +02:00
parent 50940b4ca2
commit 3a62bd34bc
4 changed files with 20 additions and 19 deletions

View File

@ -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

View File

@ -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"
}
}

View File

@ -29,17 +29,27 @@ 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, ->
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 = ->

View File

@ -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()