Example

Describes a single piece of behaviour

Requiring

var Example = require('nodespec/lib/example').Example;

In general an Example should not be instantiated directly, and instead created via ExampleGroup.example.

Summary
ExampleDescribes a single piece of behaviour
Constructors
Example
Constants
DEFAULT_TIMEOUTDefaults to 5 seconds
Properties
descriptionThe description of this example
full_descriptionThe full description, parent’s description + this example’s
file_pathThe file where this example was declared
line_numberThe line number where this example was declared.
Functions
toStringUseful string representation of the example
timeout_afterModify the execution timeout
execExecute this example

Constructors

Example

function Example(description,
options,
block)

Arguments

description{string} The title of the behaviour being described
options{options} See below
block{function} The spec definition, can be prodcedural or asynchronous.  See ExampleGroup.example.
options.timeout{nunber} seconds before assuming spec has stalled
options.groupThe parent ExampleGroup of this spec
options.nodespecThe top-level nodespec function
options.deps{options} Constructor function dependency injection
options.deps.Contextconstructor function for context
options.deps.SingleResultconstructor function for one result
options.deps.Pendingconstructor function for pending exception

Constants

DEFAULT_TIMEOUT

Defaults to 5 seconds

Returns

number

Properties

description

The description of this example

Returns

string

full_description

The full description, parent’s description + this example’s

Returns

string

file_path

The file where this example was declared

This is defined as the first file in the stack trace that is not found inside nodespec/lib

Returns

string

line_number

The line number where this example was declared.  See Example.file_path.

Returns

number

Functions

toString

Example.prototype.toString = function()

Useful string representation of the example

Includes full description, file path and line number

Returns

string

timeout_after

Example.prototype.timeout_after = function(seconds)

Modify the execution timeout

Arguments

seconds{number} New timeout value

exec

Example.prototype.exec = function(emitter,
callback/*(err, result)*/)

Execute this example

All before hooks defined will be executed in sequence, followed by the example, followed by all of the after hooks.  Any defined subjects will be available to the example’s context.

Arguments

emitter{EventEmitter} events from execution will be fired on this emitter
callback{function} Callback fired on completion of execution
callback.err{Error} undefined or an exception object
callback.result{<SingleResult>} The result of the execution

Events

exampleStart (Example)Example about to be executed
exampleComplete (Example, err)Example has finished execution
examplePass (Example)Example has passed
exampleFail (Example, err)Example has failed
examplePend (Example, err)Example is pending
exampleError (Example, err)Example has errored
function Example(description,
options,
block)
Example.prototype.toString = function()
Useful string representation of the example
Example.prototype.timeout_after = function(seconds)
Modify the execution timeout
Example.prototype.exec = function(emitter,
callback/*(err, result)*/)
Execute this example
ExampleGroup.prototype.example = function(description,
options,
block)
Define an Example to be executed against this group
A collection of sub-groups and specs describing some behaviour
function nodespec(name,
deps)
Create another top-level nodespec container, keyed by name
The file where this example was declared
Close