Skip to content

Commit

Permalink
test(robot): test robot.loadFile with coffee script file
Browse files Browse the repository at this point in the history
trying to parseHelp for a coffeescript file causes unexpexted syntax errors becuase coffe-script is not registered - causes hubotio#1376
  • Loading branch information
timkinnane committed Jul 29, 2017
1 parent 1f8d46e commit b8b2895
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
37 changes: 36 additions & 1 deletion test/robot_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ describe('Robot', function () {
expect(module._load).to.have.been.calledWith('scripts/test-script')
})

describe('proper script', function () {
describe('proper script (js)', function () {
let script

beforeEach(function () {
Expand Down Expand Up @@ -419,6 +419,41 @@ describe('Robot', function () {
})
})

describe('proper script (coffee)', function () {
let script

beforeEach(function () {
script = {
path: path.resolve('./test/scripts'),
file: 'test-script.coffee',
full: path.resolve('./test/scripts/test-script.coffee')
}
script.required = require(script.full)
this.sandbox.stub(require('module'), '_load').returns(script.required)
sinon.spy(this.robot, 'parseHelp')
})
afterEach(function () {
this.robot.parseHelp.restore()
})

it('should call the script with the Robot', function () {
this.robot.loadFile(script.path, script.file)
expect(script.required).to.have.been.calledWith(this.robot)
})

it('should parse the script documentation', function () {
this.robot.loadFile(script.path, script.file)
expect(this.robot.parseHelp).to.have.been.calledWith(script.full)
})

it('passes the commands in script comment documentation', function () {
this.robot.loadFile(script.path, script.file)
expect(this.robot.commands).to.eql([
'hubot <ping> - replies @user pong'
])
})
})

describe('non-Function script', function () {
beforeEach(function () {
const module = require('module')
Expand Down
10 changes: 10 additions & 0 deletions test/scripts/test-script.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Description:
# Says pong when you say ping
#
# Commands:
# hubot <ping> - replies @user pong
#
sinon = require 'sinon'
module.exports = sinon.spy (robot) ->
robot.respond /ping/i, (res) ->
res.reply 'pong'

0 comments on commit b8b2895

Please sign in to comment.