added suite functionality and tests on function scope

This commit is contained in:
pivotal
2008-12-02 10:27:09 -08:00
parent be33f1e6d4
commit f43ba0a51c
3 changed files with 250 additions and 211 deletions

View File

@@ -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
*/