Created
December 7, 2015 05:57
-
-
Save grocky/7e9e8c8945506bf3226e to your computer and use it in GitHub Desktop.
A js version of the awesome hubot test helper created by @mdelagrange http://leapfrogonline.io/articles/2015-11-09-testing-hubot-scripts/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
require('coffee-script').register(); | |
var HubotTestHelper = require('hubot-test-helper'); | |
var helper = null; | |
var RoomUtils = (function() { | |
function RoomUtils(room) { | |
this.room = room; | |
} | |
RoomUtils.prototype.destroyRoom = function() { | |
this.room.destroy(); | |
}; | |
RoomUtils.prototype.say = function(message, opts) { | |
var user; | |
if (opts == null) { | |
opts = {}; | |
} | |
user = (opts['user'] ? opts['user'] : 'user1'); | |
return this.room.user.say(user, message); | |
}; | |
/** | |
* @returns {String} | |
*/ | |
RoomUtils.prototype.getFirstResponse = function() { | |
return this.getResponse(0); | |
}; | |
/** | |
* @param index - zero indexed response | |
* @returns {String} | |
*/ | |
RoomUtils.prototype.getResponse = function(index) { | |
return this.room.messages[index * 2 + 1][1]; | |
}; | |
return RoomUtils; | |
})(); | |
/** | |
* @param {Object} [opts] | |
* @returns {RoomUtils} | |
*/ | |
var createRoomUtils = function(opts) { | |
opts = opts || {}; | |
var roomName = opts['roomName'] || 'testRoom'; | |
var room = helper.createRoom({name: roomName}); | |
return new RoomUtils(room); | |
}; | |
module.exports = function(script) { | |
helper = new HubotTestHelper(__dirname + '/../scripts/' + script + '.js'); | |
return { | |
createRoomUtils: createRoomUtils | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment