2 * utile-test.js: Tests for `utile` module.
4 * (C) 2011, Nodejitsu Inc.
9 var assert = require('assert'),
10 vows = require('vows'),
11 utile = require('../lib');
28 Object.defineProperties(obj2, {
48 vows.describe('utile').addBatch({
50 "it should have the same methods as the `util` module": function () {
51 Object.keys(require('util')).forEach(function (fn) {
52 assert.isFunction(utile[fn]);
55 "it should have the correct methods defined": function () {
56 assert.isFunction(utile.mixin);
57 assert.isFunction(utile.clone);
58 assert.isFunction(utile.rimraf);
59 assert.isFunction(utile.mkdirp);
60 assert.isFunction(utile.cpr);
62 "the mixin() method": function () {
63 var mixed = utile.mixin({}, obj1, obj2);
64 assert.isTrue(mixed.foo);
65 assert.isObject(mixed.bar);
66 assert.isTrue(mixed.baz);
67 assert.isString(mixed.buzz);
68 assert.isTrue(!!Object.getOwnPropertyDescriptor(mixed, 'bazz').get);
69 assert.isTrue(!!Object.getOwnPropertyDescriptor(mixed, 'bazz').set);
70 assert.isTrue(!!Object.getOwnPropertyDescriptor(mixed, 'wat').set);
71 assert.isString(mixed.bazz);
73 "the clone() method": function () {
74 var clone = utile.clone(obj1);
75 assert.isTrue(clone.foo);
76 assert.isObject(clone.bar);
77 assert.notStrictEqual(obj1, clone);
79 "the createPath() method": function () {
83 utile.createPath(x, ['a','b','c'], r)
84 assert.equal(x.a.b.c, r)
86 "the capitalize() method": function () {
87 assert.isFunction(utile.capitalize);
88 assert.equal(utile.capitalize('bullet'), 'Bullet');
89 assert.equal(utile.capitalize('bullet_train'), 'BulletTrain');
91 "the escapeRegExp() method": function () {
92 var ans = "\\/path\\/to\\/resource\\.html\\?search=query";
93 assert.isFunction(utile.escapeRegExp);
94 assert.equal(utile.escapeRegExp('/path/to/resource.html?search=query'), ans);
96 "the underscoreToCamel() method": function () {
97 var obj = utile.underscoreToCamel({
98 key_with_underscore: {
101 nested_underscores: true
103 just_one: 'underscore'
106 assert.isObject(obj.keyWithUnderscore);
107 assert.isString(obj.justOne);
108 assert.isTrue(obj.keyWithUnderscore.nestedUnderscores);
110 "the camelToUnderscore() method": function () {
111 var obj = utile.camelToUnderscore({
120 assert.isObject(obj.key_with_camel);
121 assert.isString(obj.just_one);
122 assert.isTrue(obj.key_with_camel.nested_camel);