Actuator is a tiny wrapper around a mock hubot adapter that makes it easier to write unit tests for Hubot scripts.
Note: This project is in early development, and versioning is a little different. Read this for more details.
$ npm install actuator --save-dev
require 'chai'hubot = require 'actuator'beforeEachhubotinitiatescript: './lib/hubot_script.coffee'doneafterEach ->hubotterminatedescribe 'test hubot script'->it 'should have 3 help commands'expecthubotrobothelpCommandstohavelength3doneit 'should parse help'huboton'hubot help'spreadexpectresponsetoequal """hubot actuator - actuator is awesome.hubot help - Displays all of the help commands that hubot knows about.hubot help <query> - Displays all help commands that match <query>."""donedonebind@nulldoneit 'should respond to messages'huboton'hubot actuator'spreadexpectresponsetoequal 'actuator is awesome'donedonebind@nulldone
This starts up a Hubot instance to run all your tests against. It is required
for this module to work, and belongs in your test runner's
It is asynchronous, and requires
done to be passed to it from
settings.script is essentially just the path to the script that you want to test.
This shuts down the Hubot instance and it's webserver. Calling this in your
afterEach hook is necessary in order to prevent any weird
errors (like the ports Hubot runs on being regarded as in use).
This is a direct reference to the Hubot instance itself. Any properties you might need to reference from Hubot can be found here.
it 'should have 3 help commands'expectactuatorrobothelpCommandstohavelength3done
This is where the magic happens. This method is used to listen for Hubot commands
and assert their response.
command is a string for the command Hubot should be
This method is asynchronous and returns a promise for
Hubot's response to the command. The
responses thenable is an array of all
msg.send calls in Hubot's handler for that command.
For example, if your Hubot script listens for
"hubot greet me twice", like so:
=robotrespond /greet me twice/imsgsend"Hi there."msgsend"Wassup!?"
...then this is what your test would look like:
it 'responds with two greetings'actuatoron'hubot greet me twice'thenexpectresponses0toequal "Hi there."expectresponses1toequal "Wassup!?"then -> donecatch done
it 'responds with two greetings'actuatoron'hubot greet me twice'spreadexpectfirst_greetingtoequal "Hi there."expectsecond_greetingtoequal "Wassup!?"donedonebind@nulldone