dwf/rva: rolled back blank expectations for now; Now catching exceptions & reporting them in results.

This commit is contained in:
pivotal 2008-12-10 11:20:33 -08:00
parent c9edbbe9b7
commit 259390868e
3 changed files with 115 additions and 36 deletions

View File

@ -101,7 +101,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="841" column="18" selection-start="25839" selection-end="25839" vertical-scroll-proportion="0.61732125"> <state line="922" column="5" selection-start="28893" selection-end="28893" vertical-scroll-proportion="0.7703928">
<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="261" column="49" selection-start="5654" selection-end="5654" vertical-scroll-proportion="0.7172619"> <state line="244" column="8" selection-start="5226" selection-end="5226" vertical-scroll-proportion="0.38588008">
<folding /> <folding />
</state> </state>
</provider> </provider>
@ -427,7 +427,7 @@
<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="false" weight="0.32841328" order="1" /> <window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" 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="false" weight="0.25" order="1" />
@ -514,14 +514,18 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/test/bootstrap.html"> <entry file="file://$PROJECT_DIR$/example/example.js">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state line="12" column="4" selection-start="533" selection-end="533" vertical-scroll-proportion="0.23626943"> <state line="6" column="0" selection-start="183" selection-end="183" vertical-scroll-proportion="0.11025145">
<folding /> <folding />
</state> </state>
</provider> </provider>
<provider editor-type-id="HtmlPreview"> </entry>
<state /> <entry file="file://$PROJECT_DIR$/lib/jasmine.css">
<provider selected="true" editor-type-id="text-editor">
<state line="17" column="36" selection-start="351" selection-end="351" vertical-scroll-proportion="0.31237912">
<folding />
</state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/example/example.html"> <entry file="file://$PROJECT_DIR$/example/example.html">
@ -534,12 +538,15 @@
<state /> <state />
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/example/example.js"> <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="6" column="0" selection-start="183" selection-end="183" vertical-scroll-proportion="0.11025145"> <state line="12" column="4" selection-start="533" selection-end="533" vertical-scroll-proportion="0.23626943">
<folding /> <folding />
</state> </state>
</provider> </provider>
<provider editor-type-id="HtmlPreview">
<state />
</provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/lib/json_reporter.js"> <entry file="file://$PROJECT_DIR$/lib/json_reporter.js">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
@ -550,21 +557,14 @@
</entry> </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="261" column="49" selection-start="5654" selection-end="5654" vertical-scroll-proportion="0.7172619"> <state line="244" column="8" selection-start="5226" selection-end="5226" vertical-scroll-proportion="0.38588008">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/jasmine.css">
<provider selected="true" editor-type-id="text-editor">
<state line="17" column="36" selection-start="351" selection-end="351" vertical-scroll-proportion="0.31237912">
<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="841" column="18" selection-start="25839" selection-end="25839" vertical-scroll-proportion="0.61732125"> <state line="922" column="5" selection-start="28893" selection-end="28893" vertical-scroll-proportion="0.7703928">
<folding /> <folding />
</state> </state>
</provider> </provider>

View File

@ -237,9 +237,26 @@ var it = function (description, func) {
that.finished = true; that.finished = true;
}, },
safeExecute: function(queuedFunc) {
try {
queuedFunc.execute();
}
catch (e) {
that.results.push({
passed: false,
message: e.name + ': '+ e.message + ' in ' + e.fileName +
' (line ' + e.lineNumber +')'
});
queuedFunc.next();
}
},
execute: function () { execute: function () {
if (that.queue[0]) { if (that.queue[0]) {
that.queue[0].execute(); that.safeExecute(that.queue[0])
}
else {
that.finish();
} }
} }
}; };
@ -251,7 +268,7 @@ var it = function (description, func) {
if (that.queue.length > 1) { if (that.queue.length > 1) {
var previousFunction = that.queue[that.queue.length - 2]; var previousFunction = that.queue[that.queue.length - 2];
previousFunction.next = function () { previousFunction.next = function () {
currentFunction.execute(); that.safeExecute(currentFunction);
} }
} }
@ -343,12 +360,20 @@ Jasmine.Reporters.reporter = function (callbacks) {
callbacks: callbacks || {}, callbacks: callbacks || {},
doCallback: function (callback, results) { doCallback: function (callback, results) {
if (callback) { callback(results); } if (callback) {
callback(results);
}
}, },
reportRunnerResults: function (results) { that.doCallback(that.callbacks.runnerCallback, results); }, reportRunnerResults: function (results) {
reportSuiteResults: function (results) { that.doCallback(that.callbacks.suiteCallback, results); }, that.doCallback(that.callbacks.runnerCallback, results);
reportSpecResults: function (results) { that.doCallback(that.callbacks.specCallback, results);} },
reportSuiteResults: function (results) {
that.doCallback(that.callbacks.suiteCallback, results);
},
reportSpecResults: function (results) {
that.doCallback(that.callbacks.specCallback, results);
}
} }
return that; return that;

