[test] More tests for nconf

This commit is contained in:
indexzero 2011-04-02 04:41:50 -04:00
parent 09b8c75383
commit 79717ac3b1
2 changed files with 58 additions and 22 deletions

View file

@ -62,7 +62,7 @@ nconf.load = function (callback) {
if (!nconf.store.load) { if (!nconf.store.load) {
var error = new Error('nconf store ' + nconf.store.type + ' has no load() method'); var error = new Error('nconf store ' + nconf.store.type + ' has no load() method');
if (callback) { if (callback) {
return callback (err); return callback (error);
} }
throw error; throw error;
@ -87,7 +87,7 @@ nconf.save = function (value, callback) {
if (!nconf.store.save) { if (!nconf.store.save) {
var error = new Error('nconf store ' + nconf.store.type + ' has no save() method'); var error = new Error('nconf store ' + nconf.store.type + ' has no save() method');
if (callback) { if (callback) {
return callback (err); return callback (error);
} }
throw error; throw error;

View file

@ -29,29 +29,65 @@ vows.describe('nconf').addBatch({
}, },
"the use() method": { "the use() method": {
"should instaniate the correct store": function () { "should instaniate the correct store": function () {
nconf.use('redis'); nconf.use('memory');
assert.instanceOf(nconf.store, nconf.stores.Redis); assert.instanceOf(nconf.store, nconf.stores.Memory);
} }
} }
} }
})/*.addBatch({ }).addBatch({
"When using the nconf file store": { "When using the nconf": {
"the set() method": { "with the memory store": {
"should respond with true": function () { "the set() method": {
assert.isTrue(store.set('foo:bar:bazz', 'buzz')); "should respond with true": function () {
} assert.isTrue(nconf.set('foo:bar:bazz', 'buzz'));
}, }
"the get() method": { },
"should respond with the correct value": function () { "the get() method": {
assert.equal(store.get('foo:bar:bazz'), 'buzz'); "should respond with the correct value": function () {
} assert.equal(nconf.get('foo:bar:bazz'), 'buzz');
}, }
"the clear() method": { },
"should respond with the true": function () { "the clear() method": {
assert.equal(store.get('foo:bar:bazz'), 'buzz'); "should respond with the true": function () {
assert.isTrue(store.clear('foo:bar:bazz')); assert.equal(nconf.get('foo:bar:bazz'), 'buzz');
assert.isTrue(typeof store.get('foo:bar:bazz') === 'undefined'); assert.isTrue(nconf.clear('foo:bar:bazz'));
assert.isTrue(typeof nconf.get('foo:bar:bazz') === 'undefined');
}
},
"the load() method": {
"without a callback": {
"should throw an exception": function () {
assert.throws(function () {
nconf.load();
})
}
},
"with a callback": {
topic: function () {
nconf.load(this.callback.bind(null, null));
},
"should respond with an error": function (ign, err) {
assert.isNotNull(err);
}
}
},
"the save() method": {
"without a callback": {
"should throw an exception": function () {
assert.throws(function () {
nconf.save();
})
}
},
"with a callback": {
topic: function () {
nconf.save(this.callback.bind(null, null));
},
"should respond with an error": function (ign, err) {
assert.isNotNull(err);
}
}
} }
} }
} }
})*/.export(module); }).export(module);