Permalink
Browse files

Merge pull request #8 from bengourley/master

Don't allow duplicate `addNamespace()` calls
  • Loading branch information...
2 parents b638e6a + b4eb59a commit dd5fd513e0d1af9673967766452a75589d41af1c @serby committed May 4, 2012
Showing with 23 additions and 9 deletions.
  1. +13 −9 lib/compact.js
  2. +10 −0 test/compact.test.js
View
@@ -38,16 +38,20 @@ module.exports.createCompact = function(options) {
throw new Error('Invalid namespace');
}
- if (!namespaces[name]) {
- var newNamespace = {};
- Object.defineProperty(namespaces, name, {
- get: function() { return newNamespace; },
- configurable: false,
- enumerable: true,
- set: function(value) {
- throw new Error('You can not alter a registered namespace \'' + name + '\''); }
- });
+ if (namespaces[name]) {
+ throw new Error('The namespace \'' +
+ name + '\' has already been added');
}
+
+
+ var newNamespace = {};
+ Object.defineProperty(namespaces, name, {
+ get: function() { return newNamespace; },
+ configurable: false,
+ enumerable: true,
+ set: function(value) {
+ throw new Error('You can not alter a registered namespace \'' + name + '\''); }
+ });
var namespace = namespaces[name];
function addJs(filePath) {
View
@@ -122,6 +122,16 @@ describe('compact.js', function() {
.addJs('b.js');
});
});
+
+ describe('#addNamespace()', function () {
+ it('should not allow a namespace to be added more than once', function () {
+ (function () {
+ compact.addNamespace('foo');
+ compact.addNamespace('foo');
+ }).should.throw('The namespace \'foo\' has already been added');
+ });
+ });
+
});
describe('#js()', function() {

0 comments on commit dd5fd51

Please sign in to comment.