我试图为我的hubot代码设置一个简单的单元测试,但我没有收到回复。我把它简化为:
test.coffee:
Helper = require('hubot-test-helper')
chai = require 'chai'
expect = chai.expect
helper = new Helper('../hubot-scripts/something.coffee')
describe 'PING', ->
beforeEach ->
@room = helper.createRoom()
afterEach ->
@room.destroy
it 'should PONG', ->
@room.user.say 'alice', '@hubot PING'
expect(@room.messages).to.eql [
['alice', '@hubot PING'],
['hubot', 'PONG']
]
and something.coffee:
module.exports = (robot) ->
robot.response /PING$/i, (msg) ->
msg.send 'PONG'
当我运行测试时,我得到一个断言错误:
AssertionError: expected [ [ 'alice', '@hubot PING' ] ] to deeply equal [ Array(2) ]
+ expected - actual
[
"alice"
"@hubot PING"
]
+ [
+ "hubot"
+ "PONG"
+ ]
]
意思是我根本没有回复。我试过将@hubot改成hubot(这不重要)。我还证实它找到了我的something.coffee,因为当我改变那条路径时,我收到了一个错误。
我正在关注https://hubot.github.com/docs/scripting/
底部的示例感谢您的帮助!
答案 0 :(得分:0)
对于遇到此问题的任何人,当我遇到相同的问题时,我都会发布question。
简而言之,问题是缩进-以expect
开始的行在执行@room.user.say
之前被调用。请查看我的链接以获取更多详细信息。
答案 1 :(得分:-1)
我不知道为什么,但将@ room.user.say移动到之前的块中会使这个工作。