carl/bosh - killed bootstrap dead; refactored to have emitString for use by subclasses.

This commit is contained in:
pivotal 2009-07-29 11:33:23 -07:00
parent 40577433aa
commit 19241ed03d
4 changed files with 12 additions and 196 deletions

View File

@ -1499,7 +1499,7 @@ jasmine.PrettyPrinter.prototype.format = function(value) {
} else if (value instanceof jasmine.Matchers.Any) {
this.emitScalar(value.toString());
} else if (typeof value === 'string') {
this.emitScalar(value);
this.emitString(value);
} else if (typeof value === 'function') {
this.emitScalar('Function');
} else if (typeof value.nodeType === 'number') {
@ -1534,6 +1534,7 @@ jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) {
jasmine.PrettyPrinter.prototype.emitArray = jasmine.unimplementedMethod_;
jasmine.PrettyPrinter.prototype.emitObject = jasmine.unimplementedMethod_;
jasmine.PrettyPrinter.prototype.emitScalar = jasmine.unimplementedMethod_;
jasmine.PrettyPrinter.prototype.emitString = jasmine.unimplementedMethod_;
jasmine.StringPrettyPrinter = function() {
jasmine.PrettyPrinter.call(this);
@ -1546,6 +1547,10 @@ jasmine.StringPrettyPrinter.prototype.emitScalar = function(value) {
this.append(value);
};
jasmine.StringPrettyPrinter.prototype.emitString = function(value) {
this.append("'" + value + "'");
};
jasmine.StringPrettyPrinter.prototype.emitArray = function(array) {
this.append('[ ');
for (var i = 0; i < array.length; i++) {

View File

@ -1,48 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Tests</title>
<script type="text/javascript" src="../src/base.js"></script>
<script type="text/javascript" src="../src/util.js"></script>
<script type="text/javascript" src="../src/Env.js"></script>
<script type="text/javascript" src="../src/ActionCollection.js"></script>
<script type="text/javascript" src="../src/Matchers.js"></script>
<script type="text/javascript" src="../src/NestedResults.js"></script>
<script type="text/javascript" src="../src/PrettyPrinter.js"></script>
<script type="text/javascript" src="../src/QueuedFunction.js"></script>
<script type="text/javascript" src="../src/Reporter.js"></script>
<script type="text/javascript" src="../src/Reporters.js"></script>
<script type="text/javascript" src="../src/MultiReporter.js"></script>
<script type="text/javascript" src="../src/Runner.js"></script>
<script type="text/javascript" src="../src/Spec.js"></script>
<script type="text/javascript" src="../src/Suite.js"></script>
<script type="text/javascript" src="../src/mock-timeout.js"></script>
<script type="text/javascript" src="bootstrap.js"></script>
<link type="text/css" rel="stylesheet" href="../lib/jasmine.css"/>
</head>
<body onLoad="runTests();">
<h1>
Running all Jasmine Test Suites
</h1>
<div id="icon_wrapper">
<span id="icons"></span>
<img id="spinner" src="../images/spinner.gif" alt="" />
</div>
<div id="report">
<div id="results_summary" style="display:none;">
<h2>Summary</h2>
</div>
<div id="fails" style="display:none;">
<h2 id="fails_header">Failure Messages</h2>
<div id="fail_messages"></div>
</div>
</div>
<div style="display:none" id="json_reporter_results"></div>
<div style="display:none" id="json_reporter_results_incremental"></div>
</body>
</html>

146
spec/bootstrap.js vendored
View File

@ -1,146 +0,0 @@
var createElement = function(tag, attrs) {
var element = document.createElement(tag);
for (var attr in attrs) {
element[attr] = attrs[attr];
}
return element;
};
// Bootstrap Test Reporter function
var Reporter = function () {
this.total = 0;
this.passes = 0;
this.fails = 0;
this.start = new Date();
};
Reporter.prototype.toJSON = function(object) {
return JSON.stringify(object);
};
Reporter.prototype.test = function (result, message) {
this.total++;
if (result) {
this.passes++;
iconElement = document.getElementById('icons');
iconElement.appendChild(createElement('img', {src: '../images/go-16.png'}));
}
else {
this.fails++;
var fails_report = document.getElementById('fails');
fails_report.style.display = "";
var iconElement = document.getElementById('icons');
iconElement.appendChild(createElement('img', {src: '../images/fail-16.png'}));
var failMessages = document.getElementById('fail_messages');
var newFail = createElement('p', {'class': 'fail'});
newFail.innerHTML = message;
failMessages.appendChild(newFail);
}
};
Reporter.prototype.summary = function () {
var el = createElement('p', {'class': ((this.fails > 0) ? 'fail_in_summary' : '') });
el.innerHTML = this.total + ' expectations, ' + this.passes + ' passing, ' + this.fails + ' failed in ' + (new Date().getTime() - this.start.getTime()) + "ms.";
var summaryElement = document.getElementById('results_summary');
summaryElement.appendChild(el);
summaryElement.style.display = "";
};
var reporter = new Reporter();
function runSuite(filename) {
console.log(filename);
var suite = jasmine.include(filename);
suite.execute();
emitSuiteResults(filename, suite);
}
function emitSpecResults(testName, spec) {
var results = spec.results.getItems();
reporter.test(results.length > 0, testName + ": should have results, got " + results.length);
for (var i = 0; i < results.length; i++) {
reporter.test(results[i].passed === true, testName + ':' + spec.getFullName() + ": expectation number " + i + " failed: " + results[i].message);
}
}
function emitSuiteResults(testName, suite) {
for (var j = 0; j < suite.specs.length; j++) {
var specOrSuite = suite.specs[j];
if (specOrSuite instanceof jasmine.Suite) {
emitSuiteResults(testName, specOrSuite);
} else {
emitSpecResults(testName, specOrSuite);
}
}
}
var testExplodes = function () {
var suite = describe('exploding', function () {
it('should throw an exception when this.explodes is called inside a spec', function() {
var exceptionMessage = false;
try {
this.explodes();
}
catch (e) {
exceptionMessage = e;
}
expect(exceptionMessage).toEqual('explodes function should not have been called');
});
});
suite.execute();
emitSuiteResults('testExplodes', suite);
};
function newJasmineEnv() {
return new jasmine.Env();
}
var testRunner = function() {
};
var testRunnerFinishCallback = function () {
var env = newJasmineEnv();
var foo = 0;
env.currentRunner.finish();
reporter.test((env.currentRunner.finished === true),
"Runner finished flag was not set.");
env.currentRunner.finishCallback = function () {
foo++;
};
env.currentRunner.finish();
reporter.test((env.currentRunner.finished === true),
"Runner finished flag was not set.");
reporter.test((foo === 1),
"Runner finish callback was not called");
};
var runTests = function () {
document.getElementById('spinner').style.display = "";
runSuite('suites/PrettyPrintTest.js');
runSuite('suites/MatchersTest.js');
runSuite('suites/SpecRunningTest.js');
runSuite('suites/NestedResultsTest.js');
runSuite('suites/ReporterTest.js');
runSuite('suites/RunnerTest.js');
runSuite('suites/SpyTest.js');
runSuite('suites/ExceptionsTest.js');
reporter.summary();
document.getElementById('spinner').style.display = "none";
};

View File

@ -28,7 +28,7 @@ jasmine.PrettyPrinter.prototype.format = function(value) {
} else if (value instanceof jasmine.Matchers.Any) {
this.emitScalar(value.toString());
} else if (typeof value === 'string') {
this.emitScalar("'" + value + "'");
this.emitString(value);
} else if (typeof value === 'function') {
this.emitScalar('Function');
} else if (typeof value.nodeType === 'number') {
@ -63,6 +63,7 @@ jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) {
jasmine.PrettyPrinter.prototype.emitArray = jasmine.unimplementedMethod_;
jasmine.PrettyPrinter.prototype.emitObject = jasmine.unimplementedMethod_;
jasmine.PrettyPrinter.prototype.emitScalar = jasmine.unimplementedMethod_;
jasmine.PrettyPrinter.prototype.emitString = jasmine.unimplementedMethod_;
jasmine.StringPrettyPrinter = function() {
jasmine.PrettyPrinter.call(this);
@ -75,6 +76,10 @@ jasmine.StringPrettyPrinter.prototype.emitScalar = function(value) {
this.append(value);
};
jasmine.StringPrettyPrinter.prototype.emitString = function(value) {
this.append("'" + value + "'");
};
jasmine.StringPrettyPrinter.prototype.emitArray = function(array) {
this.append('[ ');
for (var i = 0; i < array.length; i++) {