Skip to content

Commit

Permalink
chore: Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsmfm committed Aug 20, 2016
1 parent 6c12f1a commit 77f1c95
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ class Room extends Hubot.Adapter
class Helper
@Response = MockResponse

constructor: (scriptsPath) ->
if not Array.isArray(scriptsPath)
scriptsPath = [scriptsPath]
@scriptsPath = scriptsPath
constructor: (scriptsPaths) ->
if not Array.isArray(scriptsPaths)
scriptsPaths = [scriptsPaths]
@scriptsPaths = scriptsPaths

createRoom: (options={}) ->
robot = new MockRobot(options.httpd)

if 'response' of options
robot.Response = options.response

for script in @scriptsPath
for script in @scriptsPaths
script = Path.resolve(Path.dirname(module.parent.filename), script)
if Fs.statSync(script).isDirectory()
for file in Fs.readdirSync(script).sort()
Expand Down
23 changes: 23 additions & 0 deletions test/load-multiple-scripts_test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Helper = require('../src/index')
helper = new Helper(['./scripts/hello-world.coffee', './scripts/bye.coffee'])

co = require('co')
expect = require('chai').expect

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

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

it 'should reply to user', ->
expect(@room.messages).to.eql [
['alice', '@hubot hi']
['hubot', '@alice hi']
['bob', '@hubot bye']
['hubot', '@bob bye']
]
5 changes: 5 additions & 0 deletions test/scripts/bye.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Description:
# Test script
module.exports = (robot) ->
robot.respond /bye$/i, (msg) ->
msg.reply 'bye'

0 comments on commit 77f1c95

Please sign in to comment.