From 1df1de2bb7bde9a31ab046df7d4c0eb3d0a231fd Mon Sep 17 00:00:00 2001 From: pivotal Date: Tue, 2 Dec 2008 13:59:39 -0800 Subject: [PATCH] dwf/rva: results now propagated up. --- jasmine.iws | 18 +++--- lib/jasmine.js | 47 ++++++++++++++-- test/bootstrap.js | 137 +++++++++++++++++++++++++++++++++++++--------- 3 files changed, 161 insertions(+), 41 deletions(-) diff --git a/jasmine.iws b/jasmine.iws index ccf5cf4..c5402ca 100644 --- a/jasmine.iws +++ b/jasmine.iws @@ -80,7 +80,7 @@ - + @@ -92,7 +92,7 @@ - + @@ -101,7 +101,7 @@ - + @@ -110,7 +110,7 @@ - + @@ -313,7 +313,7 @@ - + @@ -434,7 +434,7 @@ - + @@ -444,21 +444,21 @@ - + - + - + diff --git a/lib/jasmine.js b/lib/jasmine.js index 96156ee..4ae9f74 100755 --- a/lib/jasmine.js +++ b/lib/jasmine.js @@ -23,6 +23,11 @@ var actionCollection = function () { actions: [], index: 0, finished: false, + results: nestedResults(), + + report: function (result) { + that.results.push(result); + }, execute: function () { if (that.actions.length > 0) { @@ -48,6 +53,7 @@ var actionCollection = function () { var id = setInterval(function () { if (action.finished) { clearInterval(id); + that.report(action.results); that.index++; that.next(); } @@ -68,7 +74,7 @@ var actionCollection = function () { Matchers = function (actual, results) { this.actual = actual; this.passing_message = 'Passed.' - this.results = results || []; + this.results = results || nestedResults(); } Matchers.method('report', function (result, failing_message) { @@ -117,6 +123,33 @@ var queuedFunction = function(func, timeout, spec) { return that; } +var nestedResults = function() { + var that = { + totalCount: 0, + passedCount: 0, + failedCount: 0, + results: [], + + push: function(result) { + if (result.results) { + that.totalCount += result.totalCount; + that.passedCount += result.passedCount; + that.failedCount += result.failedCount; + + } else { + that.totalCount++; + if (result.passed) { + that.passedCount++; + } else { + that.failedCount++; + } + } + that.results.push(result); + } + } + + return that; +} var it = function (description, func) { var that = { @@ -124,9 +157,12 @@ var it = function (description, func) { queue: [], currentTimeout: 0, finished: false, - suite: {next:function() { - }}, - results: [], + +// suite: { +// next: function() { +// }}, + + results: nestedResults(), expects_that: function (actual) { return new Matchers(actual, that.results); @@ -208,6 +244,7 @@ var Jasmine = function () { var that = actionCollection(); that.suites = that.actions; + currentRunner = that; return that; } @@ -227,7 +264,7 @@ var currentSpec; * - Suite supports after * - Suite supports before_each * - Suite supports after_each - * - Suite rolls up spec results + //* - Suite rolls up spec results //* - Suite supports asynch //* - Runner that runs suites in order // * - Runner supports async diff --git a/test/bootstrap.js b/test/bootstrap.js index 93f0439..0a96063 100755 --- a/test/bootstrap.js +++ b/test/bootstrap.js @@ -31,7 +31,7 @@ var reporter = function () { summary: function () { summary = new Element('p', {'class': ((fails > 0) ? 'fail_in_summary' : '') }); - summary.innerHTML = total + ' tests, ' + passes + ' passing, ' + fails + ' failed.'; + summary.innerHTML = total + ' expectations, ' + passes + ' passing, ' + fails + ' failed.'; var summaryElement = $('results_summary'); summaryElement.appendChild(summary); @@ -102,9 +102,9 @@ var testSpecs = function () { another_spec.execute(); another_spec.done = true; - reporter.test((another_spec.results.length == 1), + reporter.test((another_spec.results.results.length == 1), "Results aren't there after a spec was executed"); - reporter.test((another_spec.results[0].passed == true), + reporter.test((another_spec.results.results[0].passed == true), "Results has a result, but it's true"); var yet_another_spec = it('spec with failing expectation').runs(function () { @@ -114,7 +114,7 @@ var testSpecs = function () { yet_another_spec.execute(); yet_another_spec.done = true; - reporter.test((yet_another_spec.results[0].passed == false), + reporter.test((yet_another_spec.results.results[0].passed == false), "Expectation that failed, passed"); var yet_yet_another_spec = it('spec with multiple assertions').runs(function () { @@ -127,7 +127,7 @@ var testSpecs = function () { yet_yet_another_spec.execute(); yet_yet_another_spec.done = true; - reporter.test((yet_yet_another_spec.results.length == 2), + reporter.test((yet_yet_another_spec.results.results.length == 2), "Spec doesn't support multiple expectations"); } @@ -154,9 +154,9 @@ var testAsyncSpecs = function () { a_spec.execute(); - reporter.test((a_spec.results.length === 1), + reporter.test((a_spec.results.results.length === 1), 'No call to waits(): Spec queue did not run all functions'); - reporter.test((a_spec.results[0].passed === true), + reporter.test((a_spec.results.results[0].passed === true), 'No call to waits(): Queued expectation failed'); foo = 0; @@ -172,10 +172,10 @@ var testAsyncSpecs = function () { var mockSuite = { next: function() { - reporter.test((a_spec.results.length === 1), + reporter.test((a_spec.results.results.length === 1), 'Calling waits(): Spec queue did not run all functions'); - reporter.test((a_spec.results[0].passed === true), + reporter.test((a_spec.results.results[0].passed === true), 'Calling waits(): Queued expectation failed'); } }; @@ -203,9 +203,9 @@ var testAsyncSpecs = function () { next: function() { reporter.test((another_spec.queue.length === 3), 'Calling 2 waits(): Spec queue was less than expected length'); - reporter.test((another_spec.results.length === 1), + reporter.test((another_spec.results.results.length === 1), 'Calling 2 waits(): Spec queue did not run all functions'); - reporter.test((another_spec.results[0].passed === true), + reporter.test((another_spec.results.results[0].passed === true), 'Calling 2 waits(): Queued expectation failed'); } }; @@ -229,9 +229,9 @@ var testAsyncSpecs = function () { reporter.test((yet_another_spec.queue.length === 2), 'Calling 2 waits(): Spec queue was less than expected length'); - reporter.test((yet_another_spec.results.length === 1), + reporter.test((yet_another_spec.results.results.length === 1), 'Calling 2 waits(): Spec queue did not run all functions'); - reporter.test((yet_another_spec.results[0].passed === false), + reporter.test((yet_another_spec.results.results[0].passed === false), 'Calling 2 waits(): Queued expectation failed'); } }; @@ -263,9 +263,9 @@ var testAsyncSpecsWithMockSuite = function () { next: function () { reporter.test((another_spec.queue.length === 3), 'Calling 2 waits(): Spec queue was less than expected length'); - reporter.test((another_spec.results.length === 1), + reporter.test((another_spec.results.results.length === 1), 'Calling 2 waits(): Spec queue did not run all functions'); - reporter.test((another_spec.results[0].passed === true), + reporter.test((another_spec.results.results[0].passed === true), 'Calling 2 waits(): Queued expectation failed'); } }; @@ -330,7 +330,6 @@ var testSuites = function () { reporter.test((suite.specs[0].queue.length === 2), "Suite's spec did not get 2 functions pushed"); - var foo = 0; suite = describe('one suite description', function () { it('should be a test with queuedFunctions', function() { @@ -390,11 +389,11 @@ var testSpecScope = function () { setTimeout(function () { reporter.test((suite.specs[0].foo === 2), "Spec does not maintain scope in between functions"); - reporter.test((suite.specs[0].results.length === 2), + reporter.test((suite.specs[0].results.results.length === 2), "Spec did not get results for all expectations"); - reporter.test((suite.specs[0].results[0].passed === false), + reporter.test((suite.specs[0].results.results[0].passed === false), "Spec did not return false for a failed expectation"); - reporter.test((suite.specs[0].results[1].passed === true), + reporter.test((suite.specs[0].results.results[1].passed === true), "Spec did not return true for a passing expectation"); }, 1000); } @@ -441,24 +440,108 @@ var testRunner = function() { setTimeout(function () { reporter.test((runner.suites.length === 2), "Runner expected two suites"); - reporter.test((runner.suites[0].specs[0].results[0].passed === true), + reporter.test((runner.suites[0].specs[0].results.results[0].passed === true), "Runner should have run specs in first suite"); - reporter.test((runner.suites[1].specs[0].results[0].passed === false), + reporter.test((runner.suites[1].specs[0].results.results[0].passed === false), "Runner should have run specs in second suite"); }, 1000); } +var testNestedResults = function () { + + // Leaf case + var results = nestedResults(); + + results.push({passed: true, message: 'Passed.'}); + + reporter.test((results.results.length === 1), + "nestedResults.push didn't work"); + reporter.test((results.totalCount === 1), + "nestedResults.push didn't increment totalCount"); + reporter.test((results.passedCount === 1), + "nestedResults.push didn't increment passedCount"); + reporter.test((results.failedCount === 0), + "nestedResults.push didn't ignore failedCount"); + + results.push({passed: false, message: 'FAIL.'}); + + reporter.test((results.results.length === 2), + "nestedResults.push didn't work"); + reporter.test((results.totalCount === 2), + "nestedResults.push didn't increment totalCount"); + reporter.test((results.passedCount === 1), + "nestedResults.push didn't ignore passedCount"); + reporter.test((results.failedCount === 1), + "nestedResults.push didn't increment failedCount"); + + // Branch case + var leafResultsOne = nestedResults(); + leafResultsOne.push({passed: true, message: ''}); + leafResultsOne.push({passed: false, message: ''}); + + var leafResultsTwo = nestedResults(); + leafResultsTwo.push({passed: true, message: ''}); + leafResultsTwo.push({passed: false, message: ''}); + + var branchResults = nestedResults(); + branchResults.push(leafResultsOne); + branchResults.push(leafResultsTwo); + + reporter.test((branchResults.results.length === 2), + "Branch Results should have 2 nestedResults, has " + branchResults.results.length); + reporter.test((branchResults.totalCount === 4), + "Branch Results should have 4 results, has " + branchResults.totalCount); + reporter.test((branchResults.passedCount === 2), + "Branch Results should have 2 passed, has " + branchResults.passedCount); + reporter.test((branchResults.failedCount === 2), + "Branch Results should have 2 failed, has " + branchResults.failedCount); + +} + +var testReporting = function () { + var runner = Jasmine(); + describe('one suite description', function () { + it('should be a test', function() { + runs(function () { + this.expects_that(true).should_equal(true); + }); + }); + }); + + describe('another suite description', function () { + it('should be another test', function() { + runs(function () { + this.expects_that(true).should_equal(false); + }); + }); + }); + + runner.execute(); + + setTimeout(function () { + reporter.test((runner.results.totalCount === 2), + 'Expectation count should be 2, but was ' + runner.results.totalCount); + reporter.test((runner.results.passedCount === 1), + 'Expectation Passed count should be 1, but was ' + runner.results.passedCount); + reporter.test((runner.results.failedCount === 1), + 'Expectation Failed count should be 1, but was ' + runner.results.failedCount); + }, 1000); + +} + var runTests = function () { $('spinner').show(); testMatchersComparisons(); - testMatchersReporting(); - testSpecs(); - testAsyncSpecs(); - testAsyncSpecsWithMockSuite(); - testSuites(); - testSpecScope(); + testMatchersReporting(); + testSpecs(); + testAsyncSpecs(); + testAsyncSpecsWithMockSuite(); + testSuites(); + testSpecScope(); testRunner(); + testNestedResults(); + testReporting(); setTimeout(function() { $('spinner').hide();