name-test.js
2.05 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
var
vows = require('vows'),
assert = require('assert'),
path = require('path'),
tmp = require('../lib/tmp.js'),
Test = require('./base.js');
vows.describe('Name creation').addBatch({
'when using without parameters': {
topic: function () {
tmp.tmpName(this.callback);
},
'should not return with error': assert.isNull,
'should have the default prefix': Test.testPrefix('tmp-')
},
'when using with prefix': {
topic: function () {
tmp.tmpName({ prefix: 'something' }, this.callback);
},
'should not return with error': assert.isNull,
'should have the provided prefix': Test.testPrefix('something')
},
'when using with postfix': {
topic: function () {
tmp.tmpName({ postfix: '.txt' }, this.callback);
},
'should not return with error': assert.isNull,
'should have the provided postfix': Test.testPostfix('.txt')
},
'when using template': {
topic: function () {
tmp.tmpName({ template: path.join(tmp.tmpdir, 'clike-XXXXXX-postfix') }, this.callback);
},
'should not return with error': assert.isNull,
'should have the provided prefix': Test.testPrefix('clike-'),
'should have the provided postfix': Test.testPostfix('-postfix'),
'should have template filled': function (err, name) {
assert.isTrue(/[a-zA-Z0-9]{6}/.test(name));
}
},
'when using multiple options': {
topic: function () {
tmp.tmpName({ prefix: 'foo', postfix: 'bar', tries: 5 }, this.callback);
},
'should not return with error': assert.isNull,
'should have the provided prefix': Test.testPrefix('foo'),
'should have the provided postfix': Test.testPostfix('bar')
},
'no tries': {
topic: function () {
tmp.tmpName({ tries: -1 }, this.callback);
},
'should fail': function (err, name) {
assert.isObject(err);
}
},
'tries not numeric': {
topic: function () {
tmp.tmpName({ tries: 'hello'}, this.callback);
},
'should fail': function (err, name) {
assert.isObject(err);
}
}
}).exportTo(module);