Permalink
Browse files

Check that tests report errors like they should

  • Loading branch information...
adamstallard committed Jan 23, 2013
1 parent 50a13b5 commit 4acd17eaf28f05f41bc747ce29d472663066148f
Showing with 59 additions and 33 deletions.
  1. +1 −1 lib/vows/context.js
  2. +58 −2 test/vows-error-test.js
  3. +0 −30 test/vows-test.js
View
@@ -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)) }
}
};
View
@@ -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;
@@ -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);
+
View
@@ -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);

0 comments on commit 4acd17e

Please sign in to comment.