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

Expose the robot logger

Open strugee opened this issue 7 years ago • 4 comments

My module logs an error message if an environment variable isn't set. However, there's no way to test for that because I can't get access to the robot logger (or it isn't documented). It would be nice if hubot-test-helper would intercept calls to robot.logger.* and allow me to call assertions on logs.

strugee avatar Sep 09 '16 03:09 strugee

I had this issue, but found it was a problem with how I was accessing or triggering the robot and listener (which creates the response object, which includes the robot, which includes the logger).

Here's a basic working example (coffeescript). Obviously the npm modules used need to be installed. Hope it helps.

logger-test.zip

timkinnane avatar Nov 30 '16 05:11 timkinnane

You can access the robot via room.robot, so you can set spies on the logger methods: sinon.spy(room.robot.logger.error); and then assert the calls.

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

@alFReD-NSH that's a great idea. However, it seems it's not working (although it could be a bug in my test code) because the logging happens immediately on module initialization. See strugee/hubot-bridge#6.

strugee avatar Oct 02 '17 00:10 strugee

@strugee I've created hubot-pretend, which was initially a fork of hubot-test-helper but I've added lots of features now, such as easy access to an internal array keeping all the logs produced by robot logger for test assertions. Here's an example test interrogating the logs...

https://github.com/PropertyUX/hubot-pretend/tree/master/test/usage

timkinnane avatar Oct 02 '17 22:10 timkinnane