-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test] Added failing test for
.save()
regression introduced by @rus…
…sfrank in 36e061c
- Loading branch information
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |