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">
<entry file="file://$PROJECT_DIR$/test/bootstrap.js">
<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 />
</state>
</provider>
@ -110,7 +110,7 @@
<file leaf-file-name="jasmine.js" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/jasmine.js">
<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 />
</state>
</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="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="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="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="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" />
@ -432,6 +432,13 @@
</state>
</provider>
</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">
<provider selected="true" editor-type-id="text-editor">
<state line="15" column="26" selection-start="541" selection-end="541" vertical-scroll-proportion="0.47342193">
@ -442,23 +449,16 @@
<state />
</provider>
</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">
<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 />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/bootstrap.js">
<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 />
</state>
</provider>

View File

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

105
test/bootstrap.js vendored
View File

@ -357,6 +357,82 @@ var testSuites = function () {
}, 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 () {
suite = describe('one suite description', function () {
@ -459,24 +535,24 @@ var testNestedResults = function () {
results.push({passed: true, message: 'Passed.'});
reporter.test((results.results.length === 1),
"nestedResults.push didn't work");
"nestedResults.push didn't work");
reporter.test((results.totalCount === 1),
"nestedResults.push didn't increment totalCount");
"nestedResults.push didn't increment totalCount");
reporter.test((results.passedCount === 1),
"nestedResults.push didn't increment passedCount");
"nestedResults.push didn't increment passedCount");
reporter.test((results.failedCount === 0),
"nestedResults.push didn't ignore failedCount");
"nestedResults.push didn't ignore failedCount");
results.push({passed: false, message: 'FAIL.'});
reporter.test((results.results.length === 2),
"nestedResults.push didn't work");
"nestedResults.push didn't work");
reporter.test((results.totalCount === 2),
"nestedResults.push didn't increment totalCount");
"nestedResults.push didn't increment totalCount");
reporter.test((results.passedCount === 1),
"nestedResults.push didn't ignore passedCount");
"nestedResults.push didn't ignore passedCount");
reporter.test((results.failedCount === 1),
"nestedResults.push didn't increment failedCount");
"nestedResults.push didn't increment failedCount");
// Branch case
var leafResultsOne = nestedResults();
@ -492,13 +568,13 @@ var testNestedResults = function () {
branchResults.push(leafResultsTwo);
reporter.test((branchResults.results.length === 2),
"Branch Results should have 2 nestedResults, has " + branchResults.results.length);
"Branch Results should have 2 nestedResults, has " + branchResults.results.length);
reporter.test((branchResults.totalCount === 4),
"Branch Results should have 4 results, has " + branchResults.totalCount);
"Branch Results should have 4 results, has " + branchResults.totalCount);
reporter.test((branchResults.passedCount === 2),
"Branch Results should have 2 passed, has " + branchResults.passedCount);
"Branch Results should have 2 passed, has " + branchResults.passedCount);
reporter.test((branchResults.failedCount === 2),
"Branch Results should have 2 failed, has " + branchResults.failedCount);
"Branch Results should have 2 failed, has " + branchResults.failedCount);
}
var testReporting = function () {
@ -529,7 +605,7 @@ var testReporting = function () {
reporter.test((runner.results.failedCount === 1),
'Expectation Failed count should be 1, but was ' + runner.results.failedCount);
reporter.test((runner.results.description === 'All Jasmine Suites'),
'Jasmine Runner does not have the expected description, has: ' + runner.results.description);
'Jasmine Runner does not have the expected description, has: ' + runner.results.description);
}, 1000);
}
@ -543,6 +619,7 @@ var runTests = function () {
testAsyncSpecs();
testAsyncSpecsWithMockSuite();
testSuites();
testBeforeAndAfterCallbacks();
testSpecScope();
testRunner();
testNestedResults();
@ -551,7 +628,7 @@ var runTests = function () {
setTimeout(function() {
$('spinner').hide();
reporter.summary();
}, 3500);
}, 4500);
}