Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use mocha for testing

  • Loading branch information...
commit b942854987d4a724bfafc26a5d88da2adaee36d8 1 parent 6aa8baf
@mjackson authored
Showing with 125 additions and 106 deletions.
  1. +2 −2 package.json
  2. +111 −92 test/user-error-test.js
  3. +12 −12 user-error.js
View
4 package.json
@@ -9,13 +9,13 @@
},
"main": "./user-error.js",
"scripts": {
- "test": "vows test/user-error-test.js"
+ "test": "mocha"
},
"engines": {
"node": ">=0.4.7"
},
"dependencies": {},
"devDependencies": {
- "vows": "~0.5.9"
+ "mocha": "1.5.0"
}
}
View
203 test/user-error-test.js
@@ -1,94 +1,113 @@
-var assert = require("assert");
-var util = require("util");
-var vows = require("vows");
-var UserError = require("../user-error");
+var assert = require('assert');
+var util = require('util');
+var vows = require('vows');
+var UserError = require('../user-error');
-function MyError(message, cause) {
- message = message || "Boom!";
+describe('A UserError', function () {
+ describe('without a cause', function () {
+ var message, err;
+ beforeEach(function () {
+ message = 'Bang!';
+ err = new UserError(message);
+ });
+
+ it('knows its name', function () {
+ assert.equal('UserError', err.name);
+ });
+
+ it('knows its message', function () {
+ assert.equal(err.message, message);
+ });
+
+ it('does not have a cause', function () {
+ assert.ok(typeof err.cause === 'undefined');
+ });
+
+ it('has a fullStack property', function () {
+ assert.ok(typeof err.fullStack === 'string');
+ });
+ });
+
+ describe('with a cause', function () {
+ var cause, message, err;
+ beforeEach(function () {
+ cause = new UserError;
+ message = 'Another bang!';
+ err = new UserError(message, cause);
+ });
+
+ it('knows its name', function () {
+ assert.equal('UserError', err.name);
+ });
+
+ it('knows its message', function () {
+ assert.equal(err.message, message);
+ });
+
+ it('has a cause', function () {
+ assert.ok(err.cause);
+ });
+
+ it('has a fullStack property', function () {
+ assert.ok(typeof err.fullStack === 'string');
+ })
+ });
+});
+
+describe('A UserError subclass instance', function () {
+ function MyError(message, cause) {
+ message = message || 'Boom!';
UserError.call(this, message, cause);
-}
-
-util.inherits(MyError, UserError);
-
-vows.describe("UserError").addBatch({
- "A UserError": {
- topic: function () {
- this.message = "Bang!";
- var err = new UserError(this.message);
- return err;
- },
- "without a cause": {
- "should know its name": function (e, err) {
- assert.equal("UserError", err.name);
- },
- "should know its message": function (e, err) {
- assert.equal(err.message, this.message);
- },
- "should not have a cause": function (e, err) {
- assert.isUndefined(err.cause);
- },
- "should have a fullStack property": function (e, err) {
- assert.ok(typeof err.fullStack == "string");
- }
- },
- "with a cause": {
- topic: function (cause) {
- this.message = "Another bang!";
- var err = new UserError(this.message, cause);
- return err;
- },
- "should know its name": function (e, err) {
- assert.equal("UserError", err.name);
- },
- "should know its message": function (e, err) {
- assert.equal(err.message, this.message);
- },
- "should have a cause": function (e, err) {
- assert.ok(err.cause);
- },
- "should have a fullStack property": function (e, err) {
- assert.ok(typeof err.fullStack == "string");
- }
- }
- },
- "A UserError subclass instance": {
- topic: function () {
- this.message = "Boom!";
- var err = new MyError(this.message);
- return err;
- },
- "without a cause": {
- "should know its name": function (e, err) {
- assert.equal("MyError", err.name);
- },
- "should know its message": function (e, err) {
- assert.equal(err.message, this.message);
- },
- "should not have a cause": function (e, err) {
- assert.isUndefined(err.cause);
- },
- "should have a fullStack property": function (e, err) {
- assert.ok(typeof err.fullStack == "string");
- }
- },
- "with a cause": {
- topic: function (cause) {
- this.message = "Another boom!";
- var err = new MyError(this.message, cause);
- return err;
- },
- "should know its name": function (e, err) {
- assert.equal("MyError", err.name);
- },
- "should know its message": function (e, err) {
- assert.equal(err.message, this.message);
- },
- "should have a cause": function (e, err) {
- assert.ok(err.cause);
- },
- "should have a fullStack property": function (e, err) {
- assert.ok(typeof err.fullStack == "string");
- }
- }
- }
-}).export(module);
+ }
+
+ util.inherits(MyError, UserError);
+
+ describe('without a cause', function () {
+ var message, err;
+ beforeEach(function () {
+ message = 'Boom!';
+ err = new MyError(message);
+ });
+
+ it('knows its name', function () {
+ assert.equal('MyError', err.name);
+ });
+
+ it('knows its message', function () {
+ assert.equal(err.message, message);
+ });
+
+ it('does not have a cause', function () {
+ assert.ok(typeof err.cause === 'undefined');
+ });
+
+ it('has a fullStack property', function () {
+ assert.ok(typeof err.fullStack === 'string');
+ });
+ });
+
+ describe('with a cause', function () {
+ var cause, message, err;
+ beforeEach(function () {
+ cause = new UserError;
+ message = 'Another boom!';
+ err = new MyError(message, cause);
+ });
+
+ it('knows its name', function () {
+ assert.equal('MyError', err.name);
+ });
+
+ it('knows its message', function () {
+ assert.equal(err.message, message);
+ });
+
+ it('has a cause', function () {
+ assert.ok(err.cause);
+ });
+
+ it('has a fullStack property', function () {
+ assert.ok(typeof err.fullStack === 'string');
+ });
+ });
+});
View
24 user-error.js
@@ -1,4 +1,4 @@
-var util = require("util");
+var util = require('util');
module.exports = UserError;
@@ -9,21 +9,21 @@ module.exports = UserError;
* lower level.
*/
function UserError(message, cause) {
- Error.call(this);
- Error.captureStackTrace(this, this.constructor);
- this.name = this.constructor.name;
- this.message = message;
- this.cause = cause;
+ Error.call(this);
+ Error.captureStackTrace(this, this.constructor);
+ this.name = this.constructor.name;
+ this.message = message;
+ this.cause = cause;
}
util.inherits(UserError, Error);
-UserError.prototype.__defineGetter__("fullStack", function fullStack() {
- var stack = this.stack;
+UserError.prototype.__defineGetter__('fullStack', function () {
+ var stack = this.stack;
- if (this.cause) {
- stack += "\nCaused by " + (this.cause.fullStack || this.cause.stack);
- }
+ if (this.cause) {
+ stack += '\nCaused by ' + (this.cause.fullStack || this.cause.stack);
+ }
- return stack;
+ return stack;
});
Please sign in to comment.
Something went wrong with that request. Please try again.