The top-level container object for the nodespec test suite.
var nodespec = require('nodespec');
The nodespec module when included functions as the collection for all example groups and behaviours you wish to describe in your system, each module that wants to describe tests should require nodespec and use the describe method to describe groups of examples.
var nodespec = require('nodespec'); nodespec.describe("test behaviour", function() { // ... test definitions here }); nodespec.exec();
As well as acting like a singleton for the test suite, it is also callable as a factory-style method if more than one top-level container per script execution is needed for some reason (see nodespec).
var nodespec1 = require('nodespec')("top-level 1"); var nodespec2 = require('nodespec')("top-level 2");
nodespec module | The top-level container object for the nodespec test suite. |
Functions | |
nodespec | Create another top-level nodespec container, keyed by name |
Nodespec | Methods attached to the module |
Functions | |
abandon | Forget this nodespec function |
require | Require nodespec test definition files without executing them |
describe | Create an ExampleGroup to describe some behaviour |
before | Add a before hook to be run before all specs in the suite |
after | Add an after hook to be run after all specs in the suite |
mockWith | Load a pre-defined mocking library |
registerFormatter | Add an additional formatter |
exec | Run all specs currently defined for this suite |
function nodespec( name, deps )
Create another top-level nodespec container, keyed by name
Note that this function is not a method of the nodespec module, it is the callable module itself.
name | {string} Name for the separate context, subsequent calls with the same name will return the same object |
deps | {options} Allows for dependency injection of constructor functions, omitted keys will fall back to defaults |
deps.ExampleGroup | defaults to ExampleGroup |
deps.Example | defaults to Example |
deps.Context | defaults to <Context> |
deps.Result | defaults to <Result> |
deps.SingleResult | defaults to <SingleResult> |
deps.Pending | defaults to <Pending> |
deps.ExpectationError | defaults to assert.AssertionError |
{function} A new Nodespec function, which is still callable as nodespec
var nodespec = require("nodespec"); var separate_nodespec = nodespec("separate stack", {Context: AugmentedContext})
Methods attached to the module
Functions | |
abandon | Forget this nodespec function |
require | Require nodespec test definition files without executing them |
describe | Create an ExampleGroup to describe some behaviour |
before | Add a before hook to be run before all specs in the suite |
after | Add an after hook to be run after all specs in the suite |
mockWith | Load a pre-defined mocking library |
registerFormatter | Add an additional formatter |
exec | Run all specs currently defined for this suite |
nodespec.abandon = function abandon()
Forget this nodespec function
Subsequent calls to nodespec() with the same name as this instance will return a fresh instance instead of the usual behaviour.
var nodespec = require('nodespec'); var another = nodespec('another'); another.abandon(); var again = nodespec('another'); another !== again;
nodespec.require = function require( target )
Require nodespec test definition files without executing them
This function is currently the recommended way to load a test suite that spans multiple files and then executing it all at once. See the example below.
target | {string} The path to load, as with the usual nodejs require function |
// Note that glob isn't an actual built-in NodeJS function var files = glob('spec/*_spec.js'); for (var i in files) { nodespec.require(files[i]); }
nodespec.describe = function describe( description, options, definition )
Create an ExampleGroup to describe some behaviour
description | {string} The title of the behaviour being described |
[options] | {options} Any additional options to be passed to the ExampleGroup constructor. |
definition | {function} The group definition |
{ExampleGroup} The newly created example group
nodespec.before = function before( block )
Add a before hook to be run before all specs in the suite
block | {function} The hook definition |
The block will be executed before each spec on a fresh context, any exceptions or failed assertions will be treated as belonging to the spec being executed. The function can be defined in either procedural or asynchronous mode.
this within the function is bound to the test context, the following example makes ’value’ available in every test as this.variable.
nodespec.before(function() { this.variable = 'value'; })
If the function takes one argument, it is passed the test context and executed asynchronously, to signal completion you must call done(). The following example makes the value returned by the async function available to every test as this.variable.
nodespec.before(function(hook) { async_function(function(err, value) { hook.variable = value; hook.done(); }); }); See also <Nodespec.after>, <ExampleGroup.before>, <ExampleGroup.after>
nodespec.after = function after( block )
Add an after hook to be run after all specs in the suite
block | {function} The hook definition |
The block is processed in the same way as <nodespec.before>, with one difference: if an assertion fails or an error is thrown in an after block, all other after blocks will still be run.
nodespec.mockWith = function mockWith( lib )
Load a pre-defined mocking library
lib | {string} The name of a supported mocking library |
sinon | Provides a sinon sandbox to each test as context.sinon (http://sinonjs.org). |
Create another top-level nodespec container, keyed by name
function nodespec( name, deps )
Forget this nodespec function
nodespec.abandon = function abandon()
Require nodespec test definition files without executing them
nodespec.require = function require( target )
Create an ExampleGroup to describe some behaviour
nodespec.describe = function describe( description, options, definition )
Add a before hook to be run before all specs in the suite
nodespec.before = function before( block )
Add an after hook to be run after all specs in the suite
nodespec.after = function after( block )
Load a pre-defined mocking library
nodespec.mockWith = function mockWith( lib )
Add an additional formatter
nodespec.registerFormatter = function registerFormatter( name, file, set_default )
Run all specs currently defined for this suite
nodespec.exec = function exec()