Skip to content

Commit

Permalink
cleaned up project structure a little
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudhead committed Jun 1, 2010
1 parent fb7d8a9 commit 14278d0
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 54 deletions.
25 changes: 25 additions & 0 deletions lib/assert/error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var stylize = require('vows/console').stylize;
var inspect = require('vows').inspect;

require('assert').AssertionError.prototype.toString = function () {
var that = this,
source = this.stack.match(/([a-zA-Z0-9_-]+\.js)(:\d+):\d+/);

function parse(str) {
return str.replace(/{actual}/g, inspect(that.actual)).
replace(/{expected}/g, inspect(that.expected)).
replace(/{operator}/g, stylize(that.operator, 'bold'));
}

if (this.message) {
return stylize(parse(this.message), 'yellow') +
stylize(' // ' + source[1] + source[2], 'grey');
} else {
return stylize([
this.expected,
this.operator,
this.actual
].join(' '), 'yellow');
}
};

File renamed without changes.
67 changes: 13 additions & 54 deletions lib/vows.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
//
var path = require('path');

require.paths.unshift(__dirname);

var sys = require('sys'),
assert = require('assert'),
events = require('events'),
eyes = require('eyes').inspector({ stream: null }),
vows = exports;

require.paths.unshift(__dirname);

// Options
vows.options = {
Emitter: events.EventEmitter,
Expand Down Expand Up @@ -82,32 +81,20 @@ for (var i = 0, arg; i < process.argv.length; i++) {
// ('node' in most cases)
argv = argv.slice(1);

vows.inspect = function inspect(val) {
return '\033[1m' + eyes(val) + '\033[22m';
};

//
// Assertion Macros
// Assertion Macros & Extensions
//
vows.macros = require('vows/macros');

assert.AssertionError.prototype.toString = function () {
var that = this,
source = this.stack.match(/([a-zA-Z0-9_-]+\.js)(:\d+):\d+/);

function parse(str) {
return str.replace(/{actual}/g, inspect(that.actual)).
replace(/{expected}/g, inspect(that.expected)).
replace(/{operator}/g, stylize(that.operator, 'bold'));
}
require('./assert/error');
require('./assert/macros');

if (this.message) {
return stylize(parse(this.message), 'yellow') +
stylize(' // ' + source[1] + source[2], 'grey');
} else {
return stylize([
this.expected,
this.operator,
this.actual
].join(' '), 'yellow');
}
}
//
// Context constructor
//
var Context = require('vows/context').Context;

//
// This function gets added to events.EventEmitter.prototype, by default.
Expand Down Expand Up @@ -194,26 +181,6 @@ function addVow(/* description & callback */) {
}
};

function Context(vow, ctx, env) {
var that = this;

this.tests = vow.callback;
this.topics = (ctx.topics || []).slice(0);
this.emitter = null;
this.env = env || {};
this.env.context = this;
this.env.__defineGetter__('callback', function () {
that._callback = true;
return function (e, res) {
var args = Array.prototype.slice.call(arguments, 1);
if (e) { that.emitter.emit('error', e) }
else { that.emitter.emit.apply(that.emitter, ['success'].concat(args)) }
};
});
this.name = (ctx.name ? ctx.name + ' ' : '') +
(vow.description || '');
}

function addVows(tests) {
var promise = new(events.EventEmitter);
var remaining = 0;
Expand Down Expand Up @@ -467,11 +434,3 @@ vows.config = function (opts) {
return this;
};

//
// Utility functions
//

function inspect(val) {
return '\033[1m' + eyes(val) + '\033[22m';
}

21 changes: 21 additions & 0 deletions lib/vows/context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

this.Context = function (vow, ctx, env) {
var that = this;

this.tests = vow.callback;
this.topics = (ctx.topics || []).slice(0);
this.emitter = null;
this.env = env || {};
this.env.context = this;
this.env.__defineGetter__('callback', function () {
that._callback = true;
return function (e, res) {
var args = Array.prototype.slice.call(arguments, 1);
if (e) { that.emitter.emit('error', e) }
else { that.emitter.emit.apply(that.emitter, ['success'].concat(args)) }
};
});
this.name = (ctx.name ? ctx.name + ' ' : '') +
(vow.description || '');
};

0 comments on commit 14278d0

Please sign in to comment.