Skip to content

Commit

Permalink
[test] Added failing test for .save() regression introduced by @rus…
Browse files Browse the repository at this point in the history
…sfrank in 36e061c
  • Loading branch information
indexzero committed Jul 10, 2012
1 parent 04e2230 commit 7e8d9d6
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/mocks/mock-store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* mock-store.js: Mock store for ensuring certain operations are actually called.
*
* (C) 2011, Nodejitsu Inc.
*
*/

var util = require('util'),
events = require('events'),
nconf = require('../../lib/nconf');

var Mock = nconf.Mock = function () {
events.EventEmitter.call(this);
this.type = 'mock';
};

// Inherit from Memory store.
util.inherits(Mock, events.EventEmitter);

//
// ### function save (value, callback)
// #### @value {Object} _Ignored_ Left here for consistency
// #### @callback {function} Continuation to respond to when complete.
// Waits `1000ms` and then calls the callback and emits the `save` event.
//
Mock.prototype.save = function (value, callback) {
if (!callback && typeof value === 'function') {
callback = value;
value = null;
}

var self = this;

setTimeout(function () {
self.emit('save');
callback();
}, 1000);
};
39 changes: 39 additions & 0 deletions test/provider-save-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* provider-save-test.js: Ensures consistency for Provider `save` operations.
*
* (C) 2011, Nodejitsu Inc.
*
*/

var assert = require('assert'),
vows = require('vows'),
nconf = require('../lib/nconf');

//
// Expose `nconf.Mock`
//
require('./mocks/mock-store');

vows.describe('nconf/provider').addBatch({
"When using nconf": {
"an instance of 'nconf.Provider'": {
"with a Mock store": {
topic: function () {
return nconf.use('mock');
},
"the save() method": {
topic: function () {
var mock = nconf.stores.mock,
that = this;

mock.on('save', function () { that.saved = true });
nconf.save(this.callback);
},
"should actually save before responding": function () {
assert.isTrue(this.saved);
}
}
}
}
}
}).export(module);

0 comments on commit 7e8d9d6

Please sign in to comment.