Skip to content

Commit

Permalink
Check that tests report errors like they should
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstallard committed Jan 23, 2013
1 parent 50a13b5 commit 4acd17e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 33 deletions.
2 changes: 1 addition & 1 deletion lib/vows/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ this.Context = function (vow, ctx, env) {
if (typeof(e) === 'boolean' && args.length === 0) {
that.emitter.emit.call(that.emitter, 'success', e);
} else {
if (e) { that.emitter.emit.apply(that.emitter, ['error', e].concat(args)) }
if (e) { console.log('hi'); that.emitter.emit.apply(that.emitter, ['error', e].concat(args)) }
else { that.emitter.emit.apply(that.emitter, ['success'].concat(args)) }
}
};
Expand Down
60 changes: 58 additions & 2 deletions test/vows-error-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ var path = require('path'),
events = require('events'),
assert = require('assert'),
fs = require('fs'),
vows = require('../lib/vows');
vows = require('../lib/vows'),
silent = require('../lib/vows/reporters/silent');

function doSomethingAsync(callback) {
var err = null;
Expand Down Expand Up @@ -48,4 +49,59 @@ vows.describe('vows/error').addBatch({
assert.equal(testValue, 'a');
}
}
}).export(module)
}).export(module)

vows.describe('Error Handling').addBatch({
"A topic with a function that errors": {
topic: function() {
throw("Something wrong here");
},
"should return an error to a vow with two parameters": function(e, data) {
assert.equal(e, "Something wrong here");
}
},
"A topic with a built-in error": {
topic: function() {
bad.bad;
},
"should return an error to a vow with two parameters": function(e, data) {
assert(e instanceof Error, "Return value " + e + " wasn't an Error.");
}
},
"The previous two topics run in their own suite," : {
"connected to two vows expecting one argument each" : {
topic: function(){
vows.describe().addBatch({
"A topic with a function that errors": {
topic: function() {
throw("Something wrong here");
},
"should record the error in the test results" : function(data) {
assert.ok(!data);
}
//» An unexpected error was caught: "Something wrong here"
},
"A topic with a built-in error": {
topic: function() {
bad.bad;
},
"should record the error in the test results" : function(data) {
assert.ok(!data);
}
//» An unexpected error was caught: ReferenceError: bad is not defined
}
}).run({reporter : silent}, this.callback);
},
"should have an errored count of two" : function(results, unused) {
assert.equal(results.errored, 2);
},
"should have a total count of two" : function(results, unused) {
assert.equal(results.total, 2);
},
"should have an honored count of zero" : function(results, unused){
assert.equal(results.honored, 0);
}
}
}
}).export(module);

30 changes: 0 additions & 30 deletions test/vows-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,36 +171,6 @@ vows.describe("Vows").addBatch({
}
}
},
"A topic with a function that errors": {
topic: function() {
throw("Something wrong here");
},
"should return an error to a vow with two parameters": function(e, data) {
assert.equal(e, "Something wrong here");
}
// TODO: make a test that runs a vows suite and check the error count
//,
// "and record the error in the test results otherwise" : function(data) {
// assert.ok(!data);
// }
//✗ and record the error in the test results otherwise
// » An unexpected error was caught: "Something wrong here"
},
"A topic with a built-in error": {
topic: function() {
bad.bad;
},
"should return an error to a vow with two parameters": function(e, data) {
assert(e instanceof Error, "Return value " + e + " wasn't an Error.");
}
// TODO: make a test that runs a vows suite and check the error count
//,
// "and record the error in the test results otherwise" : function(data) {
// assert.ok(!data);
// }
//✗ and record the error in the test results otherwise
// » An unexpected error was caught: ReferenceError: bad is not defined
},
"A topic emitting an error": {
topic: function () {
var promise = new(events.EventEmitter);
Expand Down

0 comments on commit 4acd17e

Please sign in to comment.