Permalink
Browse files

Merge pull request #229 from ejfinneran/fix-catch-all

Catch-all method firing for all messages
  • Loading branch information...
2 parents fadbf64 + 2d89b0a commit 270ca4dd859aee56f0202cc7bb91bbae76e8fef8 @tombell tombell committed Jan 28, 2012
Showing with 21 additions and 13 deletions.
  1. +3 −2 src/robot.coffee
  2. +15 −9 test/google_images_test.coffee
  3. +1 −0 test/robot_test.coffee
  4. +1 −1 test/scripts/test.coffee
  5. +1 −1 test/tests.coffee
View
@@ -109,9 +109,10 @@ class Robot
#
# Returns nothing.
receive: (message) ->
- results = for listener in @listeners
+ results = []
+ for listener in @listeners
try
- listener.call message
+ results.push listener.call(message)
break if message.done
catch ex
@logger.error "Unable to call the listener: #{ex}"
@@ -1,7 +1,7 @@
Tests = require './tests'
assert = require 'assert'
helper = Tests.helper()
-
+Robot = require '../src/robot'
require('../src/scripts/google-images') helper
# start up a danger room for google images
@@ -28,14 +28,20 @@ tests = [
]
# run the async tests
+messages = [
+ 'helper: stache me foo',
+ 'helper: stache foo',
+ 'helper: mustache me foo',
+ 'helper: mustache foo',
+ 'helper: img foo',
+ 'helper: image me foo',
+ 'helper: image foo',
+ 'helper: animate me foo'
+]
+user = {}
danger.start tests, ->
- helper.receive 'helper: stache me foo'
- helper.receive 'helper: stache foo'
- helper.receive 'helper: mustache me foo'
- helper.receive 'helper: mustache foo'
- helper.receive 'helper: img foo'
- helper.receive 'helper: image me foo'
- helper.receive 'helper: image foo'
- helper.receive 'helper: animate me foo'
+ for message in messages
+ helper.receive new Robot.TextMessage user, message
+
helper.stop()
View
@@ -1,6 +1,7 @@
Tests = require './tests'
assert = require 'assert'
helper = Tests.helper()
+require './scripts/test'
server = require('http').createServer (req, res) ->
res.writeHead 200
View
@@ -17,4 +17,4 @@ module.exports = (robot) ->
msg.send body
robot.catchall (msg) ->
- msg.send 'catch-all' if msg.message.text is 'foobar'
+ msg.send 'catch-all'
View
@@ -33,7 +33,7 @@ exports.danger = (helper, cb) ->
class Helper extends Robot
constructor: (scriptPath) ->
- super null, null, 'helper'
+ super null, null, true, 'helper'
@load scriptPath
@id = 1
@Response = Helper.Response

0 comments on commit 270ca4d

Please sign in to comment.