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">
<entry file="file://$PROJECT_DIR$/test/bootstrap.js">
<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 />
</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="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>
@ -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="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="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" />
@ -514,14 +514,18 @@
</state>
</provider>
</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">
<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 />
</state>
</provider>
<provider editor-type-id="HtmlPreview">
<state />
</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 />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/example/example.html">
@ -534,12 +538,15 @@
<state />
</provider>
</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">
<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 />
</state>
</provider>
<provider editor-type-id="HtmlPreview">
<state />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/json_reporter.js">
<provider selected="true" editor-type-id="text-editor">
@ -550,21 +557,14 @@
</entry>
<entry file="file://$PROJECT_DIR$/lib/jasmine.js">
<provider selected="true" editor-type-id="text-editor">
<state line="261" column="49" selection-start="5654" selection-end="5654" vertical-scroll-proportion="0.7172619">
<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">
<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$/test/bootstrap.js">
<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 />
</state>
</provider>

View File

@ -237,9 +237,26 @@ var it = function (description, func) {
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 () {
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) {
var previousFunction = that.queue[that.queue.length - 2];
previousFunction.next = function () {
currentFunction.execute();
that.safeExecute(currentFunction);
}
}
@ -343,12 +360,20 @@ Jasmine.Reporters.reporter = function (callbacks) {
callbacks: callbacks || {},
doCallback: function (callback, results) {
if (callback) { callback(results); }
if (callback) {
callback(results);
}
},
reportRunnerResults: function (results) { that.doCallback(that.callbacks.runnerCallback, results); },
reportSuiteResults: function (results) { that.doCallback(that.callbacks.suiteCallback, results); },
reportSpecResults: function (results) { that.doCallback(that.callbacks.specCallback, results);}
reportRunnerResults: function (results) {
that.doCallback(that.callbacks.runnerCallback, results);
},
reportSuiteResults: function (results) {
that.doCallback(that.callbacks.suiteCallback, results);
},
reportSpecResults: function (results) {
that.doCallback(that.callbacks.specCallback, results);
}
}
return that;

74
test/bootstrap.js vendored
View File

@ -766,22 +766,73 @@ var testHandlesBlankSpecs = function () {
describe('Suite for handles blank specs', 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();
setTimeout(function() {
reporter.test((runner.suites[0].specResults.length === 2),
'Should have found 2 spec results, got ' + runner.suites[0].specResults.length);
reporter.test((runner.suites[0].results.passedCount === 2),
'Should have found 2 passing specs, got ' + runner.suites[0].results.passedCount);
}, 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.results.results[0].results.results.length === 2),
'Should have found 2 spec results, got ' + runner.results.results[0].results.results.length );
reporter.test((runner.results.results[0].results.passedCount === 2),
'Should have found 2 passing specs, got ' + runner.results.results[0].results.passedCount);
}, 250);
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 () {
@ -862,9 +913,13 @@ var runTests = function () {
testRunnerFinishCallback();
testNestedResults();
testResults();
// 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 () {
testReporterWithCallbacks();
}, 2500);
@ -875,7 +930,6 @@ var runTests = function () {
testJSONReporterWithDOM();
}, 5000);
testResultsAliasing();
setTimeout(function() {
$('spinner').hide();
reporter.summary();