Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the robot logger #37

Open
strugee opened this issue Sep 9, 2016 · 4 comments
Open

Expose the robot logger #37

strugee opened this issue Sep 9, 2016 · 4 comments

Comments

@strugee
Copy link

strugee commented Sep 9, 2016

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.

@timkinnane
Copy link

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

@alFReD-NSH
Copy link
Contributor

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.

@strugee
Copy link
Author

strugee commented Oct 2, 2017

@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.

@timkinnane
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants