hubot-test-helper icon indicating copy to clipboard operation
hubot-test-helper copied to clipboard

Allow user to require the Hubot script themselves

Open strugee opened this issue 6 years ago • 3 comments

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.

strugee avatar Aug 25 '17 20:08 strugee

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

alFReD-NSH avatar Sep 29 '17 11:09 alFReD-NSH

Thank you! That worked perfectly :thumbsup:

Maybe that should be documented somewhere? Unless I just missed it...

strugee avatar Sep 29 '17 15:09 strugee

No, its not documented. Feel free to open a pull request to update the readme to have this trick :)

alFReD-NSH avatar Sep 29 '17 15:09 alFReD-NSH