From 19241ed03df9a5a8af1d80aa04836391b256dd44 Mon Sep 17 00:00:00 2001 From: pivotal Date: Wed, 29 Jul 2009 11:33:23 -0700 Subject: [PATCH] carl/bosh - killed bootstrap dead; refactored to have emitString for use by subclasses. --- lib/jasmine.js | 7 ++- spec/bootstrap.html | 48 -------------- spec/bootstrap.js | 146 ------------------------------------------- src/PrettyPrinter.js | 7 ++- 4 files changed, 12 insertions(+), 196 deletions(-) delete mode 100755 spec/bootstrap.html delete mode 100755 spec/bootstrap.js diff --git a/lib/jasmine.js b/lib/jasmine.js index a9c2390b..63ef64b3 100644 --- a/lib/jasmine.js +++ b/lib/jasmine.js @@ -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++) { diff --git a/spec/bootstrap.html b/spec/bootstrap.html deleted file mode 100755 index cac38e95..00000000 --- a/spec/bootstrap.html +++ /dev/null @@ -1,48 +0,0 @@ - - - - Jasmine Tests - - - - - - - - - - - - - - - - - - - - - -

- Running all Jasmine Test Suites -

-
- - -
-
- - -
- - - - - - diff --git a/spec/bootstrap.js b/spec/bootstrap.js deleted file mode 100755 index 342b10e5..00000000 --- a/spec/bootstrap.js +++ /dev/null @@ -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"; -}; \ No newline at end of file diff --git a/src/PrettyPrinter.js b/src/PrettyPrinter.js index 9d8f4f96..ff793a91 100644 --- a/src/PrettyPrinter.js +++ b/src/PrettyPrinter.js @@ -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++) {