From a9c354032b8b4d3ea011d39bc98080dc0df05280 Mon Sep 17 00:00:00 2001 From: indexzero Date: Wed, 23 Nov 2011 21:37:50 -0500 Subject: [PATCH] [fix test] Fix overwritten tests in file-store-test.js --- test/stores/file-store-test.js | 62 ++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/test/stores/file-store-test.js b/test/stores/file-store-test.js index 3149d02..fd1fc38 100644 --- a/test/stores/file-store-test.js +++ b/test/stores/file-store-test.js @@ -10,39 +10,41 @@ var fs = require('fs'), vows = require('vows'), assert = require('assert'), nconf = require('../../lib/nconf'), - data = require('../fixtures/data').data, + data = require('../fixtures/data').data, store; vows.describe('nconf/stores/file').addBatch({ "When using the nconf file store": { - topic: function () { - var filePath = path.join(__dirname, '..', 'fixtures', 'store.json'); - fs.writeFileSync(filePath, JSON.stringify(data, null, 2)); - store = new nconf.File({ file: filePath }); - return null; - }, - "the load() method": { + "with a valid JSON file": { topic: function () { - store.load(this.callback); + var filePath = path.join(__dirname, '..', 'fixtures', 'store.json'); + fs.writeFileSync(filePath, JSON.stringify(data, null, 2)); + this.store = store = new nconf.File({ file: filePath }); + return null; }, - "should load the data correctly": function (err, data) { - assert.isNull(err); - assert.deepEqual(data, store.store); + "the load() method": { + topic: function () { + this.store.load(this.callback); + }, + "should load the data correctly": function (err, data) { + assert.isNull(err); + assert.deepEqual(data, this.store.store); + } } - } - }, - "When using the nconf file store": { - topic: function () { - var filePath = path.join(__dirname, '..', 'fixtures', 'malformed.json'); - store = new nconf.File({ file: filePath }); - return null; }, - "the load() method with a malformed JSON config file": { + "with a malformed JSON file": { topic: function () { - store.load(this.callback.bind(null, null)); + var filePath = path.join(__dirname, '..', 'fixtures', 'malformed.json'); + this.store = new nconf.File({ file: filePath }); + return null; }, - "should respond with an error": function (ign, err) { - assert.isTrue(!!err); + "the load() method with a malformed JSON config file": { + topic: function () { + this.store.load(this.callback.bind(null, null)); + }, + "should respond with an error": function (_, err) { + assert.isTrue(!!err); + } } } } @@ -57,19 +59,19 @@ vows.describe('nconf/stores/file').addBatch({ topic: function (tmpStore) { var that = this; - Object.keys(store.store).forEach(function (key) { - tmpStore.set(key, store.store[key]); - }); + Object.keys(data).forEach(function (key) { + tmpStore.set(key, data[key]); + }); tmpStore.save(function () { - fs.readFile(tmpStore.file, function (err, data) { - return err ? that.callback(err) : that.callback(err, JSON.parse(data.toString())); + fs.readFile(tmpStore.file, function (err, d) { + return err ? that.callback(err) : that.callback(err, JSON.parse(d.toString())); }); }); }, - "should save the data correctly": function (err, data) { + "should save the data correctly": function (err, read) { assert.isNull(err); - assert.deepEqual(data, store.store); + assert.deepEqual(read, data); } } }