Skip to content

Commit

Permalink
[fix test] Fix overwritten tests in file-store-test.js
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Nov 24, 2011
1 parent f4f1fdf commit a9c3540
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions test/stores/file-store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit a9c3540

Please sign in to comment.