dwf/rva: Suites now have beforeEach and AfterEach

This commit is contained in:
pivotal 2008-12-02 15:27:07 -08:00
parent a9a6d7cbda
commit f0de62906c
3 changed files with 129 additions and 33 deletions

View File

@ -92,7 +92,7 @@
<file leaf-file-name="bootstrap.js" pinned="false" current="true" current-in-tab="true"> <file leaf-file-name="bootstrap.js" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/test/bootstrap.js"> <entry file="file://$PROJECT_DIR$/test/bootstrap.js">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="553" column="7" selection-start="16102" selection-end="16102" vertical-scroll-proportion="0.70542634"> <state line="361" column="6" selection-start="10010" selection-end="10010" vertical-scroll-proportion="0.14728682">
<folding /> <folding />
</state> </state>
</provider> </provider>
@ -110,7 +110,7 @@
<file leaf-file-name="jasmine.js" pinned="false" current="false" current-in-tab="false"> <file leaf-file-name="jasmine.js" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/jasmine.js"> <entry file="file://$PROJECT_DIR$/lib/jasmine.js">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="260" column="33" selection-start="5439" selection-end="5439" vertical-scroll-proportion="0.7619048"> <state line="64" column="0" selection-start="1377" selection-end="1377" vertical-scroll-proportion="0.7820122">
<folding /> <folding />
</state> </state>
</provider> </provider>
@ -311,10 +311,10 @@
<window_info id="UI Designer" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="3" /> <window_info id="UI Designer" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="3" />
<window_info id="IDEtalk" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="3" /> <window_info id="IDEtalk" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="3" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="7" /> <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="7" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.21091811" order="0" /> <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.21091811" order="0" />
<window_info id="RDoc" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="8" /> <window_info id="RDoc" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="8" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.32841328" order="1" /> <window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.32841328" order="1" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" order="1" /> <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.25" order="1" />
<window_info id="Messages" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="8" /> <window_info id="Messages" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="8" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" order="6" /> <window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" order="6" />
<window_info id="Module Dependencies" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="3" /> <window_info id="Module Dependencies" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="3" />
@ -432,6 +432,13 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/test/test.css">
<provider selected="true" editor-type-id="text-editor">
<state line="5" column="0" selection-start="118" selection-end="118" vertical-scroll-proportion="0.14157973">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/bootstrap.html"> <entry file="file://$PROJECT_DIR$/test/bootstrap.html">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="15" column="26" selection-start="541" selection-end="541" vertical-scroll-proportion="0.47342193"> <state line="15" column="26" selection-start="541" selection-end="541" vertical-scroll-proportion="0.47342193">
@ -442,23 +449,16 @@
<state /> <state />
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/test/test.css">
<provider selected="true" editor-type-id="text-editor">
<state line="5" column="0" selection-start="118" selection-end="118" vertical-scroll-proportion="0.14157973">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/jasmine.js"> <entry file="file://$PROJECT_DIR$/lib/jasmine.js">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="260" column="33" selection-start="5439" selection-end="5439" vertical-scroll-proportion="0.7619048"> <state line="64" column="0" selection-start="1377" selection-end="1377" vertical-scroll-proportion="0.7820122">
<folding /> <folding />
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/test/bootstrap.js"> <entry file="file://$PROJECT_DIR$/test/bootstrap.js">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="553" column="7" selection-start="16102" selection-end="16102" vertical-scroll-proportion="0.70542634"> <state line="361" column="6" selection-start="10010" selection-end="10010" vertical-scroll-proportion="0.14728682">
<folding /> <folding />
</state> </state>
</provider> </provider>

View File

@ -40,13 +40,19 @@ var actionCollection = function () {
}, },
next: function() { next: function() {
if (that.index < that.actions.length) { if (that.index >= that.actions.length) {
that.finished = true;
return;
}
var currentAction = that.getCurrentAction(); var currentAction = that.getCurrentAction();
if (that.beforeEach) {
that.beforeEach.apply(currentAction);
}
currentAction.execute(); currentAction.execute();
that.waitForDone(currentAction); that.waitForDone(currentAction);
} else {
that.finished = true;
}
}, },
waitForDone: function(action) { waitForDone: function(action) {
@ -54,6 +60,11 @@ var actionCollection = function () {
if (action.finished) { if (action.finished) {
clearInterval(id); clearInterval(id);
that.report(action.results); that.report(action.results);
if (that.afterEach) {
that.afterEach.apply(action);
}
that.index++; that.index++;
that.next(); that.next();
} }
@ -217,11 +228,19 @@ var runs = function (func) {
currentSpec.runs(func); currentSpec.runs(func);
} }
var then = runs;
var waits = function (timeout) { var waits = function (timeout) {
currentSpec.waits(timeout); currentSpec.waits(timeout);
} }
var then = runs; var beforeEach = function (beforeEach) {
currentSuite.beforeEach = beforeEach;
}
var afterEach = function (afterEach) {
currentSuite.afterEach = afterEach;
}
var describe = function (description, spec_definitions) { var describe = function (description, spec_definitions) {
var that = actionCollection(); var that = actionCollection();

79
test/bootstrap.js vendored
View File

@ -357,6 +357,82 @@ var testSuites = function () {
}, 500); }, 500);
} }
var testBeforeAndAfterCallbacks = function () {
var suiteWithBefore = describe('one suite with a before', function () {
beforeEach(function () {
this.foo = 1;
});
it('should be a spec', function () {
runs(function() {
this.foo++;
this.expects_that(this.foo).should_equal(2);
});
});
it('should be another spec', function () {
runs(function() {
this.foo++;
this.expects_that(this.foo).should_equal(2);
});
});
});
suiteWithBefore.execute();
setTimeout(function () {
var suite = suiteWithBefore;
reporter.test((suite.beforeEach !== undefined),
"Suite's beforeEach was not defined");
reporter.test((suite.results.results[0].results[0].passed === true),
"the first spec's foo should have been 2");
reporter.test((suite.results.results[1].results[0].passed === true),
"the second spec's this.foo should have been 2");
}, 750);
setTimeout(function () {
var suiteWithAfter = describe('one suite with an after_each', function () {
it('should be a spec with an after_each', function () {
runs(function() {
this.foo = 0;
this.foo++;
this.expects_that(this.foo).should_equal(1);
});
});
it('should be another spec with an after_each', function () {
runs(function() {
this.foo = 0;
this.foo++;
this.expects_that(this.foo).should_equal(1);
});
});
afterEach(function () {
this.foo = 0;
});
});
suiteWithAfter.execute();
setTimeout(function () {
var suite = suiteWithAfter;
reporter.test((suite.afterEach !== undefined),
"Suite's afterEach was not defined");
reporter.test((suite.results.results[0].results[0].passed === true),
"afterEach failure: " + suite.results.results[0].results[0].message);
reporter.test((suite.specs[0].foo === 0),
"afterEach failure: foo was not reset to 0");
reporter.test((suite.results.results[1].results[0].passed === true),
"afterEach failure: " + suite.results.results[0].results[0].message);
reporter.test((suite.specs[1].foo === 0),
"afterEach failure: foo was not reset to 0");
}, 500);
}, 1200);
}
var testSpecScope = function () { var testSpecScope = function () {
suite = describe('one suite description', function () { suite = describe('one suite description', function () {
@ -543,6 +619,7 @@ var runTests = function () {
testAsyncSpecs(); testAsyncSpecs();
testAsyncSpecsWithMockSuite(); testAsyncSpecsWithMockSuite();
testSuites(); testSuites();
testBeforeAndAfterCallbacks();
testSpecScope(); testSpecScope();
testRunner(); testRunner();
testNestedResults(); testNestedResults();
@ -551,7 +628,7 @@ var runTests = function () {
setTimeout(function() { setTimeout(function() {
$('spinner').hide(); $('spinner').hide();
reporter.summary(); reporter.summary();
}, 3500); }, 4500);
} }