[api minor] Add .loadSync() to Memory store. Fixes #24

This commit is contained in:
indexzero 2012-01-02 17:20:06 -05:00
parent d0a91219ec
commit 6242caafda
2 changed files with 14 additions and 4 deletions

View file

@ -200,3 +200,11 @@ Memory.prototype.reset = function () {
this.store = {}; this.store = {};
return true; return true;
}; };
//
// ### function loadSync
// Returns the store managed by this instance
//
Memory.prototype.loadSync = function () {
return this.store || {};
};

View file

@ -28,6 +28,7 @@ vows.describe('nconf').addBatch({
"the use() method": { "the use() method": {
"should instaniate the correct store": function () { "should instaniate the correct store": function () {
nconf.use('memory'); nconf.use('memory');
nconf.load();
assert.instanceOf(nconf.stores['memory'], nconf.Memory); assert.instanceOf(nconf.stores['memory'], nconf.Memory);
} }
}, },
@ -79,16 +80,17 @@ vows.describe('nconf').addBatch({
}, },
"the load() method": { "the load() method": {
"without a callback": { "without a callback": {
"should throw an exception": function () { "should respond with the merged store": function () {
assert.throws(function () { nconf.load() }); assert.deepEqual(nconf.load(), { foo: { bar: {} } });
} }
}, },
"with a callback": { "with a callback": {
topic: function () { topic: function () {
nconf.load(this.callback.bind(null, null)); nconf.load(this.callback.bind(null, null));
}, },
"should respond with an error": function (ign, err) { "should respond with the merged store": function (ign, err, store) {
assert.isNotNull(err); assert.isNull(err);
assert.deepEqual(store, { foo: { bar: {} } });
} }
} }
}, },