2 vows = require('vows'),
3 assert = require('assert'),
5 path = require('path'),
7 tmp = require('../lib/tmp.js'),
8 Test = require('./base.js');
10 vows.describe('Name creation').addBatch({
11 'when using without parameters': {
13 tmp.tmpName(this.callback);
16 'should not return with error': assert.isNull,
17 'should have the default prefix': Test.testPrefix('tmp-')
20 'when using with prefix': {
22 tmp.tmpName({ prefix: 'something' }, this.callback);
25 'should not return with error': assert.isNull,
26 'should have the provided prefix': Test.testPrefix('something')
29 'when using with postfix': {
31 tmp.tmpName({ postfix: '.txt' }, this.callback);
34 'should not return with error': assert.isNull,
35 'should have the provided postfix': Test.testPostfix('.txt')
39 'when using template': {
41 tmp.tmpName({ template: path.join(tmp.tmpdir, 'clike-XXXXXX-postfix') }, this.callback);
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));
52 'when using multiple options': {
54 tmp.tmpName({ prefix: 'foo', postfix: 'bar', tries: 5 }, this.callback);
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')
64 tmp.tmpName({ tries: -1 }, this.callback);
67 'should fail': function (err, name) {
72 'tries not numeric': {
74 tmp.tmpName({ tries: 'hello'}, this.callback);
77 'should fail': function (err, name) {