From aa209f1c8ef4673d316118cb70b5e6b867b429a1 Mon Sep 17 00:00:00 2001 From: Corey Donohoe Date: Tue, 3 Jun 2014 21:10:26 -0700 Subject: [PATCH 1/4] allow for absolute pathing to adapters for testing --- src/robot.coffee | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/robot.coffee b/src/robot.coffee index be066d722..264f438c4 100644 --- a/src/robot.coffee +++ b/src/robot.coffee @@ -323,7 +323,10 @@ class Robot path = if adapter in HUBOT_DEFAULT_ADAPTERS "#{path}/#{adapter}" else - "hubot-#{adapter}" + if path.indexOf("/") == 0 + "#{path}/#{adapter}" + else + "hubot-#{adapter}" @adapter = require(path).use @ catch err From fcd6a633c01ea7b3a3d33f6164f452e3b9382057 Mon Sep 17 00:00:00 2001 From: Corey Donohoe Date: Thu, 12 Jun 2014 16:27:22 -0700 Subject: [PATCH 2/4] check for directory existence --- src/robot.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/robot.coffee b/src/robot.coffee index 264f438c4..707a193b8 100644 --- a/src/robot.coffee +++ b/src/robot.coffee @@ -323,7 +323,7 @@ class Robot path = if adapter in HUBOT_DEFAULT_ADAPTERS "#{path}/#{adapter}" else - if path.indexOf("/") == 0 + if Fs.existsSync(path) "#{path}/#{adapter}" else "hubot-#{adapter}" From 4bc387d9db22674e3fe141b1de7897db4a190d94 Mon Sep 17 00:00:00 2001 From: Corey Donohoe Date: Thu, 12 Jun 2014 16:31:09 -0700 Subject: [PATCH 3/4] just drop the test adapter into the project --- src/adapters/test.coffee | 25 +++++++++++++++++++++++++ src/robot.coffee | 6 ++---- 2 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 src/adapters/test.coffee diff --git a/src/adapters/test.coffee b/src/adapters/test.coffee new file mode 100644 index 000000000..48cd87440 --- /dev/null +++ b/src/adapters/test.coffee @@ -0,0 +1,25 @@ +Robot = require '../robot' +Adapter = require '../adapter' +{TextMessage} = require '../message' + +class Test extends Adapter + send: (envelope, strings...) -> + for str in strings + @history.push str + + reply: (envelope, strings...) -> + strings = strings.map (s) -> "#{envelope.user.name}: #{s}" + @send envelope, strings... + + receiveText: (input) -> + user = @robot.brain.userForId '1', name: 'test', room: 'Test' + textMessage = new TextMessage user, input, 'messageId' + @receive textMessage + + run: -> + self = @ + @history = [ ] + self.emit 'connected' + +exports.use = (robot) -> + new Test robot diff --git a/src/robot.coffee b/src/robot.coffee index 707a193b8..a93ca033c 100644 --- a/src/robot.coffee +++ b/src/robot.coffee @@ -13,6 +13,7 @@ Response = require './response' HUBOT_DEFAULT_ADAPTERS = [ 'campfire' 'shell' + 'test' ] HUBOT_DOCUMENTATION_SECTIONS = [ @@ -323,10 +324,7 @@ class Robot path = if adapter in HUBOT_DEFAULT_ADAPTERS "#{path}/#{adapter}" else - if Fs.existsSync(path) - "#{path}/#{adapter}" - else - "hubot-#{adapter}" + "hubot-#{adapter}" @adapter = require(path).use @ catch err From c212674dc64d80c41b11f3e7f3044d5fc45debf0 Mon Sep 17 00:00:00 2001 From: Corey Donohoe Date: Thu, 12 Jun 2014 16:40:56 -0700 Subject: [PATCH 4/4] add basic docs for the test adapter --- docs/adapters.md | 3 ++- docs/adapters/test.md | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 docs/adapters/test.md diff --git a/docs/adapters.md b/docs/adapters.md index 331d4948f..69ed4c49e 100644 --- a/docs/adapters.md +++ b/docs/adapters.md @@ -4,9 +4,10 @@ Adapters are the interface to the service you want your hubot to run on. ## Official Adapters -Hubot includes two official adapters: +Hubot includes three official adapters: * [Shell](adapters/shell.md), i.e. for use with development +* [Test](adapters/test.md), i.e. for use with testing * [Campfire](adapters/campfire.md) ## Third-party Adapters diff --git a/docs/adapters/test.md b/docs/adapters/test.md new file mode 100644 index 000000000..07cc23138 --- /dev/null +++ b/docs/adapters/test.md @@ -0,0 +1,35 @@ +# Adapters: Test + +The test adapter provides a simple way to test what hubot would've responded to in your own scripts. +It can be useful for testing scripts that you distribute via npm. + +## Getting Started + +```coffeescript +Path = require("path") +Robot = require("hubot").Robot + +pkg = require Path.join __dirname, "..", 'package.json' +testAdapter = Path.join(__dirname, "adapters") + +Version = pkg.version + +describe "The Hubot Script", () -> + robot = null + beforeEach () -> + robot = new Robot testAdapter, "test", false, "hubot" + robot.loadFile Path.join(__dirname, "..", "src"), "script.coffee" + robot.run() + + afterEach () -> + robot.shutdown() + + it "displays the version", () -> + robot.adapter.receiveText("hubot deploy:version") + expected = "hubot-deploy v#{Version}/hubot v2.7.5/node v0.10.21" + assert.equal expected, robot.adapter.history +``` + +## Configuring + +This adapter doesn't require any configuration.