[test] More tests for nconf

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

View File

@ -29,29 +29,65 @@ vows.describe('nconf').addBatch({
},
"the use() method": {
"should instaniate the correct store": function () {
nconf.use('redis');
assert.instanceOf(nconf.store, nconf.stores.Redis);
nconf.use('memory');
assert.instanceOf(nconf.store, nconf.stores.Memory);
}
}
}
})/*.addBatch({
"When using the nconf file store": {
"the set() method": {
"should respond with true": function () {
assert.isTrue(store.set('foo:bar:bazz', 'buzz'));
}
},
"the get() method": {
"should respond with the correct value": function () {
assert.equal(store.get('foo:bar:bazz'), 'buzz');
}
},
"the clear() method": {
"should respond with the true": function () {
assert.equal(store.get('foo:bar:bazz'), 'buzz');
assert.isTrue(store.clear('foo:bar:bazz'));
assert.isTrue(typeof store.get('foo:bar:bazz') === 'undefined');
}).addBatch({
"When using the nconf": {
"with the memory store": {
"the set() method": {
"should respond with true": function () {
assert.isTrue(nconf.set('foo:bar:bazz', 'buzz'));
}
},
"the get() method": {
"should respond with the correct value": function () {
assert.equal(nconf.get('foo:bar:bazz'), 'buzz');
}
},
"the clear() method": {
"should respond with the true": function () {
assert.equal(nconf.get('foo:bar:bazz'), 'buzz');
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);