Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
Merge 0b0702a into c00f2ca
Browse files Browse the repository at this point in the history
  • Loading branch information
wmakeev committed Nov 27, 2014
2 parents c00f2ca + 0b0702a commit 2aa9ea3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion plugins/src/scaleApp.strophe.coffee
Expand Up @@ -169,7 +169,7 @@ plugin = (core) ->

when s.ERROR
resetPlugin()
mediator.emit "error", "an error occoured"
mediator.emit "error", "an error occurred"
when s.CONNECTING
resetPlugin()
mediator.emit "connecting"
Expand Down
14 changes: 7 additions & 7 deletions spec/Core.spec.coffee
Expand Up @@ -78,7 +78,7 @@ describe "scaleApp core", ->
(expect err).not.to.exist
done()

it "returns an error if instance was aleready started", (done) ->
it "returns an error if instance was already started", (done) ->
@core.start "myId", =>
@core.start "myId", (err) ->
(expect err).to.exist
Expand Down Expand Up @@ -133,17 +133,17 @@ describe "scaleApp core", ->
@core.start "anId", cb
(expect cb).to.have.been.called

it "calls the callback function with an error if an error occours", (done) ->
it "calls the callback function with an error if an error occurs", (done) ->
initCB = sinon.spy()
mod1 = (sb) ->
init: ->
initCB()
thisWillProcuceAnError()
thisWillProduceAnError()
(expect @core.register "anId", mod1).to.equal @core
@core.start "anId", (err)->
(expect initCB).to.have.been.called
(expect err.message.indexOf("could not start module:") >= 0).to.be.true
(expect err.message.indexOf("thisWillProcuceAnError") >= 0).to.be.true
(expect err.message.indexOf("thisWillProduceAnError") >= 0).to.be.true
done()

it "starts a separate instance", ->
Expand Down Expand Up @@ -255,7 +255,7 @@ describe "scaleApp core", ->
@core.start ["invalid", "valid"], (err) ->
(expect spy1).to.have.been.called
(expect spy2).to.have.been.called
(expect err.message).to.equal "errors occoured in the following modules: 'invalid'"
(expect err.message).to.equal "errors occurred in the following modules: 'invalid'"
(expect err.moduleErrors.invalid?).to.equal true
(expect err.moduleErrors.invalid instanceof Error).to.equal true
(expect err.moduleErrors.valid?).to.equal false
Expand All @@ -271,7 +271,7 @@ describe "scaleApp core", ->
@core.register "valid", @validModule
@core.register "x", mod
finished = (err) ->
(expect err.message).to.equal "errors occoured in the following modules: 'invalid','y'"
(expect err.message).to.equal "errors occurred in the following modules: 'invalid','y'"
done()
(expect @core.start ["valid","invalid", "x", "y"], finished).to.equal @core
(expect spy2).to.have.been.called
Expand Down Expand Up @@ -431,7 +431,7 @@ describe "scaleApp core", ->
sb.bar = -> "foo"
done()

it "does not regsiter a plugin if it is not a function", ->
it "does not register a plugin if it is not a function", ->
(expect @core.use("foo")._plugins.length).to.equal 0

it "registers a plugin if it's a function", ->
Expand Down
24 changes: 11 additions & 13 deletions spec/Mediator.spec.coffee
Expand Up @@ -22,7 +22,6 @@ describe "Mediator", ->
ch = "a channel"
obj = {}
cb1 = sinon.spy()
cb2 = sinon.spy()

sub = @paul.on ch, cb1
sub2 = @paul.on ch, cb1, obj
Expand Down Expand Up @@ -88,21 +87,21 @@ describe "Mediator", ->
describe "off function", ->

it "removes a subscription from a channel", ->

ch = "a channel"
obj = {}
cb1 = sinon.spy()
cb2 = sinon.spy()

@paul.on ch, cb1
sub = @paul.on ch, cb2
@paul.on ch, cb2

@paul.emit ch, "hello"
@paul.off ch, cb1
@paul.emit ch, "hello2"
(expect cb1.callCount).to.equal 1
(expect cb2.callCount).to.equal 2

it "removes a callbackfunction from all channels", ->
it "removes a callback function from all channels", ->

