Permalink
Browse files

Refactored issue tests to use vows

  • Loading branch information...
1 parent 6c97e07 commit bf30236e9f1646eadc73150b3a7d020e936e02cc @ixti ixti committed Dec 16, 2011
Showing with 112 additions and 64 deletions.
  1. +7 −9 Makefile
  2. +36 −0 test/helper.js
  3. +3 −0 test/issues-test.js
  4. +12 −10 test/issues/issue-17.js
  5. +14 −12 test/issues/issue-19.js
  6. +12 −10 test/issues/issue-26.js
  7. +13 −11 test/issues/issue-8.js
  8. +15 −11 test/issues/issue-9.js
  9. +0 −1 test/issues/run.js
View
@@ -25,7 +25,13 @@ lint:
# (white) -> tolerate messy whitespace
jslint --node --nomen --bitwise --white --indent=2 ${JS_FILES}
-test: lint test-issues test-functional
+test: lint test-functional
+ @if test ! `which vows` ; then \
+ echo "You need 'vows' installed in order to run tests." >&2 ; \
+ echo " $ make dev-deps" >&2 ; \
+ exit 128 ; \
+ fi
+ NODE_ENV=test vows --spec
test-functional:
echo
@@ -35,14 +41,6 @@ test-functional:
node ./test/functional/run.js
echo
-test-issues:
- echo
- echo "## ISSUES ######################################################################"
- echo "################################################################################"
- echo
- node ./test/issues/run.js
- echo
-
dev-deps:
@if test ! `which npm` ; then \
echo "You need 'npm' installed." >&2 ; \
View
@@ -0,0 +1,36 @@
+var Vows = require('vows');
+var Assert = require('assert');
+var Path = require('path');
+var Fs = require('fs');
+
+
+var Helper = module.exports = {};
+
+
+Helper.suite = function suite(name, dirname, regexp) {
+ var suite = Vows.describe(name);
+
+ Fs.readdirSync(dirname).forEach(function (filename) {
+ var file = Path.join(dirname, filename);
+
+ if (Fs.statSync(file).isFile() && regexp.test(filename)) {
+ suite.addBatch(require(file));
+ }
+ });
+
+ return suite;
+};
+
+
+Helper.issue = function issue(desc) {
+ var batch = {};
+
+ batch[desc.title] = function () {
+ desc.test();
+ if (!desc.fixed) {
+ throw {message: "Test passed, but it shouldn't!"};
+ }
+ };
+
+ return batch;
+};
View
@@ -0,0 +1,3 @@
+require(__dirname + '/helper')
+ .suite('Issues', __dirname + '/issues', /^issue-\d+\.js$/)
+ .export(module);
View
@@ -1,11 +1,13 @@
-var issue = module.exports = {},
- assert = require('assert'),
- jsyaml = require(__dirname + '/../../lib/js-yaml'),
- source = __dirname + '/data/issue-17.yml';
+var Assert = require('assert');
+var JsYaml = require('../../lib/js-yaml');
+var source = __dirname + '/data/issue-17.yml';
-issue.title = "#17: Non-specific `!` tags should resolve to !!str";
-issue.fixed = true;
-issue.execute = function () {
- var str = require(source).shift();
- assert.equal('string', typeof str);
-};
+
+module.exports = require('../helper').issue({
+ title: "#17: Non-specific `!` tags should resolve to !!str",
+ fixed: true,
+ test: function () {
+ var str = require(source).shift();
+ Assert.equal('string', typeof str);
+ }
+});
View
@@ -1,13 +1,15 @@
-var issue = module.exports = {},
- assert = require('assert'),
- jsyaml = require(__dirname + '/../../lib/js-yaml'),
- source = __dirname + '/data/issue-19.yml';
+var Assert = require('assert');
+var JsYaml = require('../../lib/js-yaml');
+var source = __dirname + '/data/issue-19.yml';
-issue.title = "#19: Timestamp parsing is one month off";
-issue.fixed = true;
-issue.execute = function () {
- var doc = require(source).shift(),
- expected = new Date(2011, 11, 24);
- // JS month starts with 0 (0 => Jan, 1 => Feb, ...)
- assert.equal(doc.xmas.getTime(), expected.getTime());
-};
+
+module.exports = require('../helper').issue({
+ title: "#19: Timestamp parsing is one month off",
+ fixed: true,
+ test: function () {
+ var doc = require(source).shift(), expected = new Date(2011, 11, 24);
+
+ // JS month starts with 0 (0 => Jan, 1 => Feb, ...)
+ Assert.equal(doc.xmas.getTime(), expected.getTime());
+ }
+});
View
@@ -1,11 +1,13 @@
-var issue = module.exports = {},
- assert = require('assert'),
- jsyaml = require(__dirname + '/../../lib/js-yaml'),
- source = __dirname + '/data/issue-26.yml';
+var Assert = require('assert');
+var JsYaml = require('../../lib/js-yaml');
+var source = __dirname + '/data/issue-26.yml';
-issue.title = "#26: should convert new line into white space";
-issue.fixed = true;
-issue.execute = function () {
- var doc = require(source).shift();
- assert.equal(doc.test, 'a b c\n');
-};
+
+module.exports = require('../helper').issue({
+ title: "#26: should convert new line into white space",
+ fixed: true,
+ test: function () {
+ var doc = require(source).shift();
+ Assert.equal(doc.test, 'a b c\n');
+ }
+});
View
@@ -1,12 +1,14 @@
-var issue = module.exports = {},
- assert = require('assert'),
- jsyaml = require(__dirname + '/../../lib/js-yaml'),
- source = __dirname + '/data/issue-8.yml';
+var Assert = require('assert');
+var JsYaml = require('../../lib/js-yaml');
+var source = __dirname + '/data/issue-8.yml';
-issue.title = "#8: Parse failed when no document start present";
-issue.fixed = true;
-issue.execute = function () {
- assert.doesNotThrow(function () {
- require(source).shift();
- }, TypeError);
-};
+
+module.exports = require('../helper').issue({
+ title: "#8: Parse failed when no document start present",
+ fixed: true,
+ test: function () {
+ Assert.doesNotThrow(function () {
+ require(source).shift();
+ }, TypeError);
+ }
+});
View
@@ -1,13 +1,17 @@
-var issue = module.exports = {},
- jsyaml = require(__dirname + '/../../lib/js-yaml'),
- source = __dirname + '/data/issue-9.yml';
+var Assert = require('assert');
+var JsYaml = require('../../lib/js-yaml');
+var source = __dirname + '/data/issue-9.yml';
-issue.title = "#9: Reader fails on File Resource stream, when file is less than 4KB";
-issue.fixed = true;
-issue.execute = function () {
- var fs = require('fs'),
- fd = fs.openSync(source, 'r');
- jsyaml.load(fd);
- fs.closeSync(fd);
-};
+module.exports = require('../helper').issue({
+ title: "#9: Reader fails on File Resource stream, when file is less than 4KB",
+ fixed: true,
+ test: function () {
+ Assert.doesNotThrow(function () {
+ var fs = require('fs'), fd = fs.openSync(source, 'r');
+
+ JsYaml.load(fd);
+ fs.closeSync(fd);
+ }, Error);
+ }
+});
View
@@ -1 +0,0 @@
-require(__dirname + '/../test-helper').run(__dirname, /^issue-.+\.js$/);

0 comments on commit bf30236

Please sign in to comment.