dependency-injection
Advanced tools
Comparing version 1.6.1 to 1.6.2
@@ -22,3 +22,3 @@ // Generated by CoffeeScript 1.6.3 | ||
if (__indexOf.call(this.reserved, name) >= 0) { | ||
throw new Error("DI: name '" + name + "' is reserved by DI"); | ||
throw new Error("DI: name '" + name + "' is reserved by DI."); | ||
} | ||
@@ -65,3 +65,3 @@ this.services[name] = new Service(this, service, args); | ||
} else if (this.findDefinitionByName(arg).autowired === false) { | ||
throw new Error("DI: service " + arg + " can not be autowired"); | ||
throw new Error("DI: Service '" + arg + "' can not be autowired."); | ||
} else if (factory === true) { | ||
@@ -117,3 +117,3 @@ result.push(this.getFactory(arg)); | ||
if (!(fn instanceof Function)) { | ||
throw new Error('Inject method can be called only on functions.'); | ||
throw new Error('DI: Inject method can be called only on functions.'); | ||
} | ||
@@ -130,3 +130,3 @@ args = this.autowireArguments(fn, []); | ||
if (need === true) { | ||
throw new Error("DI: Service '" + name + "' was not found"); | ||
throw new Error("DI: Service '" + name + "' was not found."); | ||
} else { | ||
@@ -133,0 +133,0 @@ return null; |
{ | ||
"name": "dependency-injection", | ||
"description": "Dependency injection with configuration and autowire for node js and browser", | ||
"version": "1.6.1", | ||
"version": "1.6.2", | ||
"author": { | ||
@@ -25,6 +25,6 @@ "name": "David Kudera", | ||
"dependencies": { | ||
"easy-configuration": "latest" | ||
"easy-configuration": "~1.5.4" | ||
}, | ||
"devDependencies": { | ||
"should": "1.2.2" | ||
"chai": "~1.8.1" | ||
}, | ||
@@ -31,0 +31,0 @@ "scripts": { |
@@ -280,2 +280,7 @@ # Dependency injection | ||
* 1.6.2 | ||
+ Some optimizations | ||
+ Should assert module replaced with chai | ||
+ Better error messages | ||
* 1.6.1 | ||
@@ -282,0 +287,0 @@ + Bug with setting other arguments than strings |
// Generated by CoffeeScript 1.6.3 | ||
(function() { | ||
var Application, DI, Http, Service, di, dir, path, should; | ||
var Application, DI, Http, Service, di, dir, expect, path; | ||
should = require('should'); | ||
expect = require('chai').expect; | ||
@@ -27,11 +27,11 @@ path = require('path'); | ||
it('should return instance of new Service class from object', function() { | ||
return di.addService('array', Array).should.be.instanceOf(Service); | ||
return expect(di.addService('array', Array)).to.be.an["instanceof"](Service); | ||
}); | ||
it('should return instance of new Service class from path', function() { | ||
return di.addService('app', "" + dir + "/Application").should.be.instanceOf(Service); | ||
return expect(di.addService('app', "" + dir + "/Application")).to.be.an["instanceof"](Service); | ||
}); | ||
it('should throw an error if you try to register service with reserved name', function() { | ||
return (function() { | ||
return expect(function() { | ||
return di.addService('di', DI); | ||
}).should["throw"](); | ||
}).to["throw"](Error, "DI: name 'di' is reserved by DI."); | ||
}); | ||
@@ -41,3 +41,3 @@ return it('should create service with null as arguments', function() { | ||
di.addService('app', "" + dir + "/Application", [null]); | ||
return should.not.exists(di.get('app').array); | ||
return expect(di.get('app').array).to.not.exists; | ||
}); | ||
@@ -48,3 +48,3 @@ }); | ||
di.addService('array', Array); | ||
return di.autowireArguments(Application).should.be.eql([[]]); | ||
return expect(di.autowireArguments(Application)).to.be.eql([[]]); | ||
}); | ||
@@ -55,4 +55,4 @@ it('should return array with services for inject method', function() { | ||
args = di.autowireArguments((new Application([])).injectHttp); | ||
args.should.have.length(1); | ||
return args[0].should.be.an.instanceOf(Http); | ||
expect(args).to.have.length(1); | ||
return expect(args[0]).to.be.an["instanceof"](Http); | ||
}); | ||
@@ -63,8 +63,8 @@ it('should return array with services for Application with custom ones', function() { | ||
app = new Application([]); | ||
return di.autowireArguments(app.prepare, ['simq']); | ||
return expect(di.autowireArguments(app.prepare, ['simq'])).to.be.eql(['simq', ['hello']]); | ||
}); | ||
it('should throw an error if service to autowire does not exists', function() { | ||
return (function() { | ||
return expect(function() { | ||
return di.autowireArguments(Application); | ||
}).should["throw"](); | ||
}).to["throw"](Error, "DI: Service 'array' was not found."); | ||
}); | ||
@@ -74,3 +74,3 @@ it('should return array with services from params if they are not in definition', function() { | ||
app = new Application([]); | ||
return di.autowireArguments(app.withoutDefinition, ['hello']).should.be.eql(['hello']); | ||
return expect(di.autowireArguments(app.withoutDefinition, ['hello'])).to.be.eql(['hello']); | ||
}); | ||
@@ -83,3 +83,3 @@ return it('should inject another service by at char', function() { | ||
di.addService('array', Array); | ||
return di.autowireArguments(fn, ['@array']).should.be.eql([[]]); | ||
return expect(di.autowireArguments(fn, ['@array'])).to.be.eql([[]]); | ||
}); | ||
@@ -95,11 +95,11 @@ }); | ||
app = di.createInstance(Application); | ||
app.should.be.an.instanceOf(Application); | ||
app.array.should.be.an.instanceOf(Array); | ||
return app.http.should.be.an.instanceOf(Http); | ||
expect(app).to.be.an["instanceof"](Application); | ||
expect(app.array).to.be.an["instanceof"](Array); | ||
return expect(app.http).to.be.an["instanceof"](Http); | ||
}); | ||
return it('should throw an error when service to inject does not exists', function() { | ||
delete di.services.http; | ||
return (function() { | ||
return expect(function() { | ||
return di.createInstance(Application); | ||
}).should["throw"](); | ||
}).to["throw"](Error, "DI: Service 'http' was not found."); | ||
}); | ||
@@ -110,8 +110,8 @@ }); | ||
di.addService('array', Array); | ||
return di.findDefinitionByName('array').should.be.an.instanceOf(Service); | ||
return expect(di.findDefinitionByName('array')).to.be.an["instanceof"](Service); | ||
}); | ||
return it('should throw an error if service is not registered', function() { | ||
return (function() { | ||
return expect(function() { | ||
return di.findDefinitionByName('array'); | ||
}).should["throw"](); | ||
}).to["throw"](Error, "DI: Service 'array' was not found."); | ||
}); | ||
@@ -131,22 +131,22 @@ }); | ||
app = di.get('application'); | ||
app.should.be.an.instanceOf(Application); | ||
app.namespace.should.be.equal('simq'); | ||
app.array.should.be.eql([]); | ||
return app.http.should.be.an.instanceOf(Http); | ||
expect(app).to.be.an["instanceof"](Application); | ||
expect(app.namespace).to.be.equal('simq'); | ||
expect(app.array).to.be.eql([]); | ||
return expect(app.http).to.be.an["instanceof"](Http); | ||
}); | ||
it('should return always the same instance of Application', function() { | ||
return di.get('application').should.be.equal(di.get('application')); | ||
return expect(di.get('application')).to.be.equal(di.get('application')); | ||
}); | ||
it('should return info array without instantiating it', function() { | ||
return di.get('info').should.be.eql(['hello']); | ||
return expect(di.get('info')).to.be.eql(['hello']); | ||
}); | ||
it('should not set services which are not autowired', function() { | ||
di.findDefinitionByName('application').addSetup('setData'); | ||
return (function() { | ||
return expect(function() { | ||
return di.get('application'); | ||
}).should["throw"](); | ||
}).to["throw"](Error, "DI: Service 'noArray' can not be autowired."); | ||
}); | ||
it('should autowire di container into Application instance', function() { | ||
di.findDefinitionByName('application').addSetup('setDi'); | ||
return di.get('application').di.should.be.equal(di); | ||
return expect(di.get('application').di).to.be.equal(di); | ||
}); | ||
@@ -157,8 +157,8 @@ it('should autowire di container factory into Application instance', function() { | ||
factory = di.get('application').diFactory; | ||
factory.should.be.an.instanceOf(Function); | ||
return factory().should.be.equal(di); | ||
expect(factory).to.be.an["instanceof"](Function); | ||
return expect(factory()).to.be.equal(di); | ||
}); | ||
return it('should set info property directly', function() { | ||
di.findDefinitionByName('application').addSetup('info', 'by property'); | ||
return di.get('application').info.should.be.equal('by property'); | ||
return expect(di.get('application').info).to.be.equal('by property'); | ||
}); | ||
@@ -168,3 +168,3 @@ }); | ||
return it('should return always new instance of Application', function() { | ||
return di.create('application').should.not.be.equal(di.create('application')); | ||
return expect(di.create('application')).to.not.be.equal(di.create('application')); | ||
}); | ||
@@ -176,4 +176,4 @@ }); | ||
factory = di.getFactory('application'); | ||
factory.should.be.an.instanceOf(Function); | ||
return factory().should.be.an.instanceOf(Application); | ||
expect(factory).to.be.an["instanceof"](Function); | ||
return expect(factory()).to.be.an["instanceof"](Application); | ||
}); | ||
@@ -185,3 +185,3 @@ }); | ||
return di.inject(function(array) { | ||
array.should.be.eql([]); | ||
expect(array).to.be.eql([]); | ||
return done(); | ||
@@ -191,5 +191,5 @@ }); | ||
return it('should throw an error if inject method is not called on function', function() { | ||
return (function() { | ||
return expect(function() { | ||
return di.inject(''); | ||
}).should["throw"](); | ||
}).to["throw"](Error, "DI: Inject method can be called only on functions."); | ||
}); | ||
@@ -196,0 +196,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
40646
340
+ Addedclone@0.1.19(transitive)
+ Addedeasy-configuration@1.5.7(transitive)
+ Addedrecursive-merge@1.0.0(transitive)
- Removedcallsite@1.0.0(transitive)
- Removedeasy-configuration@2.0.2(transitive)
- Removedrecursive-merge@1.2.1(transitive)
Updatedeasy-configuration@~1.5.4