name-test.js 2.1 KB

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