diet-yadda
Version:
A true BDD framework for JavaScript - slimmed down
54 lines (44 loc) • 1.82 kB
JavaScript
/*
* Copyright 2010 Acuminous Ltd / Energized Work Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*jslint node: true */
;
var Interpreter = require('./Interpreter');
var Context = require('./Context');
var fn = require('./fn');
var Yadda = function(libraries, interpreter_context) {
if (!(this instanceof Yadda)) {
return new Yadda(libraries, interpreter_context);
}
this.interpreter = new Interpreter(libraries);
var _this = this;
this.requires = function(libraries) {
this.interpreter.requires(libraries);
return this;
};
this.yadda = function(scenario, scenario_context, next) {
if (arguments.length === 0) return this;
if (arguments.length === 2 && fn.is_function(scenario_context)) return this.yadda(scenario, {}, scenario_context);
this.interpreter.validate(scenario);
this.interpreter.interpret(scenario, new Context().merge(interpreter_context).merge(scenario_context), next);
};
// Not everyone shares my sense of humour re the recursive api :(
// See https://github.com/acuminous/yadda/issues/111
this.run = this.yadda;
this.toString = function() {
return "Yadda 0.22.1 Copyright 2010 Stephen Cresswell / Energized Work Ltd";
};
};
module.exports = Yadda;