Skip to content

Commit

Permalink
[test refactor] test/{helpers.js => helpers/macros.js}
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalecki committed Dec 9, 2011
1 parent ce7d5a1 commit 1d1656c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
20 changes: 10 additions & 10 deletions test/cli-test.js
Expand Up @@ -10,7 +10,7 @@ var fs = require('fs'),
path = require('path'),
assert = require('assert'),
vows = require('vows'),
helpers = require('./helpers'),
macros = require('./helpers/macros'),
rimraf = require('utile').rimraf,
forever = require('../lib/forever');

Expand All @@ -23,16 +23,16 @@ vows.describe('forever/cli').addBatch({
topic: function () {
rimraf(path.join(process.env.HOME, '.forever', 'sock'), this.callback);
},
'and starting script using `forever start`': helpers.spawn(['start', script], {
'`forever.list` result': helpers.list({
'and starting script using `forever start`': macros.spawn(['start', script], {
'`forever.list` result': macros.list({
'should contain spawned process': function (list) {
helpers.assertList(list);
macros.assertList(list);
assert.equal(list[0].command, 'node');
assert.equal(fs.realpathSync(list[0].file), fs.realpathSync(script));
helpers.assertStartsWith(list[0].logFile, forever.config.get('root'));
macros.assertStartsWith(list[0].logFile, forever.config.get('root'));
},
'and stopping it using `forever stop`': helpers.spawn(['stop', script], {
'`forever.list` result': helpers.list({
'and stopping it using `forever stop`': macros.spawn(['stop', script], {
'`forever.list` result': macros.list({
'should not contain previous process': function (list) {
assert.isNull(list);
}
Expand All @@ -44,10 +44,10 @@ vows.describe('forever/cli').addBatch({
}
}).addBatch({
'When using forever CLI': {
'and starting script using `forever start` with arguments': helpers.spawn(['start', script].concat(options), {
'`forever.list` result': helpers.list({
'and starting script using `forever start` with arguments': macros.spawn(['start', script].concat(options), {
'`forever.list` result': macros.list({
'should contain spawned process with proper options': function (list) {
helpers.assertList(list);
macros.assertList(list);
assert.notEqual(list[0].uid, 'itShouldNotGoToUIDField');
assert.deepEqual(list[0].options, options);
}
Expand Down
3 changes: 1 addition & 2 deletions test/env-spawn-test.js
Expand Up @@ -9,8 +9,7 @@
var assert = require('assert'),
path = require('path'),
vows = require('vows'),
forever = require('../lib/forever'),
helpers = require('./helpers');
forever = require('../lib/forever');

vows.describe('forever/spawn-options').addBatch({
"When using forever": {
Expand Down
6 changes: 3 additions & 3 deletions test/forever-test.js
Expand Up @@ -10,7 +10,7 @@ var assert = require('assert'),
path = require('path'),
vows = require('vows'),
forever = require('../lib/forever'),
helpers = require('./helpers');
macros = require('./helpers/macros');

vows.describe('forever').addBatch({
"When using forever": {
Expand Down Expand Up @@ -43,7 +43,7 @@ vows.describe('forever').addBatch({
}
}
},
"running error-on-timer sample three times": helpers.assertTimes(
"running error-on-timer sample three times": macros.assertTimes(
path.join(__dirname, '..', 'examples', 'error-on-timer.js'),
3,
{
Expand All @@ -54,7 +54,7 @@ vows.describe('forever').addBatch({
options: []
}
),
"running error-on-timer sample once": helpers.assertTimes(
"running error-on-timer sample once": macros.assertTimes(
path.join(__dirname, '..', 'examples', 'error-on-timer.js'),
1,
{
Expand Down
19 changes: 10 additions & 9 deletions test/helpers.js → test/helpers/macros.js
@@ -1,5 +1,5 @@
/*
* helpers.js: Test helpers for the forever module
* macros.js: Test macros for the forever module
*
* (C) 2010 Nodejitsu Inc.
* MIT LICENCE
Expand All @@ -9,11 +9,11 @@
var assert = require('assert'),
path = require('path'),
spawn = require('child_process').spawn,
forever = require('../lib/forever');
forever = require('../../lib/forever');

var helpers = exports;
var macros = exports;

helpers.assertTimes = function (script, times, options) {
macros.assertTimes = function (script, times, options) {
options.max = times;

return {
Expand All @@ -28,7 +28,7 @@ helpers.assertTimes = function (script, times, options) {
}
};

helpers.spawn = function (args, options) {
macros.spawn = function (args, options) {
options.topic = function () {
var self = this;

Expand Down Expand Up @@ -57,18 +57,19 @@ helpers.spawn = function (args, options) {
return options;
};

helpers.list = function (options) {
macros.list = function (options) {
options.topic = function () {
forever.list(false, this.callback)
};
return options;
};

helpers.assertStartsWith = function (string, substring) {
macros.assertStartsWith = function (string, substring) {
assert.equal(string.slice(0, substring.length), substring);
};

helpers.assertList = function (list) {
macros.assertList = function (list) {
assert.isNotNull(list);
assert.lengthOf(list, 1);
};
};

3 changes: 1 addition & 2 deletions test/tail-test.js
Expand Up @@ -10,8 +10,7 @@ var assert = require('assert'),
path = require('path'),
spawn = require('child_process').spawn,
vows = require('vows'),
forever = require('../lib/forever'),
helpers = require('./helpers');
forever = require('../lib/forever');

vows.describe('forever/tail').addBatch({
"When using forever": {
Expand Down

0 comments on commit 1d1656c

Please sign in to comment.