updated tests to verify that Provider.load respects hierarchy

master
Jonathan Stewmon 2011-12-19 19:35:20 -06:00 committed by indexzero
parent a216336290
commit fdb73f007b
4 changed files with 47 additions and 16 deletions

View File

@ -18,7 +18,8 @@
"pkginfo": "0.2.x"
},
"devDependencies": {
"vows": "0.6.x"
"vows": "0.6.x",
"eyes": "0.1.7"
},
"main": "./lib/nconf",
"scripts": { "test": "vows test/*-test.js test/**/*-test.js --spec" },

View File

@ -1,7 +1,11 @@
{
"apples": true,
"bananas": true,
"foo": {
"bar": "boo"
},
"candy": {
"something": "file1",
"something1": true,
"something2": true
}

View File

@ -1,5 +1,6 @@
{
"candy": {
"something": "file2",
"something3": true,
"something4": true
},

View File

@ -11,7 +11,8 @@ var assert = require('assert'),
spawn = require('child_process').spawn,
vows = require('vows'),
helpers = require('./helpers'),
nconf = require('../lib/nconf');
nconf = require('../lib/nconf'),
eyes = require('eyes');
var fixturesDir = path.join(__dirname, 'fixtures'),
mergeFixtures = path.join(fixturesDir, 'merge'),
@ -72,23 +73,47 @@ vows.describe('nconf/provider').addBatch({
provider.load();
provider.merge(override);
helpers.assertMerged(null, provider.stores.file.store);
assert.equal(provider.stores.file.store.candy.something, 'file1');
}
},
"when sources are passed in": {
topic: new nconf.Provider({
sources: {
user: {
type: 'file',
file: files[0]
},
global: {
type: 'file',
file: files[1]
}
}
}
}).addBatch({
"When using nconf": {
"an instance of 'nconf.Provider'": {
"the load() method": {
"when sources are passed in": {
topic: new nconf.Provider({
sources: {
user: {
type: 'file',
file: files[0]
},
global: {
type: 'file',
file: files[1]
}
}
}),
"should respect the hierarchy ": function (provider) {
var merged = provider.load();
helpers.assertMerged(null, merged);
assert.equal(merged.candy.something, 'file1');
console.log(provider.sources);
}
},
"when multiple stores are used": {
topic: new nconf.Provider().overrides({foo: {bar: 'baz'}})
.add('file1', {type: 'file', file: files[0]})
.add('file2', {type: 'file', file: files[1]}),
"should respect the hierarchy": function(provider) {
var merged = provider.load();
helpers.assertMerged(null, merged);
assert.equal(merged.foo.bar, 'baz');
assert.equal(merged.candy.something, 'file1');
}
}),
"should have the result merged in": function (provider) {
helpers.assertMerged(null, provider.load());
}
}
}