ch1 = "channel1"
ch2 = "channel2"
Expand Down Expand Up @@ -194,11 +193,11 @@ describe "Mediator", ->
it "calls the callback if it is defined", (done) ->
cb = sinon.spy()
@paul.on "event", cb
@paul.emit "event", {}, (err) ->
@paul.emit "event", {}, () ->
(expect cb.callCount).to.equal 1
done()

it "calls the callback even if there are not subsribers", (done) ->
it "calls the callback even if there are not subscribers", (done) ->
m1 = new @Mediator
m2 = new @Mediator
m1.emit "x", (err)->
Expand All @@ -217,7 +216,7 @@ describe "Mediator", ->
done()


it "calls the callback asynchrounously", (done) ->
it "calls the callback asynchronously", (done) ->
cb = sinon.spy()
cb2 = sinon.spy()
@paul.on "event", (data, channel, next) ->
Expand All @@ -230,8 +229,7 @@ describe "Mediator", ->
(expect err?).to.be.false
done()

it "calls the callback asynchrounously and looks for errors", (done) ->

it "calls the callback asynchronously and looks for errors", (done) ->
@paul.on "event", (data, channel, next) ->
setTimeout (-> next null), 1
@paul.on "event", (data, channel, x) ->
Expand Down Expand Up @@ -274,6 +272,7 @@ describe "Mediator", ->
(expect cb2.callCount).to.equal 3

it "takes care of the context", (done) ->

mediator = new @Mediator
myObj = {}
empty = {}
Expand All @@ -288,7 +287,6 @@ describe "Mediator", ->
done()

it "installs the mediator functions on creation", ->

myObj = {}
new @Mediator myObj
(expect myObj.on).to.be.a "function"
Expand Down Expand Up @@ -326,11 +324,11 @@ describe "Mediator", ->
@anObject.on "a channel", @cb
@peter.on "a channel", @cb2
@paul.emit "a channel", @data
@paul.emit "doees not exist", @data
@paul.emit "does not exist", @data
(expect @cb.callCount).to.equal 2
(expect @cb2).not.to.have.been.called

it "publishes data to all subscribers even if an error occours", ->
it "publishes data to all subscribers even if an error occurs", ->
cb = sinon.spy()
@paul.on "channel", -> cb()
@paul.on "channel", -> (throw new Error "err"); cb()
Expand Down Expand Up @@ -368,7 +366,7 @@ describe "Mediator", ->

# then we bind the read event to our database
@dbAccess.on "read", (r) ->
# prcocess the query
# process the query
result = []
for user in db
result.push user for k,v of r.query when user[k] is v
Expand Down
4 changes: 2 additions & 2 deletions spec/Util.spec.coffee
Expand Up @@ -132,7 +132,7 @@ describe "Util", ->
cb2 = (next) -> thisMethodDoesNotExist()
cb3 = (next) -> next null, "three"
fini = (err, res) ->
(expect err).to.exsit
(expect err).to.exist
(expect res[0]).to.eql ["one", 2]
(expect res[1]).not.to.exist
(expect res[2]).not.to.exist
Expand Down Expand Up @@ -193,7 +193,7 @@ describe "Util", ->

it "returns an array of argument names", ->
fn = (a,b,c,d) ->
(expect @util.getArgumentNames fn).to.eql ["a","b","c", "d"]
(expect @util.getArgumentNames fn).to.eql ["a","b","c","d"]
(expect @util.getArgumentNames ->).to.eql []

it "does not break if the function is not defined", ->
Expand Down
2 changes: 1 addition & 1 deletion src/Core.coffee
Expand Up @@ -140,7 +140,7 @@ class Core
modErrors = {}
modErrors[mods[i]] = x for x,i in err when x?
mdls = ("'#{k}'" for k of modErrors)
e = new Error "errors occoured in the following modules: #{mdls}"
e = new Error "errors occurred in the following modules: #{mdls}"
e.moduleErrors = modErrors
cb? e
util.doForAll mods, startAction, done, true
Expand Down
2 changes: 1 addition & 1 deletion src/Mediator.coffee
Expand Up @@ -53,7 +53,7 @@ class Mediator
# Parameters:
# - (String) topic - The topic name
# - (Object) data - The data that gets published
# - (Funtction) - callback method
# - (Function) - callback method
emit: (channel, data, cb=->) ->

if typeof data is "function"
Expand Down

0 comments on commit 2aa9ea3

Please sign in to comment.