
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
http://glenjamin.github.com/nodespec
.. image:: https://secure.travis-ci.org/glenjamin/nodespec.png
A light-weight RSpec_-esque testing framework designed and built specifically for NodeJS.
.. _RSpec: http://relishapp.com/rspec
.. contents:: :local:
Ground-up support for NodeJS convention callbacks
Only one test running at a time
No global variables
RSpec style syntactic sugar
Pluggable mocking support
Native assertions
Easy to extend or replace the default assertions
Multiple output formatters on the same test run (not yet implemented)
README Driven Development_
Any and all features will be outlined in this readme file before the tests
are written.
BEHAVIOUR Driven Development
Integration tests which treat the executable as a black-box will be written
using cucumber_ & aruba_ (yes, using Ruby)
before any implementation.
Lots and lots of Unit Tests All code will be fully unit tested using NodeSpec itself before release.
.. _README Driven Development: http://tom.preston-werner.com/2010/08/23/readme-driven-development.html
.. _cucumber: http://cukes.info/
.. _aruba: https://github.com/cucumber/aruba
If you'd like to contribute
cucumber -p allIf you're fixing a bug, please add a testcase to prove it was broken and is fixed, if you're adding a new feature, please add cucumber feature file for it.
To be able to run cucumber, you'll need Ruby and Bundler installed, then do bundle install.
Via npm::
npm install nodespec
Or clone directly from github::
git clone git://github.com/glenjamin/nodespec
cd nodespec
npm link
Require the module into test files to use it::
var nodespec = require('nodespec');
And then at the end of each test file::
nodespec.exec();
Simple spec::
nodespec.describe("Addition", function() {
this.example("1 + 1 = 2", function() {
this.assert.equal(1 + 1, 2);
});
});
Simple async spec::
nodespec.describe("nextTick", function() {
// Accept 1 argument in the definition for an async test
this.example("fires the callback", function(test) {
this.expect(2);
this.assert.strictEqual(this, test);
process.nextTick(function() {
this.assert.strictNotEqual(this, test);
// async tests must call test.done()
test.done();
});
});
});
Before/After Hooks::
// Hooks share `this` with tests, but it's rebuilt each time
nodespec.describe("Some databasey test", function() {
this.before(function(hook) {
this.assert.strictEqual(this, hook);
db_connect(function (err, conn) {
hook.db = conn;
hook.db.start_transaction(function(err, tx) {
hook.tx = tx;
hook.done();
});
});
});
this.after(function() {
this.tx.rollback();
});
this.example("database interaction", function(test) {
test.expect(2);
test.db.insert({field: 1}, function(err, result) {
test.assert.strictEqual(result.affected, 1);
test.db.get(function(err, result) {
test.assert.strictEqual(result.field, 1);
test.done();
});
});
});
});
Nested contexts with subject::
nodespec.describe("My Server", function() {
// This function is executed once when `this.server` is accessed
this.subject('server', function() {
return new Server(1337);
});
this.context("Strict Mode", function() {
this.before(function() {
this.server.use_strict_mode();
});
this.example("invalid request fails", function(test) {
test.expect(1);
test.server.request('invalid', function(err, result) {
test.assert.notEqual(err, null);
test.done();
});
});
});
this.context("Not Strict Mode", function() {
this.before(function() {
this.server.dont_use_strict_mode();
});
this.example("invalid request fails silently", function(test) {
test.expect(2);
test.server.request('invalid', function(err, result) {
test.assert.equal(err, null);
test.assert.equal(result, null);
test.done();
});
});
});
});
Copyright © 2011 The NodeSpec Authors. See LICENSE and AUTHORS for details.
FAQs
A light-weight RSpec-esque testing framework
We found that nodespec demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.