Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add test for coffeeconfiguration files

  • Loading branch information...
commit 7ec34ebc4365cf3da5a59576d801f36c7c1c6c55 1 parent cd4d9c6
@mgutz authored
View
6 Makefile
@@ -8,12 +8,12 @@ GEN_JS = $(COFFEE:$(SRC_DIR)/%.coffee=$(BUILD_DIR)/%.js)
.PHONY: all clean
-all: generate
+all: generate
generate: $(GEN_JS)
-test: generate
- @expresso test/settings.test.js
+test: clean generate
+ @expresso test/*.test.js
clean:
@rm -f $(GEN_JS)
View
8 lib/settings.js
@@ -5,11 +5,15 @@
AUTO-GENERATED. DO NOT EDIT.
============================================================================*/
// Original file: src/lib/settings.coffee
-var Settings, assert, coffee, merger;
+var Settings, assert, merger;
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
assert = require('assert');
merger = require('../support/merger');
-coffee = require('coffee-script');
+try {
+ require('coffee-script');
+} catch (ex) {
+
+}
Settings = function(pathOrModule, options) {
this.options = options != null ? options : {};
if (typeof pathOrModule === 'string') {
View
5 package.json
@@ -3,8 +3,5 @@
"description": "Simple environment-based application settings",
"author": "Mario Gutierrez <mario@mgutz.com>",
"main": "index",
- "repository" : "git://github.com/mgutz/node-settings",
- "dependencies": {
- "coffee-script": ">=1.1.1"
- }
+ "repository" : "git://github.com/mgutz/node-settings"
}
View
12 src/lib/settings.coffee
@@ -2,18 +2,22 @@
# Copyright(c) 2010 Mario L Gutierrez <mario@mgutz.com>
# MIT Licensed
#
+# TODO - add watcher on settings file
assert = require('assert')
merger = require('../support/merger')
-coffee = require('coffee-script') # allows use of coffee for configs
-# TODO - add watcher on settings file
+# IF coffee is installed, also read configs written in CoffeeScript.
+try
+ # coffee extension is registered with node as a side-effect
+ require('coffee-script') # allows use of coffee for configs
+catch ex
+
# Provides settings from an environment file or an object.
#
# The settings module must export, at a minimum, a `common` property.
-#
-# Other environments are deep merged into `common`.
+# Other environments are deep merged over `common`.
#
# @param {String | Object} pathOrModule The file to load or an object.
#
View
22 src/test/coffee.test.coffee
@@ -0,0 +1,22 @@
+Settings = require('../lib')
+assert = require('assert')
+
+# read the original coffee file
+_settings = new Settings(__dirname + '/../src/test/config/environment')
+
+# Coffee compiles to javascript. A single test is enough here.
+# Exhaustive tests are performed against javascript configuration files.
+module.exports =
+ "should get specific environment": ->
+ settings = _settings.getEnvironment('development')
+ assert.equal 'server_dev', settings.storage.database
+
+ # default should be 'common'
+ settings = _settings.getEnvironment()
+ assert.equal 'server_dev', settings.storage.database
+
+ settings = _settings.getEnvironment('test')
+ assert.equal 'server_test', settings.storage.database
+
+ settings = _settings.getEnvironment('production')
+ assert.equal 'server_production', settings.storage.database
View
3  src/test/settings.test.coffee
@@ -5,7 +5,6 @@ _settings = new Settings(__dirname + '/config/environment')
module.exports =
-
"should be global installable using custom key": ->
environments =
'common':
@@ -32,7 +31,7 @@ module.exports =
settings = _settings.getEnvironment('development')
assert.equal 'server_dev', settings.storage.database
- # default should be 'development'
+ # default should be 'common'
settings = _settings.getEnvironment()
assert.equal 'server_dev', settings.storage.database
View
24 test/coffee.test.js
@@ -0,0 +1,24 @@
+/*============================================================================
+ Copyright(c) 2010 Mario L Gutierrez <mario@mgutz.com>
+ MIT Licensed
+
+ AUTO-GENERATED. DO NOT EDIT.
+============================================================================*/
+// Original file: src/test/coffee.test.coffee
+var Settings, assert, _settings;
+Settings = require('../lib');
+assert = require('assert');
+_settings = new Settings(__dirname + '/../src/test/config/environment');
+module.exports = {
+ "should get specific environment": function() {
+ var settings;
+ settings = _settings.getEnvironment('development');
+ assert.equal('server_dev', settings.storage.database);
+ settings = _settings.getEnvironment();
+ assert.equal('server_dev', settings.storage.database);
+ settings = _settings.getEnvironment('test');
+ assert.equal('server_test', settings.storage.database);
+ settings = _settings.getEnvironment('production');
+ return assert.equal('server_production', settings.storage.database);
+ }
+};
Please sign in to comment.
Something went wrong with that request. Please try again.