Permalink
Browse files

first successful mock

  • Loading branch information...
1 parent 93e769a commit af3c15896d9b60062bec356e94ffe9e0eb0a058a @mwawrusch mwawrusch committed Oct 14, 2011
Showing with 29 additions and 8 deletions.
  1. +4 −4 lib/index.js
  2. +17 −0 spec/mock-spec.coffee
  3. +4 −0 spec/spec_helper.coffee
  4. +4 −4 src/index.coffee
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -18,4 +18,21 @@ vows.describe("integration_task")
return
"THEN IT SHOULD SET UP :)": () ->
assert.isTrue true
+ .addBatch
+ "WHEN mocking a single trigger that emits a bar::foo event":
+ topic: () ->
+ specHelper.setMock
+ name: "mock1"
+ triggers: [
+ "event" : "foo::bar"
+ ]
+ actions: [
+ "event" : "bar::foo"
+ ]
+
+ specHelper.hookMeUp @callback
+ specHelper.hook.emit "foo::bar", {}
+ return
+ "THEN it must receive the bar::foo event": (err,event,data) ->
+ assert.equal event,"bar::foo"
.export module
View
@@ -31,6 +31,10 @@ module.exports =
try
fs.unlinkSync @tmpPath(file)
catch ignore
+
+ setMock: (mock) ->
+ @hook.mocks = []
+ @hook._addMock mock
# Invoke this in your topic and pass your callback.
# The cb will be called with: null,event,data
View
@@ -18,7 +18,7 @@ Mock = exports.Mock = (options) ->
self._anyCalled self.event,data
self.on "mock::add", (data)->
- self._addMock(data)
+ self._addMock(data.mock)
self.on "mock::remove", (data)->
self._removeMock(data)
@@ -45,13 +45,13 @@ Mock.prototype._anyCalled = (eventName,data) ->
if @_isMatch(eventName,mock)
@_fireActions(mock)
-Mock.prototype._addMock = (data) ->
+Mock.prototype._addMock = (mock) ->
##@emit "mock::error", data
- @mocks.push data.mock
+ @mocks.push mock
@emit "mock::added",
- name : data.mock.name
+ name : mock.name
Mock.prototype._removeMock = (data) ->
##@emit "mock::error", data

0 comments on commit af3c158

Please sign in to comment.