Initial commit
[yaffs-website] / node_modules / tmp / test / name-test.js
1 var
2   vows   = require('vows'),
3   assert = require('assert'),
4
5   path   = require('path'),
6
7   tmp    = require('../lib/tmp.js'),
8   Test   = require('./base.js');
9
10 vows.describe('Name creation').addBatch({
11   'when using without parameters': {
12     topic: function () {
13       tmp.tmpName(this.callback);
14     },
15
16     'should not return with error': assert.isNull,
17     'should have the default prefix': Test.testPrefix('tmp-')
18   },
19
20   'when using with prefix': {
21     topic: function () {
22       tmp.tmpName({ prefix: 'something' }, this.callback);
23     },
24
25     'should not return with error': assert.isNull,
26     'should have the provided prefix': Test.testPrefix('something')
27   },
28
29   'when using with postfix': {
30     topic: function () {
31       tmp.tmpName({ postfix: '.txt' }, this.callback);
32     },
33
34     'should not return with error': assert.isNull,
35     'should have the provided postfix': Test.testPostfix('.txt')
36
37   },
38
39   'when using template': {
40     topic: function () {
41       tmp.tmpName({ template: path.join(tmp.tmpdir, 'clike-XXXXXX-postfix') }, this.callback);
42     },
43
44     'should not return with error': assert.isNull,
45     'should have the provided prefix': Test.testPrefix('clike-'),
46     'should have the provided postfix': Test.testPostfix('-postfix'),
47     'should have template filled': function (err, name) {
48       assert.isTrue(/[a-zA-Z0-9]{6}/.test(name));
49     }
50   },
51
52   'when using multiple options': {
53     topic: function () {
54       tmp.tmpName({ prefix: 'foo', postfix: 'bar', tries: 5 }, this.callback);
55     },
56
57     'should not return with error': assert.isNull,
58     'should have the provided prefix': Test.testPrefix('foo'),
59     'should have the provided postfix': Test.testPostfix('bar')
60   },
61
62   'no tries': {
63     topic: function () {
64       tmp.tmpName({ tries: -1 }, this.callback);
65     },
66
67     'should fail': function (err, name) {
68       assert.isObject(err);
69     }
70   },
71
72   'tries not numeric': {
73     topic: function () {
74       tmp.tmpName({ tries: 'hello'}, this.callback);
75     },
76
77     'should fail': function (err, name) {
78       assert.isObject(err);
79     }
80   }
81
82 }).exportTo(module);