78
test/bootstrap.js vendored
View File

@ -766,24 +766,75 @@ var testHandlesBlankSpecs = function () {
describe('Suite for handles blank specs', function () { describe('Suite for handles blank specs', function () {
it('should be a test with a blank runs block', function() { it('should be a test with a blank runs block', function() {
runs(function () { runs(function () {});
});
});
it('should be a blank (empty function) test', function() {
}); });
it('should be a blank (empty function) test', function() {});
}); });
runner.execute(); runner.execute();
setTimeout(function() { setTimeout(function() {
reporter.test((runner.results.results[0].results.results.length === 2), reporter.test((runner.suites[0].specResults.length === 2),
'Should have found 2 spec results, got ' + runner.results.results[0].results.results.length ); 'Should have found 2 spec results, got ' + runner.suites[0].specResults.length);
reporter.test((runner.results.results[0].results.passedCount === 2), reporter.test((runner.suites[0].results.passedCount === 2),
'Should have found 2 passing specs, got ' + runner.results.results[0].results.passedCount); 'Should have found 2 passing specs, got ' + runner.suites[0].results.passedCount);
}, 250); }, 250);
} }
var testHandlesExceptions = function () {
jasmine = Jasmine.init();
var runner = Runner();
describe('Suite for handles exceptions', function () {
it('should be a test that fails because it throws an exception', function() {
runs(function () {
fakeObject.fakeMethod();
});
});
it('should be another test that fails because it throws an exception', function() {
runs(function () {
fakeObject2.fakeMethod2();
});
runs(function () {
this.expects_that(true).should_equal(true);
});
});
it('should be a passing test that runs after exceptions are thrown', function() {
runs(function () {
this.expects_that(true).should_equal(true);
});
});
});
runner.execute();
setTimeout(function() {
reporter.test((runner.suites[0].specResults.length === 3),
'Should have found 3 spec results, got ' + runner.suites[0].specResults.length);
reporter.test((runner.suites[0].specs[0].expectationResults[0].passed === false),
'First test should have failed, got passed');
reporter.test((runner.suites[0].specs[0].expectationResults[0].message === 'ReferenceError: fakeObject is not defined in file:///Users/pivotal/workspace/jasmine/test/bootstrap.js (line 791)'),
'First test should have shown some exception string, got ' + runner.suites[0].specs[0].expectationResults[0].message);
reporter.test((runner.suites[0].specs[1].expectationResults[0].passed === false),
'Second test should have a failing first result, got passed');
reporter.test((runner.suites[0].specs[1].expectationResults[0].message === 'ReferenceError: fakeObject2 is not defined in file:///Users/pivotal/workspace/jasmine/test/bootstrap.js (line 797)'),
'Second test should have shown an exception message for the first result, got ' + runner.suites[0].specs[1].expectationResults[0].message);
reporter.test((runner.suites[0].specs[1].expectationResults[1].passed === true),
'Second expectation in second test should have still passed');
reporter.test((runner.suites[0].specs[2].expectationResults[0].passed === true),
'Third test should have passed, got failed');
}, 2000);
}
var testResultsAliasing = function () { var testResultsAliasing = function () {
jasmine = Jasmine.init(); jasmine = Jasmine.init();
var runner = Runner(); var runner = Runner();
@ -862,9 +913,13 @@ var runTests = function () {
testRunnerFinishCallback(); testRunnerFinishCallback();
testNestedResults(); testNestedResults();
testResults(); testResults();
// testHandlesBlankSpecs(); // handle blank specs will work later.
// testHandlesBlankSpecs();
testHandlesExceptions();
testResultsAliasing();
// Timing starts to matter with these tests; ALWAYS use setTimeout()
// Timing starts to matter with these tests; ALWAYS use setTimeout()
setTimeout(function () { setTimeout(function () {
testReporterWithCallbacks(); testReporterWithCallbacks();
}, 2500); }, 2500);
@ -875,7 +930,6 @@ var runTests = function () {
testJSONReporterWithDOM(); testJSONReporterWithDOM();
}, 5000); }, 5000);
testResultsAliasing();
setTimeout(function() { setTimeout(function() {
$('spinner').hide(); $('spinner').hide();
reporter.summary(); reporter.summary();