Skip to content

Commit

Permalink
Added test integration for process.env integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Damon Oehlman committed Dec 31, 2012
1 parent 11ea425 commit 012ff87
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
15 changes: 8 additions & 7 deletions index.js
@@ -1,6 +1,7 @@
var data = {},
reObfuscatedUser = /([\w\-]+)\:(\*+)/,
reObfuscatedVariable = /\*{2}([\w\-]+)\*{2}/;
reObfuscatedVariable = /\*{2}([\w\-]+)\*{2}/,
hasOwn = Object.prototype.hasOwnProperty;

function clarity() {
}
Expand All @@ -14,7 +15,7 @@ clarity.clear = function() {
data = {};

return clarity;
}
};

clarity.decode = function(input) {
var matchUser, matchVariable, output, parts;
Expand Down Expand Up @@ -69,27 +70,27 @@ clarity.deepDecode = function(input) {
});

return clone;
}
};

clarity.use = function() {
function extend() {
var dest = {},
sources = Array.prototype.slice.call(arguments),
source = sources.shift();

while (source) {
Object.keys(source).forEach(function(key) {
if (source.hasOwnProperty(key)) {
if (hasOwn.call(source, key)) {
dest[key] = source[key];
}
});

source = sources.shift();
}

return dest;
}

// update the current data with the supplied sources
data = extend.apply(null, [data].concat(Array.prototype.slice.call(arguments)));

Expand Down
13 changes: 13 additions & 0 deletions test/process-env.js
@@ -0,0 +1,13 @@
var assert = require('assert'),
clarity = require('..');

describe('object value replacement - shallow', function() {
before(function() {
clarity.clear();
clarity.use(process.env);
});

it('should be able to replace an common environment variable (USER)', function() {
assert.notEqual(clarity.decode('**USER**'), '**USER**');
});
});

0 comments on commit 012ff87

Please sign in to comment.