hubot-test-helper
hubot-test-helper copied to clipboard
Allow user to require the Hubot script themselves
I have a script which is using res.random
. Obviously that's hard to test for, so I want to use proxyquire to override the require that gets the possible responses, such that there's only one possible response. However I can't do this because hubot-test-helper is calling require()
for me.
It'd be nice if I could just pass in a function and have that interpreted by hubot-test-helper as the plugin itself, pre-require()
'd.
You can do something like this:
Helper = require('hubot-test-helper')
helper = new Helper sctiptPath
room = helper.createRoom name: 'bob'
room.robot.Response = class extends Helper.Response
# Generated using a fair dice!
random: -> 4
Thank you! That worked perfectly :thumbsup:
Maybe that should be documented somewhere? Unless I just missed it...
No, its not documented. Feel free to open a pull request to update the readme to have this trick :)