Skip to content

Commit

Permalink
Doc, example, hmm.
Browse files Browse the repository at this point in the history
  • Loading branch information
5long committed Nov 3, 2010
1 parent 54dc2fe commit 632541b
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 11 deletions.
50 changes: 41 additions & 9 deletions README.mkd
@@ -1,29 +1,61 @@
# REimplementing Unit Test

Simply another unit test framework for node.js.
Simply another unit test framework for [node.js](http://nodejs.org)

## Design

* QUnit-like API
* Doesn't force you to use a flow control pattern
* But try to support async tests
* Does a little bit magic but not too much
* Keep a \`right' design internally
* Tries to support async tests
* Saves typing
* No scope or object shall be cluttered
* __NO__ huge object literals or 7-level indentation
* Keeps a "right" design internally (which you won't see)

## Features

### Implemented

* Extended assertion method
* Ensure callback's called and event's fired
* Set timeout for tests
* A better-than-nothing command line test runner
* setup support

### Upcoming

* teardown support
* Suite-wise setup/teardown (startup and shutdown would be good names)
* Nested test suites

### (Not So) Near Future

* Colored output, web runner...
* Watch mode?
* Tagged tests and/or suites
* Custom running policy for skipping/picking tests
* Custom test result reporter (after the internal API stablized)
* Any crazy idea(s)

## Installation

By using [npm](http://npmjs.org):

$ npm install reut

Install from repo:

$ cp -r src ~/.node_libraries/reut
# Assuming ~/bin is in your $PATH
$ ln -s ~/.node_libraries/reut/bin/cli.js ~/bin/reut

## Usage

$ cat <<EOF >hello.js
var reut = require("reut")
reut.suite("Say hello!")
reut.test("Chinese", function(test) {
reut.test("Say hello in Chinese!", function(test) {
test.ok(true, "你好")
})
EOF
# And here we go
$ reut hello.js

See `doc/api.mkd` for more.
Document doc/api.mkd sucks. See example/\* instead.
4 changes: 2 additions & 2 deletions doc/api.mkd
Expand Up @@ -154,7 +154,7 @@ Example:
test.in(1, ["o", "k"])
test.in("foo", {foo: "here"})

test.match(/hi/, "holy shit")
test.match("holy shit", /hi/)
})

### test.cb([fn [, message]])
Expand Down Expand Up @@ -198,7 +198,7 @@ Notice the broken snippet below:

This is roughly equivalent to:

source.on(type, test.cb([fn [, message]]))
source.on(type, test.cb(fn, message))

## Command Line Runner

Expand Down
57 changes: 57 additions & 0 deletions example/all_in_one.js
@@ -0,0 +1,57 @@
var reut = require("reut")
, EE = require("events").EventEmitter
, fs = require("fs")

reut.suite("A suite to contain 'em all")
.setup(function(fixture, done) {
fixture.answer = 42
done()
})
.test("Native assert methods", function(test, fixture) {
test.ok(!test.fail, "Not provided")
test.ok(!test.ifError, "Others are ok to use")
test.notStrictEqual(0/0, NaN)
test.strictEqual(42, fixture.answer)
test.equal([], 0)
test.throws(function() {
return someth1ngUndefined
}, ReferenceError)
})
.test("Extended assert methods", function(test, fixture) {
test.typeOf(null, "object")
test.instanceOf(Function, Function)

test.include("foobar", "foo", "Works with string")
test.include([3, 5, 6], 5, "And array")

test.length([], 0)
test.length("goofy", 5)

test.match("holy shit", /hi/)

test.in(1, ["o", "k"])
// Setup for fixture.stat is defined below
test.in("stat", fixture)
})
// Async setup
.setup(function(fixture, done) {
fs.stat("/", function(err, stat) {
fixture.stat = stat
done()
})
})
.test("Something async", function(test, fixture) {
var boy = new EE()
test.instanceOf(fixture.stat, fs.Stats)
// Ensured callback
setTimeout(test.cb(function(theBoy) {
theBoy.emit("cry")
}), 10, boy)
test.timeout = 20 // Longer than 10

// Ensured event
test.emits(boy, "cry", function() {
test.ok(false, "Expected to fail")
test.equal(this, boy, "Still got tested")
})
})

0 comments on commit 632541b

Please sign in to comment.