Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[0.4.5] new format for this.t

* changed readme file
* altered static analysis code (simplified it)
  • Loading branch information...
commit d68bcec6d0736098f7bd00262960a9bc4578f5f1 1 parent b56e64b
@dscape authored
Showing with 22 additions and 25 deletions.
  1. +14 −13 README.md
  2. +3 −4 engines/tap.js
  3. +1 −1  package.json
  4. +4 −7 test/tap/tap.js
View
27 README.md
@@ -11,7 +11,6 @@
```js
var ensure = require('ensure')
- , assert = require('assert')
, tests = exports
;
@@ -20,7 +19,7 @@
};
tests.foo_ok = function (t) {
- assert.ok(t);
+ this.t.ok(t);
};
ensure('foo', tests, module);
@@ -38,33 +37,35 @@ an extra parameter is available to allow you to define only some tests from a sp
ensure('foo',tests,module,process.argv[2]);
```
-you can also set `ensure` to use a different test engine. for now we have [tap][4] and [vows][5] available with `vows` by default. here's an example using tap
+you can also set `ensure` to use a different test engine. for now we have [tap][4] and [vows][5] available with `tap` by default. here's an example using vows
```js
- var ensure = require('ensure').use('tap')
- , tests = exports
+ var ensure = require('ensure')
+ , assert = require('assert')
+ , tests = exports
;
- tests.tap = function (cb) { cb('foo'); };
- tests.tap_ok = function (value) {
- var t = this.t; // get the assertions from tap engine
- t.equal(value,'foo','foo test worked');
+ tests.vows = function (cb) { cb('foo'); };
+ tests.vows_ok = function (value) {
+ assert.equal(value,'foo','foo test worked');
};
ensure(__filename,tests,module,process.argv[2]);
```
-to run test `tap` you can do:
+to run test `vows` you can do:
```sh
- node test/tap.js tap
+ node vows.js vows
```
-`tap` is the test name and _is_ optional (by default all tests run).
+`vows` is the test name and _is_ optional (by default all tests run).
+
+*note:* `this.t` should not be placed in a variable. `ensure` uses a very simple static analysis algorithm to determine how many assertions exist in your callback. if you think this is not satisfactory feel free to make a pull request with better static analysis code.
# contribute
-everyone is welcome to contribute. patches, bugfixes, new features
+everyone is welcome to contribute. patches, bug-fixes, new features
1. create an [issue][2] on github so the community can comment on your idea
2. fork `nano` in github
View
7 engines/tap.js
@@ -1,5 +1,5 @@
-var _ = require('underscore')
- , tap = require('tap')
+var _ = require('underscore')
+ , tap = require('tap')
, test = tap.test
, plan = tap.plan
;
@@ -13,8 +13,7 @@ module.exports = exports = function(name,tests,module,selected) {
test(name, function (t) {
test_names.forEach(function(name) { // quick'n'dirty static analysis
var f_body = tests[name+'_ok'].toString()
- , var_name = /(\w)\s*=\s*this\.t/.exec(f_body)[1] + '\\.'
- , count = f_body.match(new RegExp(var_name, ['g', 'm'])).length
+ , count = f_body.match(/this\.t/gm).length
;
total += count;
});
View
2  package.json
@@ -2,7 +2,7 @@
, "description" : "node.js testing made easy"
, "homepage" : "http://github.com/dscape/ensure"
, "repository" : "git://github.com/dscape/ensure"
-, "version" : "0.4.4"
+, "version" : "0.4.5"
, "author" : "Nuno Job <nunojobpinto@gmail.com> (http://nunojob.com)"
, "keywords" : ["vows", "node-tap", "tap", "testing", "tests"]
, "dependencies" :
View
11 test/tap/tap.js
@@ -4,21 +4,18 @@ var ensure = require('../../ensure')
tests.tap = function (cb) { cb('foo'); };
tests.tap_ok = function (value) {
- var t = this.t;
- t.equal(value,'foo','foo works');
+ this.t.equal(value,'foo','foo works');
};
tests.tap2 = function (cb) { cb('foo','bar'); };
tests.tap2_ok = function (foo,bar) {
- var t = this.t;
- t.equal(foo,'foo','foo is foo');
- t.equal(bar,'bar','bar is bar');
+ this.t.equal(foo,'foo','foo is foo');
+ this.t.equal(bar,'bar','bar is bar');
};
tests.plan_works = function (cb) { cb('bar'); };
tests.plan_works_ok = function (value) {
- var t = this.t;
- t.equal(value,'bar','plan tests work');
+ this.t.equal(value,'bar','plan tests work');
};
ensure('tap',tests,module,process.argv[2]);
Please sign in to comment.
Something went wrong with that request. Please try again.