32 lines
1.0 KiB
CoffeeScript
32 lines
1.0 KiB
CoffeeScript
#expect = require("chai").expect
|
|
path = require("path")
|
|
|
|
Robot = require("hubot/src/robot")
|
|
TextMessage = require("hubot/src/message").TextMessage
|
|
|
|
before = (done) ->
|
|
robot = new Robot null, "mock-adapter", no, 'asjon'
|
|
robot.adapter.on 'connected', ->
|
|
# Initialize mocked environment
|
|
user = robot.brain.userForId "1", { name: 'mocha', room: '#mocha' }
|
|
adapter = robot.adapter
|
|
send = (s) -> robot.adapter.receive new TextMessage user, s
|
|
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
|
|
TextMessage: TextMessage, Robot: Robot
|
|
adapter: adapter, after: after, clear: clear
|
|
robot.run()
|
|
|
|
module.exports = before
|