vows-fluent.js | |
---|---|
var vows = require("vows"); | |
Context object. This is an abstraction around Vows contexts | var Context = { |
initialize the context | "start": function _start() {
this._ctx = {};
return this;
}, |
end the context. This returns the Object that vow expects to be a context. This will call end recursively if it exists | "end": function _end() {
var ctx = {};
Object.keys(this._ctx).forEach((function(key) {
var val = this._ctx[key];
if (val.end) {
ctx[key] = val.end();
} else {
ctx[key] = val;
}
}).bind(this));
return ctx;
}, |
Sets the topic of the context to be | "topic": function _topic(topic) {
this._ctx.topic = topic
return this;
}, |
Adds a vow to the contex
with the name | "vow": function _vow(text, vow) {
this._ctx[text] = vow;
return this;
}, |
Create a new sub context and add it to this context
with the name | "context": function _context(text) {
var c = Object.create(Context);
c._ctx = {};
c._parent = this;
c._batch = this._batch;
this._ctx[text] = c;
return c;
}, |
Returns the parent context | "parent": function _parent() {
if (this._parent) {
return this._parent;
}
return this.batch();
}, |
returns the batch this context belongs to | "batch": function _batch() {
return this._batch;
}, |
returns the suite this context belongs to | "suite": function _suite() {
return this._batch._suite;
}
}; |
A representation of a vows batch. A vows batch just contains a bunch of contexts | var Batch = { |
initialize the object | "start": function _start() {
this._batch = {};
return this;
}, |
end the batch. This transforms it into a vows compliant data structure. | "end": function _end(){
var batch = {};
Object.keys(this._batch).forEach((function(ctx) {
batch[ctx] = this._batch[ctx].end();
}).bind(this));
return batch;
}, |
create a new context and adds it to the batch
with the name | "context": function _context(title) {
var c = createContext();
c._batch = this;
this._batch[title] = c;
return c;
}, |
returns the suite this batch belongs to. | "suite": function() {
return this._suite;
}
}; |
A representation of a vows Suite. Every application should onhly have one suite. | var Suite = { |
initialize the suite. Set's the describtion
of the suite to be | "start": function _start(name) {
this._batch = [];
this._suite = vows.describe(name);
return this;
}, |
Creates a batch and add's it to the suite. Returns the batch | "batch": function _batch() {
var b = createBatch();
b._suite = this;
this._batch.push(b);
return b;
}, |
end the suite and call export on the vows suite | "export": function _export(m, options) {
var s = this.end();
return s.export(m || module, options);
}, |
A macro for JSLint | "exportTo": function _exportTo(m, options) {
return this.export(m, options);
}, |
end the suite and call run on the vows suite | "run": function _run(options, callback) {
var s = this.end();
return s.run(options, callback);
}, |
end the suite returning a vows Suite. | "end": function _end() {
this._batch.forEach((function _addBatches(batch) {
this._suite.addBatch(batch.end());
}).bind(this));
return this._suite;
}
} |
creates a batch by cloning | var createBatch = function() {
return Object.create(Batch).start();
} |
Create a context by cloning | var createContext = function() {
return Object.create(Context).start();
} |
Create a Suite by cloning | var createSuite = function(name) {
return Object.create(Suite).start(name);
} |
expose objects | exports.Context = Context;
exports.Batch = Batch;
exports.Suite = Suite;
exports.context = exports.createContext = createContext;
exports.batch = exports.createBatch = createBatch;
exports.suite = exports.createSuite = createSuite;
|