macros.js
1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* macros.js: Test macros for prompt.
*
* (C) 2010, Nodejitsu Inc.
*
*/
var assert = require('assert'),
helpers = require('./helpers'),
prompt = require('../lib/prompt');
exports.shouldConfirm = function (options, mixin) {
var message = options.response.toString().replace(/\n/g, ''),
messages = ["When using prompt", "the confirm() method"],
context = {},
last = context;
messages = messages.concat(options.messages || []);
while (messages.length) {
var text = messages.shift();
last[text] = {};
last = last[text];
}
last['responding with ' + message] = {
topic: function () {
if(!mixin)
prompt.confirm(options.prop, this.callback);
else
prompt.confirm(options.prop, mixin, this.callback);
if (!Array.isArray(options.response)) {
helpers.stdin.writeNextTick(options.response + '\n');
}
else {
helpers.stdin.writeSequence(options.response);
}
},
"should respond with true" : function(err, result) {
assert.isNull(err);
assert.isTrue(result);
}
}
return context;
};
exports.shouldNotConfirm = function (options) {
var message = options.response.toString().replace(/\n/g, ''),
messages = ["When using prompt", "the confirm() method"],
context = {},
last = context;
messages = messages.concat(options.messages || []);
while (messages.length) {
var text = messages.shift();
last[text] = {};
last = last[text];
}
last['responding with ' + message] = {
topic: function () {
prompt.confirm(options.prop, this.callback);
if (!Array.isArray(options.response)) {
helpers.stdin.writeNextTick(options.response + '\n');
}
else {
helpers.stdin.writeSequence(options.response);
}
},
"should respond with false" : function(err, result) {
assert.isNull(err);
assert.isFalse(result);
}
};
return context;
};