dwf/rva: refactoring Suite (describe function) & Runner to use shared parent actionCollection

This commit is contained in:
pivotal 2008-12-02 11:21:50 -08:00
parent 2c1d809e62
commit 42eeab1cdb
2 changed files with 58 additions and 101 deletions

View File

@ -89,10 +89,10 @@
</provider>
</entry>
</file>
<file leaf-file-name="bootstrap.js" pinned="false" current="true" current-in-tab="true">
<file leaf-file-name="bootstrap.js" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/test/bootstrap.js">
<provider selected="true" editor-type-id="text-editor">
<state line="465" column="7" selection-start="12461" selection-end="12461" vertical-scroll-proportion="0.9632495">
<state line="333" column="14" selection-start="9162" selection-end="9162" vertical-scroll-proportion="1.0473888">
<folding />
</state>
</provider>
@ -107,10 +107,10 @@
</provider>
</entry>
</file>
<file leaf-file-name="jasmine.js" pinned="false" current="false" current-in-tab="false">
<file leaf-file-name="jasmine.js" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/lib/jasmine.js">
<provider selected="true" editor-type-id="text-editor">
<state line="238" column="9" selection-start="4765" selection-end="4765" vertical-scroll-proportion="0.5599194">
<state line="230" column="0" selection-start="4905" selection-end="4938" vertical-scroll-proportion="0.7703928">
<folding />
</state>
</provider>
@ -449,16 +449,16 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/jasmine.js">
<entry file="file://$PROJECT_DIR$/test/bootstrap.js">
<provider selected="true" editor-type-id="text-editor">
<state line="238" column="9" selection-start="4765" selection-end="4765" vertical-scroll-proportion="0.5599194">
<state line="333" column="14" selection-start="9162" selection-end="9162" vertical-scroll-proportion="1.0473888">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/bootstrap.js">
<entry file="file://$PROJECT_DIR$/lib/jasmine.js">
<provider selected="true" editor-type-id="text-editor">
<state line="465" column="7" selection-start="12461" selection-end="12461" vertical-scroll-proportion="0.9632495">
<state line="230" column="0" selection-start="4905" selection-end="4938" vertical-scroll-proportion="0.7703928">
<folding />
</state>
</provider>

View File

@ -18,6 +18,46 @@ if (typeof Function.method !== 'function') {
}
}
var actionCollection = function () {
var that = {
actions: [],
index: 0,
finished: false,
execute: function () {
if (that.actions.length > 0) {
that.next();
}
},
getCurrentAction: function () {
return that.actions[that.index];
},
next: function() {
if (that.index < that.actions.length) {
var currentAction = that.getCurrentAction();
currentAction.execute();
that.waitForDone(currentAction);
} else {
that.finished = true;
}
},
waitForDone: function(action) {
var id = setInterval(function () {
if (action.finished) {
clearInterval(id);
that.index++;
that.next();
}
}, 150);
}
}
return that;
}
/******************************************************************************
* Jasmine
******************************************************************************/
@ -150,106 +190,24 @@ var waits = function (timeout) {
var then = runs;
var describe = function (description, spec_definitions) {
var that = {
description: description,
specs: [],
specIndex: 0,
finished: false,
var that = actionCollection();
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);
}
else {
that.finished = true;
}
},
waitForDone: function(spec) {
var id = setInterval(function () {
if (spec.finished) {
clearInterval(id);
that.specIndex++;
that.next();
}
}, 150);
}
}
that.description = description;
that.specs = that.actions;
currentSuite = that;
currentRunner.suites.push(that);
spec_definitions();
return that;
}
var Jasmine = function () {
var that = actionCollection();
/*
* Jasmine constructor
*/
//var jasmine_init = function () {
// return {
// results: []
// }
//}
/*
* Jasmine instance
*/
//var Jasmine = jasmine_init();
var Jasmine = function() {
var that = {
suites: [],
suiteIndex: 0,
execute: function () {
if (that.suites.length > 0) {
that.next();
}
},
getCurrentSuite: function () {
return that.suites[that.suiteIndex];
},
next: function() {
if (that.suiteIndex < that.suites.length) {
var currentSuite = that.getCurrentSuite();
currentSuite.execute();
that.waitForDone(currentSuite);
}
},
waitForDone: function(suite) {
var id = setInterval(function () {
if (suite.finished) {
clearInterval(id);
that.suiteIndex++;
that.next();
}
}, 150);
}
}
that.suites = that.actions;
currentRunner = that;
return that;
}
@ -259,7 +217,6 @@ var currentSuite = describe('default current suite', function() {});
var currentSpec;
/*
* TODO:
* - add spec or description to results
@ -272,8 +229,8 @@ var currentSpec;
* - Suite supports after_each
* - Suite rolls up spec results
//* - Suite supports asynch
* - Runner that runs suites in order
* - Runner supports async
//* - Runner that runs suites in order
// * - Runner supports async
* - HTML reporter
* - Shows pass/fail progress (just like bootstrap reporter)
* - Lists a Summary: total # specs, # of passed, # of failed