From da9ddeb05d19aec1aab25c0f4a466a2668215780 Mon Sep 17 00:00:00 2001 From: Cam Pedersen Date: Mon, 24 Oct 2011 19:50:47 -0400 Subject: [PATCH] testable against a string value --- lib/envious.js | 2 ++ test/default.js | 3 +++ 2 files changed, 5 insertions(+) diff --git a/lib/envious.js b/lib/envious.js index 861ae46..71f9d2c 100644 --- a/lib/envious.js +++ b/lib/envious.js @@ -23,6 +23,7 @@ function envious () { env = process.env.NODE_ENV; if (this[env]) { // environment matched + this[env].__proto__.valueOf = function(){ return env; } return this[env]; } else { // no environment matched @@ -38,6 +39,7 @@ function envious () { throw new Error('envious: no configuration found for default environment `' + this.default_env + '`'); } else if (this.default_env && this[this.default_env]) { // return default + this[this.default_env].__proto__.valueOf = function(){ return env; } return this[this.default_env]; } } diff --git a/test/default.js b/test/default.js index 1df3ac8..79e779c 100644 --- a/test/default.js +++ b/test/default.js @@ -28,6 +28,9 @@ assert.doesNotThrow(function() { envious.apply() }); console.log('test -- variable site_url should match that of the default set'); assert.equal(env.site_url, 'http://127.0.0.1/'); +console.log('test -- testable against a string value matching environment name'); +assert.equal(env, 'development'); + console.log('test -- variable site_url should not match that of the production set'); assert.notEqual(env.site_url, 'http://zombo.com/');