1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | var fs = require('fs'),
|
9 | path = require('path'),
|
10 | vows = require('vows'),
|
11 | assert = require('assert'),
|
12 | nconf = require('../lib/nconf'),
|
13 | data = require('./fixtures/data').data;
|
14 |
|
15 | vows.describe('nconf').addBatch({
|
16 | "When using the nconf": {
|
17 | "should have the correct methods set": function () {
|
18 | assert.isFunction(nconf.key);
|
19 | assert.isFunction(nconf.path);
|
20 | assert.isFunction(nconf.use);
|
21 | assert.isFunction(nconf.get);
|
22 | assert.isFunction(nconf.set);
|
23 | assert.isFunction(nconf.clear);
|
24 | assert.isFunction(nconf.load);
|
25 | assert.isFunction(nconf.save);
|
26 | assert.isFunction(nconf.reset);
|
27 | },
|
28 | "the use() method": {
|
29 | "should instaniate the correct store": function () {
|
30 | nconf.use('memory');
|
31 | assert.instanceOf(nconf.memory, nconf.stores.Memory);
|
32 | }
|
33 | },
|
34 | "it should": {
|
35 | topic: function () {
|
36 | fs.readFile(path.join(__dirname, '..', 'package.json'), this.callback);
|
37 | },
|
38 | "have the correct version set": function (err, data) {
|
39 | assert.isNull(err);
|
40 | data = JSON.parse(data.toString());
|
41 | assert.equal(nconf.version, data.version);
|
42 | }
|
43 | }
|
44 | }
|
45 | }).addBatch({
|
46 | "When using the nconf": {
|
47 | "with the memory store": {
|
48 | "the set() method": {
|
49 | "should respond with true": function () {
|
50 | assert.isTrue(nconf.set('foo:bar:bazz', 'buzz'));
|
51 | }
|
52 | },
|
53 | "the get() method": {
|
54 | "without a callback": {
|
55 | "should respond with the correct value": function () {
|
56 | assert.equal(nconf.get('foo:bar:bazz'), 'buzz');
|
57 | }
|
58 | },
|
59 | "with a callback": {
|
60 | topic: function () {
|
61 | nconf.get('foo:bar:bazz', this.callback);
|
62 | },
|
63 | "should respond with the correct value": function (err, value) {
|
64 | assert.equal(value, 'buzz');
|
65 | }
|
66 | }
|
67 | }
|
68 | }
|
69 | }
|
70 | }).addBatch({
|
71 | "When using nconf": {
|
72 | "with the memory store": {
|
73 | "the clear() method": {
|
74 | "should respond with the true": function () {
|
75 | assert.equal(nconf.get('foo:bar:bazz'), 'buzz');
|
76 | assert.isTrue(nconf.clear('foo:bar:bazz'));
|
77 | assert.isTrue(typeof nconf.get('foo:bar:bazz') === 'undefined');
|
78 | }
|
79 | },
|
80 | "the load() method": {
|
81 | "without a callback": {
|
82 | "should throw an exception": function () {
|
83 | assert.throws(function () { nconf.load() });
|
84 | }
|
85 | },
|
86 | "with a callback": {
|
87 | topic: function () {
|
88 | nconf.load(this.callback.bind(null, null));
|
89 | },
|
90 | "should respond with an error": function (ign, err) {
|
91 | assert.isNotNull(err);
|
92 | }
|
93 | }
|
94 | },
|
95 | "the save() method": {
|
96 | "without a callback": {
|
97 | "should throw an exception": function () {
|
98 | assert.throws(function () { nconf.save() });
|
99 | }
|
100 | },
|
101 | "with a callback": {
|
102 | topic: function () {
|
103 | nconf.save(this.callback.bind(null, null));
|
104 | },
|
105 | "should respond with an error": function (ign, err) {
|
106 | assert.isNotNull(err);
|
107 | }
|
108 | }
|
109 | }
|
110 | }
|
111 | }
|
112 | }).export(module); |
\ | No newline at end of file |