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

testing exec replies #57

Open
simbo1905 opened this issue May 26, 2018 · 1 comment
Open

testing exec replies #57

simbo1905 opened this issue May 26, 2018 · 1 comment

Comments

@simbo1905
Copy link

With a spec:

describe 'hello-world', ->
  beforeEach ->
    @room = helper.createRoom(httpd: false)
  afterEach ->
    @room.destroy()

  context 'user says hi to hubot', (done) ->
    beforeEach ->
      co =>
        yield @room.user.say 'alice', '@hubot hi'
        yield @room.user.say 'bob',   '@hubot hi'

    it 'should reply to user', ->
      console.log(@room.messages)
      expect(@room.messages).to.eql [
        ['alice', '@hubot hi']
        ['hubot', '@alice hi']
        ['bob',   '@hubot hi']
        ['hubot', '@bob hi']
      ]

Then a synchronous reply works as expected:

     robot.respond /hi$/i, (msg) -> 
       msg.reply('hi')

If I change the response to be the stdout of an require('child_process').exec such as:

     robot.respond /hi$/i, (msg) -> 
       @exec = require('child_process').exec
       command = "echo hi"
       @exec command, { shell: '/bin/bash' } , (error, stdout, stderr) ->
         if error
            msg.send "@#{msg.message.user.name} " + "Ops! Not able to run "+ command +" ```" + stderr + "```"
         else
            msg.reply stdout

Then the test fails with only two messages in the room with no responses from hubot. Yet if I run the hubot then the output of @exec command appears as expected.

How do I test code that uses @exec command to generate hubot responses?

@thinca
Copy link

thinca commented Sep 24, 2018

I met a similar problem, but the README taught me the answer.
https://github.com/mtsmfm/hubot-test-helper#manual-delay

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

2 participants