Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
use mockery instead of call mojito start directly
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichun Zhan committed Jan 23, 2013
1 parent 7d05ba3 commit 77c7b25
Showing 1 changed file with 44 additions and 48 deletions.
92 changes: 44 additions & 48 deletions tests/unit/lib/app/commands/test-start.js
Expand Up @@ -7,89 +7,85 @@
/*jslint anon:true, sloppy:true, nomen:true, stupid:true, plusplus:true */
/*globals YUI*/

YUI().use('test', function(Y) {
YUI().use('mojito', 'mojito-test-extra', 'test', function(Y) {

var suite = new Y.Test.Suite('start tests'),
A = Y.Assert,
AA = Y.ArrayAssert,
OA = Y.ObjectAssert,

libpath = require('path'),
cmdpath = libpath.join(__dirname, '../../../../../lib/app/commands/start.js'),
libutils = require(libpath.join(__dirname, '../../../../../lib/management/utils.js')),
start = require(cmdpath);
mojito_src = libpath.resolve(__dirname, '../../../../../lib/mojito'),
mockery = require('mockery'),
mocks,
start,
count;

mocks = {
Mojito: {
createServer: function(options) {
return {
listen: function(port, host, cb) { count++; cb(); }
};
}
}
};

suite.add(new Y.Test.Case({

name: 'start test cases',

setUp: function() {
start = require(cmdpath);
},

'test require': function() {
A.isNotNull(start);
A.isFunction(start.run, 'No run function exported');
A.isString(start.usage, 'No usage string exported');
A.isArray(start.options, 'No options array exported');
}

}));

suite.add(new Y.Test.Case({

name: 'start test cases',

setUp: function() {
mockery.registerAllowable(cmdpath);
mockery.registerMock(mojito_src, mocks.Mojito);
mockery.enable({'warnOnUnregistered': false, useCleanCache: true});
start = require(cmdpath);
count = 0;
},

'test run start': function() {
var mockConsole = Y.Mock();
Y.Mock.expect(mockConsole, {
method: "log",
args: [Y.Mock.Value.String],
run: function (message) {
A.isTrue(/Mojito\(/.test(message));
A.isTrue(/started on http:\/\//.test(message));
}
});
libutils.test.setConsole(mockConsole);
A.areSame(0, count);
start.run([null], null, function() {});
A.areSame(1, count);
},

'test run start port': function() {
var mockConsole = Y.Mock();
Y.Mock.expect(mockConsole, {
method: "log",
args: [Y.Mock.Value.String],
run: function (message) {
A.isTrue(/Mojito\(/.test(message));
A.isTrue(/started on http:\/\//.test(message));
}
});
libutils.test.setConsole(mockConsole);
A.areSame(0, count);
start.run(["8667"], null, function() {});
A.areSame(1, count);
},

'test run start context': function() {
var options = {
context: "environment:production"
},
mockConsole = Y.Mock();
Y.Mock.expect(mockConsole, {
method: "log",
args: [Y.Mock.Value.String],
run: function (message) {
A.isTrue(/Mojito\(/.test(message));
A.isTrue(/started on http:\/\//.test(message));
}
});
libutils.test.setConsole(mockConsole);
};
A.areSame(0, count);
start.run(['8668'], options, function() {});
A.areSame(1, count);
},

'test run start perf': function() {
var options = {
perf: "abc"
},
mockConsole = Y.Mock();
Y.Mock.expect(mockConsole, {
method: "log",
args: [Y.Mock.Value.String],
run: function (message) {
A.isTrue(/Mojito\(/.test(message));
A.isTrue(/started on http:\/\//.test(message));
}
});
libutils.test.setConsole(mockConsole);
};
A.areSame(0, count);
start.run(["8669"], options, function() {});
A.areSame(1, count);
}

}));
Expand Down

0 comments on commit 77c7b25

Please sign in to comment.