diff --git a/package.json b/package.json index 91d23b7..0c776a4 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/test/fixtures/merge/file1.json b/test/fixtures/merge/file1.json index b5bf573..8005a30 100644 --- a/test/fixtures/merge/file1.json +++ b/test/fixtures/merge/file1.json @@ -1,7 +1,11 @@ { "apples": true, "bananas": true, + "foo": { + "bar": "boo" + }, "candy": { + "something": "file1", "something1": true, "something2": true } diff --git a/test/fixtures/merge/file2.json b/test/fixtures/merge/file2.json index 1214bf1..815779c 100644 --- a/test/fixtures/merge/file2.json +++ b/test/fixtures/merge/file2.json @@ -1,5 +1,6 @@ { "candy": { + "something": "file2", "something3": true, "something4": true }, diff --git a/test/provider-test.js b/test/provider-test.js index c0559b6..6091f37 100644 --- a/test/provider-test.js +++ b/test/provider-test.js @@ -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()); } } }