Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Commit

Permalink
Remove optional express arg, use proxyquire instead. Improve test cov…
Browse files Browse the repository at this point in the history
…erage to 100%.
  • Loading branch information
cliffano committed Nov 6, 2014
1 parent 5703e96 commit c8df5e2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
5 changes: 1 addition & 4 deletions lib/ute.js
Expand Up @@ -29,11 +29,8 @@ function Ute(opts) {
* - application port configurable via opts.confDir/<env>.json, default: conf/local.json
*
* @param {Array} handlers: handler functions with reques, response, next arguments
* @param {Object} opts: optional express for testing
*/
Ute.prototype.start = function (handlers, opts) {
opts = opts || {};
express = opts.express || express;
Ute.prototype.start = function (handlers) {

var self = this;
var app = express();
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -32,6 +32,7 @@
},
"devDependencies": {
"buster-node": "~0.7.0",
"proxyquire": "~1.0.1",
"referee": "~1.1.0"
},
"scripts": {},
Expand All @@ -44,4 +45,4 @@
"url": "http://github.com/cliffano/ute/raw/master/LICENSE"
}
]
}
}
47 changes: 25 additions & 22 deletions test/ute.js
@@ -1,12 +1,13 @@
var buster = require('buster-node');
var ejs = require('ejs');
var express = require('express');
var partials = require('express-partials');
var fs = require('fs');
var nconf = require('nconf');
var referee = require('referee');
var Ute = require('../lib/ute');
var assert = referee.assert;
var buster = require('buster-node');
var ejs = require('ejs');
var express = require('express');
var partials = require('express-partials');
var fs = require('fs');
var nconf = require('nconf');
var proxyquire = require('proxyquire');
var referee = require('referee');
var Ute = require('../lib/ute');
var assert = referee.assert;

buster.testCase('ute - ute', {
setUp: function () {
Expand Down Expand Up @@ -42,15 +43,7 @@ buster.testCase('ute - ute', {

buster.testCase('ute - start', {
setUp: function () {
this.mockConsole = this.mock(console);
this.mockFs = this.mock(fs);
this.mockNconf = this.mock(nconf);
},
'should start the application on specified port': function () {

var self = this;

var mockApp = {
this.mockApp = {
use : function () {},
engine: function (ext, type) {
assert.equals(ext, '.html');
Expand All @@ -64,12 +57,22 @@ buster.testCase('ute - start', {
assert.isTrue(handler !== null);
}
};
var self = this;
var mockExpress = function () {
return mockApp;
return self.mockApp;
};
mockExpress.static = function (dir) {
assert.equals(dir, 'somestaticdir');
};
this.Ute = proxyquire('../lib/ute', { express: mockExpress });

this.mockConsole = this.mock(console);
this.mockFs = this.mock(fs);
this.mockNconf = this.mock(nconf);
},
'should start the application on specified port': function () {

var self = this;
var handlers = {
somehandler: function () {}
};
Expand All @@ -81,9 +84,9 @@ buster.testCase('ute - start', {
this.mockFs.expects('readFileSync').withExactArgs('test/fixtures/routes.json')
.returns('[{ "method": "GET", "path": "/foo", "handler": "somehandler" }]');

var ute = new Ute({ confDir: 'test/fixtures', staticDir: 'somestaticdir' });
var app = ute.start(handlers, { express: mockExpress });
var ute = new this.Ute({ confDir: 'test/fixtures', staticDir: 'somestaticdir' });
var app = ute.start(handlers);

assert.equals(app, mockApp);
assert.equals(app, this.mockApp);
}
});

0 comments on commit c8df5e2

Please sign in to comment.