added suite functionality and tests on function scope
This commit is contained in:
@@ -78,13 +78,14 @@ var queuedFunction = function(func, timeout, spec) {
|
||||
}
|
||||
|
||||
|
||||
var it = function (description) {
|
||||
var it = function (description, func) {
|
||||
var that = {
|
||||
description: description,
|
||||
queue: [],
|
||||
currentTimeout: 0,
|
||||
finished: false,
|
||||
suite: {next:function() {}},
|
||||
suite: {next:function() {
|
||||
}},
|
||||
results: [],
|
||||
|
||||
expects_that: function (actual) {
|
||||
@@ -129,25 +130,74 @@ var it = function (description) {
|
||||
that.runs = addToQueue;
|
||||
that.then = addToQueue;
|
||||
|
||||
currentSuite.tests.push(that);
|
||||
currentSuite.specs.push(that);
|
||||
currentSpec = that;
|
||||
|
||||
if (func) {
|
||||
func();
|
||||
}
|
||||
|
||||
return that;
|
||||
}
|
||||
|
||||
var runs = function (func) {
|
||||
currentSpec.runs(func);
|
||||
}
|
||||
|
||||
var currentSuite;
|
||||
var waits = function (timeout) {
|
||||
currentSpec.waits(timeout);
|
||||
}
|
||||
|
||||
var describe = function (description, tests) {
|
||||
var then = runs;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var describe = function (description, spec_definitions) {
|
||||
var that = {
|
||||
description: description,
|
||||
tests: []
|
||||
specs: [],
|
||||
specIndex: 0,
|
||||
|
||||
execute: function () {
|
||||
if (that.specs.length > 0) {
|
||||
that.next();
|
||||
}
|
||||
},
|
||||
|
||||
getCurrentSpec: function () {
|
||||
return that.specs[that.specIndex];
|
||||
},
|
||||
|
||||
next: function() {
|
||||
if (that.specIndex < that.specs.length) {
|
||||
var currentSpec = that.getCurrentSpec();
|
||||
currentSpec.execute();
|
||||
that.waitForDone(currentSpec);
|
||||
}
|
||||
},
|
||||
|
||||
waitForDone: function(spec) {
|
||||
var id = setInterval(function () {
|
||||
if (spec.finished) {
|
||||
clearInterval(id);
|
||||
that.specIndex++;
|
||||
that.next();
|
||||
}
|
||||
}, 150);
|
||||
}
|
||||
}
|
||||
|
||||
currentSuite = that;
|
||||
tests();
|
||||
spec_definitions();
|
||||
|
||||
return that;
|
||||
}
|
||||
|
||||
var currentSuite = describe('default current suite', function() {});
|
||||
var currentSpec;
|
||||
|
||||
/*
|
||||
* Jasmine constructor
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user