diff --git a/contrib/ruby/jasmine_runner.rb b/contrib/ruby/jasmine_runner.rb index 61ff5e0..dee3b71 100644 --- a/contrib/ruby/jasmine_runner.rb +++ b/contrib/ruby/jasmine_runner.rb @@ -165,8 +165,8 @@ module Jasmine sleep 0.1 end - puts @driver.get_eval("window.getResults()") - failed_count = @driver.get_eval("window.jasmine.getEnv().currentRunner.getResults().failedCount").to_i + puts @driver.get_eval("window.results()") + failed_count = @driver.get_eval("window.jasmine.getEnv().currentRunner.results().failedCount").to_i failed_count == 0 end diff --git a/contrib/ruby/jasmine_spec_builder.rb b/contrib/ruby/jasmine_spec_builder.rb index 4a6e902..ab3ee11 100644 --- a/contrib/ruby/jasmine_spec_builder.rb +++ b/contrib/ruby/jasmine_spec_builder.rb @@ -57,17 +57,17 @@ module Jasmine sleep 0.1 end - @suites = eval_js('JSON.stringify(jsApiReporter.suites)') + @suites = eval_js('JSON.stringify(jsApiReporter.suites())') end def results_for(spec_id) spec_id = spec_id.to_s return @spec_results[spec_id] if @spec_results[spec_id] - @spec_results[spec_id] = eval_js("JSON.stringify(jsApiReporter.results[#{spec_id}])") + @spec_results[spec_id] = eval_js("JSON.stringify(jsApiReporter.resultsForSpec(#{spec_id}))") while @spec_results[spec_id].nil? do sleep 0.1 - @spec_results[spec_id] = eval_js("JSON.stringify(jsApiReporter.results[#{spec_id}])") + @spec_results[spec_id] = eval_js("JSON.stringify(jsApiReporter.resultsForSpec(#{spec_id}))") end @spec_results[spec_id] diff --git a/doc/files.html b/doc/files.html index 5d4b5dd..11410a1 100644 --- a/doc/files.html +++ b/doc/files.html @@ -258,7 +258,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Sep 09 2009 18:14:14 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
\ No newline at end of file diff --git a/doc/index.html b/doc/index.html index 79b65b3..1fadab8 100644 --- a/doc/index.html +++ b/doc/index.html @@ -300,7 +300,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Sep 09 2009 18:14:14 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
\ No newline at end of file diff --git a/doc/symbols/_global_.html b/doc/symbols/_global_.html index 5eb02fd..562431d 100644 --- a/doc/symbols/_global_.html +++ b/doc/symbols/_global_.html @@ -908,7 +908,7 @@ A convenience method that allows existing specs to be disabled temporarily durin
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Sep 09 2009 18:14:14 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Block.html b/doc/symbols/jasmine.Block.html index 4ab35b8..904f176 100644 --- a/doc/symbols/jasmine.Block.html +++ b/doc/symbols/jasmine.Block.html @@ -339,7 +339,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Sep 09 2009 18:14:14 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Env.html b/doc/symbols/jasmine.Env.html index 114e039..e850c9c 100644 --- a/doc/symbols/jasmine.Env.html +++ b/doc/symbols/jasmine.Env.html @@ -288,6 +288,33 @@ ul.inheritsList + +   + +
nextSpecId() +
+
+ + + + +   + +
nextSuiteId() +
+
+ + + + +   + +
version() +
+
+ + + @@ -370,6 +397,102 @@ ul.inheritsList +
+ + +
+ + + nextSpecId() + +
+
+ + + +
+ + + + + + + + +
+
Returns:
+ +
a sequential integer starting at 0
+ +
+ + + + +
+ + +
+ + + nextSuiteId() + +
+
+ + + +
+ + + + + + + + +
+
Returns:
+ +
a sequential integer starting at 0
+ +
+ + + + +
+ + +
+ + + version() + +
+
+ + + +
+ + + + + + + + +
+
Returns:
+ +
an object containing jasmine version build info, if set.
+ +
+ + + + @@ -384,7 +507,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Sep 09 2009 18:14:14 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.JsApiReporter.html b/doc/symbols/jasmine.JsApiReporter.html index 02a653a..ff64c78 100644 --- a/doc/symbols/jasmine.JsApiReporter.html +++ b/doc/symbols/jasmine.JsApiReporter.html @@ -316,7 +316,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Sep 09 2009 18:14:14 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.MultiReporter.html b/doc/symbols/jasmine.MultiReporter.html index 659a7e5..4b29098 100644 --- a/doc/symbols/jasmine.MultiReporter.html +++ b/doc/symbols/jasmine.MultiReporter.html @@ -316,7 +316,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Sep 09 2009 18:14:14 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.NestedResults.html b/doc/symbols/jasmine.NestedResults.html index d0719e1..cbd9d73 100644 --- a/doc/symbols/jasmine.NestedResults.html +++ b/doc/symbols/jasmine.NestedResults.html @@ -700,7 +700,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Sep 09 2009 18:14:14 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Reporter.html b/doc/symbols/jasmine.Reporter.html index 74f6508..3a54b0f 100644 --- a/doc/symbols/jasmine.Reporter.html +++ b/doc/symbols/jasmine.Reporter.html @@ -316,7 +316,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Sep 09 2009 18:14:14 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Runner.html b/doc/symbols/jasmine.Runner.html index e70264a..7afa212 100644 --- a/doc/symbols/jasmine.Runner.html +++ b/doc/symbols/jasmine.Runner.html @@ -288,6 +288,15 @@ ul.inheritsList + +   + +
getResults() +
+
+ + + @@ -370,6 +379,31 @@ ul.inheritsList +
+ + +
+ + + getResults() + +
+
+ + + +
+ + + + + + + + + + + @@ -384,7 +418,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Sep 09 2009 18:14:14 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Spec.html b/doc/symbols/jasmine.Spec.html index 0f86075..6629e1d 100644 --- a/doc/symbols/jasmine.Spec.html +++ b/doc/symbols/jasmine.Spec.html @@ -267,6 +267,33 @@ ul.inheritsList + + + + + + + + + + + + + + + + + + +
Method Summary
Method AttributesMethod Name and Description
  + +
+
+ + + + @@ -328,6 +355,36 @@ ul.inheritsList +
+ Method Detail +
+ + +
+ + + getResults() + +
+
+ + + +
+ + + + + + + + + + + + + + @@ -339,7 +396,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Sep 09 2009 18:14:14 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Spy.html b/doc/symbols/jasmine.Spy.html index 69f0223..2607bf1 100644 --- a/doc/symbols/jasmine.Spy.html +++ b/doc/symbols/jasmine.Spy.html @@ -845,7 +845,7 @@ expect(foo.bar.callCount).toEqual(0);
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Sep 09 2009 18:14:14 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.Suite.html b/doc/symbols/jasmine.Suite.html index ebbd170..b8a3775 100644 --- a/doc/symbols/jasmine.Suite.html +++ b/doc/symbols/jasmine.Suite.html @@ -279,6 +279,15 @@ ul.inheritsList + +   + +
getResults() +
+
+ + +   @@ -365,6 +374,31 @@ ul.inheritsList Method Detail + +
+ + + getResults() + +
+
+ + + +
+ + + + + + + + + + + +
+
@@ -402,7 +436,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Sep 09 2009 18:14:14 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.html b/doc/symbols/jasmine.html index a1b66d8..3d4227f 100644 --- a/doc/symbols/jasmine.html +++ b/doc/symbols/jasmine.html @@ -678,7 +678,7 @@ Jasmine environment.
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Sep 09 2009 18:14:14 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
diff --git a/doc/symbols/jasmine.util.html b/doc/symbols/jasmine.util.html index f17cc42..7e04f24 100644 --- a/doc/symbols/jasmine.util.html +++ b/doc/symbols/jasmine.util.html @@ -316,7 +316,7 @@ ul.inheritsList
- Documentation generated by JsDoc Toolkit 2.1.0 on Wed Sep 09 2009 18:14:14 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Mon Sep 28 2009 11:12:11 GMT-0700 (PDT)
diff --git a/doc/symbols/src/lib_TrivialReporter.js.html b/doc/symbols/src/lib_TrivialReporter.js.html index b04a52d..32a15cb 100644 --- a/doc/symbols/src/lib_TrivialReporter.js.html +++ b/doc/symbols/src/lib_TrivialReporter.js.html @@ -59,7 +59,7 @@ 52 }; 53 54 jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) { - 55 var results = runner.getResults(); + 55 var results = runner.results(); 56 var className = (results.failedCount > 0) ? "runner failed" : "runner passed"; 57 this.runnerDiv.setAttribute("class", className); 58 var message = results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s"); @@ -68,7 +68,7 @@ 61 }; 62 63 jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) { - 64 var results = suite.getResults(); + 64 var results = suite.results(); 65 var status = results.passed() ? 'passed' : 'failed'; 66 if (results.totalCount == 0) { // todo: change this to check results.skipped 67 status = 'skipped'; @@ -77,7 +77,7 @@ 70 }; 71 72 jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) { - 73 var results = spec.getResults(); + 73 var results = spec.results(); 74 var status = results.passed() ? 'passed' : 'failed'; 75 if (results.skipped) { 76 status = 'skipped'; diff --git a/doc/symbols/src/lib_jasmine-0.9.0.js.html b/doc/symbols/src/lib_jasmine-0.9.0.js.html index bc1ee18..e35deae 100644 --- a/doc/symbols/src/lib_jasmine-0.9.0.js.html +++ b/doc/symbols/src/lib_jasmine-0.9.0.js.html @@ -330,7 +330,7 @@ 323 }; 324 325 jasmine.log = function(message) { -326 jasmine.getEnv().currentSpec.getResults().log(message); +326 jasmine.getEnv().currentSpec.log(message); 327 }; 328 329 /** @@ -524,7 +524,7 @@ 517 "major": 0, 518 "minor": 9, 519 "build": 0, -520 "revision": 1252545239 +520 "revision": 1254161493 521 }; 522 /** 523 * @namespace @@ -617,1426 +617,1479 @@ 610 jasmine.Env.prototype.setInterval = jasmine.setInterval; 611 jasmine.Env.prototype.clearInterval = jasmine.clearInterval; 612 -613 jasmine.Env.prototype.version = function () { -614 if (jasmine.version_) { -615 return jasmine.version_; -616 } else { -617 throw new Error('Version not set'); -618 } -619 }; -620 -621 /** -622 * Register a reporter to receive status updates from Jasmine. -623 * @param {jasmine.Reporter} reporter An object which will receive status updates. -624 */ -625 jasmine.Env.prototype.addReporter = function(reporter) { -626 this.reporter.addReporter(reporter); -627 }; -628 -629 jasmine.Env.prototype.execute = function() { -630 this.currentRunner.execute(); -631 }; -632 -633 jasmine.Env.prototype.describe = function(description, specDefinitions) { -634 var suite = new jasmine.Suite(this, description, specDefinitions, this.currentSuite); -635 -636 var parentSuite = this.currentSuite; -637 if (parentSuite) { -638 parentSuite.add(suite); -639 } else { -640 this.currentRunner.add(suite); -641 } -642 -643 this.currentSuite = suite; -644 -645 specDefinitions.call(suite); -646 -647 this.currentSuite = parentSuite; -648 -649 return suite; -650 }; -651 -652 jasmine.Env.prototype.beforeEach = function(beforeEachFunction) { -653 this.currentSuite.beforeEach(beforeEachFunction); -654 }; -655 -656 jasmine.Env.prototype.afterEach = function(afterEachFunction) { -657 this.currentSuite.afterEach(afterEachFunction); -658 }; +613 /** +614 * @returns an object containing jasmine version build info, if set. +615 */ +616 jasmine.Env.prototype.version = function () { +617 if (jasmine.version_) { +618 return jasmine.version_; +619 } else { +620 throw new Error('Version not set'); +621 } +622 }; +623 +624 /** +625 * @returns a sequential integer starting at 0 +626 */ +627 jasmine.Env.prototype.nextSpecId = function () { +628 return this.nextSpecId_++; +629 }; +630 +631 /** +632 * @returns a sequential integer starting at 0 +633 */ +634 jasmine.Env.prototype.nextSuiteId = function () { +635 return this.nextSuiteId_++; +636 }; +637 +638 /** +639 * Register a reporter to receive status updates from Jasmine. +640 * @param {jasmine.Reporter} reporter An object which will receive status updates. +641 */ +642 jasmine.Env.prototype.addReporter = function(reporter) { +643 this.reporter.addReporter(reporter); +644 }; +645 +646 jasmine.Env.prototype.execute = function() { +647 this.currentRunner.execute(); +648 }; +649 +650 jasmine.Env.prototype.describe = function(description, specDefinitions) { +651 var suite = new jasmine.Suite(this, description, specDefinitions, this.currentSuite); +652 +653 var parentSuite = this.currentSuite; +654 if (parentSuite) { +655 parentSuite.add(suite); +656 } else { +657 this.currentRunner.add(suite); +658 } 659 -660 jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) { -661 return { -662 execute: function() { -663 } -664 }; -665 }; -666 -667 jasmine.Env.prototype.it = function(description, func) { -668 var spec = new jasmine.Spec(this, this.currentSuite, description); -669 this.currentSuite.add(spec); -670 this.currentSpec = spec; -671 -672 if (func) { -673 spec.runs(func); -674 } -675 -676 return spec; -677 }; -678 -679 jasmine.Env.prototype.xit = function(desc, func) { -680 return { -681 id: this.nextSpecId_++, -682 runs: function() { -683 } -684 }; -685 }; -686 -687 jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) { -688 if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) { -689 return true; -690 } -691 -692 a.__Jasmine_been_here_before__ = b; -693 b.__Jasmine_been_here_before__ = a; -694 -695 var hasKey = function(obj, keyName) { -696 return obj != null && obj[keyName] !== undefined; -697 }; -698 -699 for (var property in b) { -700 if (!hasKey(a, property) && hasKey(b, property)) { -701 mismatchKeys.push("expected has key '" + property + "', but missing from <b>actual</b>."); -702 } -703 } -704 for (property in a) { -705 if (!hasKey(b, property) && hasKey(a, property)) { -706 mismatchKeys.push("<b>expected</b> missing key '" + property + "', but present in actual."); -707 } -708 } -709 for (property in b) { -710 if (property == '__Jasmine_been_here_before__') continue; -711 if (!this.equals_(a[property], b[property], mismatchKeys, mismatchValues)) { -712 mismatchValues.push("'" + property + "' was<br /><br />'" + (b[property] ? jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "'<br /><br />in expected, but was<br /><br />'" + (a[property] ? jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "'<br /><br />in actual.<br />"); -713 } -714 } +660 this.currentSuite = suite; +661 +662 specDefinitions.call(suite); +663 +664 this.currentSuite = parentSuite; +665 +666 return suite; +667 }; +668 +669 jasmine.Env.prototype.beforeEach = function(beforeEachFunction) { +670 this.currentSuite.beforeEach(beforeEachFunction); +671 }; +672 +673 jasmine.Env.prototype.afterEach = function(afterEachFunction) { +674 this.currentSuite.afterEach(afterEachFunction); +675 }; +676 +677 jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) { +678 return { +679 execute: function() { +680 } +681 }; +682 }; +683 +684 jasmine.Env.prototype.it = function(description, func) { +685 var spec = new jasmine.Spec(this, this.currentSuite, description); +686 this.currentSuite.add(spec); +687 this.currentSpec = spec; +688 +689 if (func) { +690 spec.runs(func); +691 } +692 +693 return spec; +694 }; +695 +696 jasmine.Env.prototype.xit = function(desc, func) { +697 return { +698 id: this.nextSpecId(), +699 runs: function() { +700 } +701 }; +702 }; +703 +704 jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) { +705 if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) { +706 return true; +707 } +708 +709 a.__Jasmine_been_here_before__ = b; +710 b.__Jasmine_been_here_before__ = a; +711 +712 var hasKey = function(obj, keyName) { +713 return obj != null && obj[keyName] !== undefined; +714 }; 715 -716 if (jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) { -717 mismatchValues.push("arrays were not the same length"); -718 } -719 -720 delete a.__Jasmine_been_here_before__; -721 delete b.__Jasmine_been_here_before__; -722 return (mismatchKeys.length == 0 && mismatchValues.length == 0); -723 }; -724 -725 jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) { -726 mismatchKeys = mismatchKeys || []; -727 mismatchValues = mismatchValues || []; -728 -729 if (a === b) return true; -730 -731 if (a === undefined || a === null || b === undefined || b === null) { -732 return (a == undefined && b == undefined); -733 } -734 -735 if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) { -736 return a === b; -737 } -738 -739 if (a instanceof Date && b instanceof Date) { -740 return a.getTime() == b.getTime(); -741 } -742 -743 if (a instanceof jasmine.Matchers.Any) { -744 return a.matches(b); -745 } -746 -747 if (b instanceof jasmine.Matchers.Any) { -748 return b.matches(a); -749 } -750 -751 if (typeof a === "object" && typeof b === "object") { -752 return this.compareObjects_(a, b, mismatchKeys, mismatchValues); -753 } -754 -755 for (var i = 0; i < this.equalityTesters_.length; i++) { -756 var equalityTester = this.equalityTesters_[i]; -757 var result = equalityTester(a, b, this, mismatchKeys, mismatchValues); -758 if (result !== undefined) return result; -759 } -760 -761 //Straight check -762 return (a === b); -763 }; -764 -765 jasmine.Env.prototype.contains_ = function(haystack, needle) { -766 if (jasmine.isArray_(haystack)) { -767 for (var i = 0; i < haystack.length; i++) { -768 if (this.equals_(haystack[i], needle)) return true; -769 } -770 return false; -771 } -772 return haystack.indexOf(needle) >= 0; -773 }; -774 -775 jasmine.Env.prototype.addEqualityTester = function(equalityTester) { -776 this.equalityTesters_.push(equalityTester); -777 }; -778 /** No-op base class for Jasmine reporters. -779 * -780 * @constructor -781 */ -782 jasmine.Reporter = function() { -783 }; -784 -785 //noinspection JSUnusedLocalSymbols -786 jasmine.Reporter.prototype.reportRunnerStarting = function(runner) { -787 }; -788 -789 //noinspection JSUnusedLocalSymbols -790 jasmine.Reporter.prototype.reportRunnerResults = function(runner) { -791 }; -792 -793 //noinspection JSUnusedLocalSymbols -794 jasmine.Reporter.prototype.reportSuiteResults = function(suite) { -795 }; -796 -797 //noinspection JSUnusedLocalSymbols -798 jasmine.Reporter.prototype.reportSpecResults = function(spec) { -799 }; -800 -801 //noinspection JSUnusedLocalSymbols -802 jasmine.Reporter.prototype.log = function(str) { -803 }; -804 -805 /** -806 * Blocks are functions with executable code that make up a spec. -807 * -808 * @constructor -809 * @param {jasmine.Env} env -810 * @param {Function} func -811 * @param {jasmine.Spec} spec -812 */ -813 jasmine.Block = function(env, func, spec) { -814 this.env = env; -815 this.func = func; -816 this.spec = spec; -817 }; -818 -819 jasmine.Block.prototype.execute = function(onComplete) { -820 try { -821 this.func.apply(this.spec); -822 } catch (e) { -823 this.fail(e); -824 } -825 onComplete(); -826 }; -827 -828 jasmine.Block.prototype.fail = function(e) { -829 this.spec.results.addResult(new jasmine.ExpectationResult(false, jasmine.util.formatException(e), null)); -830 }; -831 /** JavaScript API reporter. -832 * -833 * @constructor -834 */ -835 jasmine.JsApiReporter = function() { -836 this.started = false; -837 this.finished = false; -838 this.suites = []; -839 this.results = {}; -840 }; -841 -842 jasmine.JsApiReporter.prototype.reportRunnerStarting = function(runner) { -843 this.started = true; -844 var suites = runner.suites(); -845 for (var i = 0; i < suites.length; i++) { -846 var suite = suites[i]; -847 this.suites.push(this.summarize_(suite)); -848 } -849 }; -850 -851 jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) { -852 var isSuite = suiteOrSpec instanceof jasmine.Suite -853 var summary = { -854 id: suiteOrSpec.id, -855 name: suiteOrSpec.description, -856 type: isSuite ? 'suite' : 'spec', -857 children: [] -858 }; -859 if (isSuite) { -860 var specs = suiteOrSpec.specs(); -861 for (var i = 0; i < specs.length; i++) { -862 summary.children.push(this.summarize_(specs[i])); -863 } -864 } -865 return summary; +716 for (var property in b) { +717 if (!hasKey(a, property) && hasKey(b, property)) { +718 mismatchKeys.push("expected has key '" + property + "', but missing from <b>actual</b>."); +719 } +720 } +721 for (property in a) { +722 if (!hasKey(b, property) && hasKey(a, property)) { +723 mismatchKeys.push("<b>expected</b> missing key '" + property + "', but present in actual."); +724 } +725 } +726 for (property in b) { +727 if (property == '__Jasmine_been_here_before__') continue; +728 if (!this.equals_(a[property], b[property], mismatchKeys, mismatchValues)) { +729 mismatchValues.push("'" + property + "' was<br /><br />'" + (b[property] ? jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "'<br /><br />in expected, but was<br /><br />'" + (a[property] ? jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "'<br /><br />in actual.<br />"); +730 } +731 } +732 +733 if (jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) { +734 mismatchValues.push("arrays were not the same length"); +735 } +736 +737 delete a.__Jasmine_been_here_before__; +738 delete b.__Jasmine_been_here_before__; +739 return (mismatchKeys.length == 0 && mismatchValues.length == 0); +740 }; +741 +742 jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) { +743 mismatchKeys = mismatchKeys || []; +744 mismatchValues = mismatchValues || []; +745 +746 if (a === b) return true; +747 +748 if (a === undefined || a === null || b === undefined || b === null) { +749 return (a == undefined && b == undefined); +750 } +751 +752 if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) { +753 return a === b; +754 } +755 +756 if (a instanceof Date && b instanceof Date) { +757 return a.getTime() == b.getTime(); +758 } +759 +760 if (a instanceof jasmine.Matchers.Any) { +761 return a.matches(b); +762 } +763 +764 if (b instanceof jasmine.Matchers.Any) { +765 return b.matches(a); +766 } +767 +768 if (typeof a === "object" && typeof b === "object") { +769 return this.compareObjects_(a, b, mismatchKeys, mismatchValues); +770 } +771 +772 for (var i = 0; i < this.equalityTesters_.length; i++) { +773 var equalityTester = this.equalityTesters_[i]; +774 var result = equalityTester(a, b, this, mismatchKeys, mismatchValues); +775 if (result !== undefined) return result; +776 } +777 +778 //Straight check +779 return (a === b); +780 }; +781 +782 jasmine.Env.prototype.contains_ = function(haystack, needle) { +783 if (jasmine.isArray_(haystack)) { +784 for (var i = 0; i < haystack.length; i++) { +785 if (this.equals_(haystack[i], needle)) return true; +786 } +787 return false; +788 } +789 return haystack.indexOf(needle) >= 0; +790 }; +791 +792 jasmine.Env.prototype.addEqualityTester = function(equalityTester) { +793 this.equalityTesters_.push(equalityTester); +794 }; +795 /** No-op base class for Jasmine reporters. +796 * +797 * @constructor +798 */ +799 jasmine.Reporter = function() { +800 }; +801 +802 //noinspection JSUnusedLocalSymbols +803 jasmine.Reporter.prototype.reportRunnerStarting = function(runner) { +804 }; +805 +806 //noinspection JSUnusedLocalSymbols +807 jasmine.Reporter.prototype.reportRunnerResults = function(runner) { +808 }; +809 +810 //noinspection JSUnusedLocalSymbols +811 jasmine.Reporter.prototype.reportSuiteResults = function(suite) { +812 }; +813 +814 //noinspection JSUnusedLocalSymbols +815 jasmine.Reporter.prototype.reportSpecResults = function(spec) { +816 }; +817 +818 //noinspection JSUnusedLocalSymbols +819 jasmine.Reporter.prototype.log = function(str) { +820 }; +821 +822 /** +823 * Blocks are functions with executable code that make up a spec. +824 * +825 * @constructor +826 * @param {jasmine.Env} env +827 * @param {Function} func +828 * @param {jasmine.Spec} spec +829 */ +830 jasmine.Block = function(env, func, spec) { +831 this.env = env; +832 this.func = func; +833 this.spec = spec; +834 }; +835 +836 jasmine.Block.prototype.execute = function(onComplete) { +837 try { +838 this.func.apply(this.spec); +839 } catch (e) { +840 this.spec.fail(e); +841 } +842 onComplete(); +843 }; +844 /** JavaScript API reporter. +845 * +846 * @constructor +847 */ +848 jasmine.JsApiReporter = function() { +849 this.started = false; +850 this.finished = false; +851 this.suites_ = []; +852 this.results_ = {}; +853 }; +854 +855 jasmine.JsApiReporter.prototype.reportRunnerStarting = function(runner) { +856 this.started = true; +857 var suites = runner.suites(); +858 for (var i = 0; i < suites.length; i++) { +859 var suite = suites[i]; +860 this.suites_.push(this.summarize_(suite)); +861 } +862 }; +863 +864 jasmine.JsApiReporter.prototype.suites = function() { +865 return this.suites_; 866 }; 867 -868 //noinspection JSUnusedLocalSymbols -869 jasmine.JsApiReporter.prototype.reportRunnerResults = function(runner) { -870 this.finished = true; -871 }; -872 -873 //noinspection JSUnusedLocalSymbols -874 jasmine.JsApiReporter.prototype.reportSuiteResults = function(suite) { -875 }; -876 -877 //noinspection JSUnusedLocalSymbols -878 jasmine.JsApiReporter.prototype.reportSpecResults = function(spec) { -879 this.results[spec.id] = { -880 messages: spec.results.getItems(), -881 result: spec.results.failedCount > 0 ? "failed" : "passed" -882 }; +868 jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) { +869 var isSuite = suiteOrSpec instanceof jasmine.Suite +870 var summary = { +871 id: suiteOrSpec.id, +872 name: suiteOrSpec.description, +873 type: isSuite ? 'suite' : 'spec', +874 children: [] +875 }; +876 if (isSuite) { +877 var specs = suiteOrSpec.specs(); +878 for (var i = 0; i < specs.length; i++) { +879 summary.children.push(this.summarize_(specs[i])); +880 } +881 } +882 return summary; 883 }; 884 -885 //noinspection JSUnusedLocalSymbols -886 jasmine.JsApiReporter.prototype.log = function(str) { +885 jasmine.JsApiReporter.prototype.results = function() { +886 return this.results_; 887 }; 888 -889 jasmine.Matchers = function(env, actual, results) { -890 this.env = env; -891 this.actual = actual; -892 this.passing_message = 'Passed.'; -893 this.results = results || new jasmine.NestedResults(); -894 }; -895 -896 jasmine.Matchers.pp = function(str) { -897 return jasmine.util.htmlEscape(jasmine.pp(str)); -898 }; -899 -900 jasmine.Matchers.prototype.getResults = function() { -901 return this.results; -902 }; -903 -904 jasmine.Matchers.prototype.report = function(result, failing_message, details) { -905 this.results.addResult(new jasmine.ExpectationResult(result, result ? this.passing_message : failing_message, details)); -906 return result; -907 }; -908 -909 /** -910 * Matcher that compares the actual to the expected using ===. -911 * -912 * @param expected -913 */ -914 jasmine.Matchers.prototype.toBe = function(expected) { -915 return this.report(this.actual === expected, 'Expected<br /><br />' + jasmine.Matchers.pp(expected) -916 + '<br /><br />to be the same object as<br /><br />' + jasmine.Matchers.pp(this.actual) -917 + '<br />'); -918 }; -919 -920 /** -921 * Matcher that compares the actual to the expected using !== -922 * @param expected -923 */ -924 jasmine.Matchers.prototype.toNotBe = function(expected) { -925 return this.report(this.actual !== expected, 'Expected<br /><br />' + jasmine.Matchers.pp(expected) -926 + '<br /><br />to be a different object from actual, but they were the same.'); -927 }; -928 -929 /** -930 * Matcher that compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc. -931 * -932 * @param expected -933 */ -934 jasmine.Matchers.prototype.toEqual = function(expected) { -935 var mismatchKeys = []; -936 var mismatchValues = []; -937 -938 var formatMismatches = function(name, array) { -939 if (array.length == 0) return ''; -940 var errorOutput = '<br /><br />Different ' + name + ':<br />'; -941 for (var i = 0; i < array.length; i++) { -942 errorOutput += array[i] + '<br />'; -943 } -944 return errorOutput; -945 }; -946 -947 return this.report(this.env.equals_(this.actual, expected, mismatchKeys, mismatchValues), -948 'Expected<br /><br />' + jasmine.Matchers.pp(expected) -949 + '<br /><br />but got<br /><br />' + jasmine.Matchers.pp(this.actual) -950 + '<br />' -951 + formatMismatches('Keys', mismatchKeys) -952 + formatMismatches('Values', mismatchValues), { -953 matcherName: 'toEqual', expected: expected, actual: this.actual -954 }); -955 }; -956 /** @deprecated */ -957 jasmine.Matchers.prototype.should_equal = jasmine.Matchers.prototype.toEqual; +889 jasmine.JsApiReporter.prototype.resultsForSpec = function(specId) { +890 return this.results_[specId]; +891 }; +892 +893 //noinspection JSUnusedLocalSymbols +894 jasmine.JsApiReporter.prototype.reportRunnerResults = function(runner) { +895 this.finished = true; +896 }; +897 +898 //noinspection JSUnusedLocalSymbols +899 jasmine.JsApiReporter.prototype.reportSuiteResults = function(suite) { +900 }; +901 +902 //noinspection JSUnusedLocalSymbols +903 jasmine.JsApiReporter.prototype.reportSpecResults = function(spec) { +904 this.results_[spec.id] = { +905 messages: spec.results().getItems(), +906 result: spec.results().failedCount > 0 ? "failed" : "passed" +907 }; +908 }; +909 +910 //noinspection JSUnusedLocalSymbols +911 jasmine.JsApiReporter.prototype.log = function(str) { +912 }; +913 +914 jasmine.Matchers = function(env, actual, results) { +915 this.env = env; +916 this.actual = actual; +917 this.passing_message = 'Passed.'; +918 this.results_ = results || new jasmine.NestedResults(); +919 }; +920 +921 jasmine.Matchers.pp = function(str) { +922 return jasmine.util.htmlEscape(jasmine.pp(str)); +923 }; +924 +925 /** @deprecated */ +926 jasmine.Matchers.prototype.getResults = function() { +927 return this.results_; +928 }; +929 +930 jasmine.Matchers.prototype.results = function() { +931 return this.results_; +932 }; +933 +934 jasmine.Matchers.prototype.report = function(result, failing_message, details) { +935 this.results_.addResult(new jasmine.ExpectationResult(result, result ? this.passing_message : failing_message, details)); +936 return result; +937 }; +938 +939 /** +940 * Matcher that compares the actual to the expected using ===. +941 * +942 * @param expected +943 */ +944 jasmine.Matchers.prototype.toBe = function(expected) { +945 return this.report(this.actual === expected, 'Expected<br /><br />' + jasmine.Matchers.pp(expected) +946 + '<br /><br />to be the same object as<br /><br />' + jasmine.Matchers.pp(this.actual) +947 + '<br />'); +948 }; +949 +950 /** +951 * Matcher that compares the actual to the expected using !== +952 * @param expected +953 */ +954 jasmine.Matchers.prototype.toNotBe = function(expected) { +955 return this.report(this.actual !== expected, 'Expected<br /><br />' + jasmine.Matchers.pp(expected) +956 + '<br /><br />to be a different object from actual, but they were the same.'); +957 }; 958 959 /** -960 * Matcher that compares the actual to the expected using the ! of jasmine.Matchers.toEqual -961 * @param expected -962 */ -963 jasmine.Matchers.prototype.toNotEqual = function(expected) { -964 return this.report(!this.env.equals_(this.actual, expected), -965 'Expected ' + jasmine.Matchers.pp(expected) + ' to not equal ' + jasmine.Matchers.pp(this.actual) + ', but it does.'); -966 }; -967 /** @deprecated */ -968 jasmine.Matchers.prototype.should_not_equal = jasmine.Matchers.prototype.toNotEqual; -969 -970 /** -971 * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes -972 * a pattern or a String. -973 * -974 * @param reg_exp -975 */ -976 jasmine.Matchers.prototype.toMatch = function(reg_exp) { -977 return this.report((new RegExp(reg_exp).test(this.actual)), -978 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to match ' + reg_exp + '.'); -979 }; -980 /** @deprecated */ -981 jasmine.Matchers.prototype.should_match = jasmine.Matchers.prototype.toMatch; -982 -983 /** -984 * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch -985 * @param reg_exp -986 */ -987 jasmine.Matchers.prototype.toNotMatch = function(reg_exp) { -988 return this.report((!new RegExp(reg_exp).test(this.actual)), -989 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to not match ' + reg_exp + '.'); -990 }; -991 /** @deprecated */ -992 jasmine.Matchers.prototype.should_not_match = jasmine.Matchers.prototype.toNotMatch; -993 -994 /** -995 * Matcher that compares the acutal to undefined. -996 */ -997 jasmine.Matchers.prototype.toBeDefined = function() { -998 return this.report((this.actual !== undefined), -999 'Expected a value to be defined but it was undefined.'); -1000 }; -1001 /** @deprecated */ -1002 jasmine.Matchers.prototype.should_be_defined = jasmine.Matchers.prototype.toBeDefined; -1003 -1004 /** -1005 * Matcher that compares the actual to null. -1006 * -1007 */ -1008 jasmine.Matchers.prototype.toBeNull = function() { -1009 return this.report((this.actual === null), -1010 'Expected a value to be null but it was ' + jasmine.Matchers.pp(this.actual) + '.'); -1011 }; -1012 /** @deprecated */ -1013 jasmine.Matchers.prototype.should_be_null = jasmine.Matchers.prototype.toBeNull; -1014 -1015 /** -1016 * Matcher that boolean not-nots the actual. -1017 */ -1018 jasmine.Matchers.prototype.toBeTruthy = function() { -1019 return this.report(!!this.actual, -1020 'Expected a value to be truthy but it was ' + jasmine.Matchers.pp(this.actual) + '.'); -1021 }; -1022 /** @deprecated */ -1023 jasmine.Matchers.prototype.should_be_truthy = jasmine.Matchers.prototype.toBeTruthy; -1024 -1025 /** -1026 * Matcher that boolean nots the actual. -1027 */ -1028 jasmine.Matchers.prototype.toBeFalsy = function() { -1029 return this.report(!this.actual, -1030 'Expected a value to be falsy but it was ' + jasmine.Matchers.pp(this.actual) + '.'); -1031 }; -1032 /** @deprecated */ -1033 jasmine.Matchers.prototype.should_be_falsy = jasmine.Matchers.prototype.toBeFalsy; -1034 -1035 /** -1036 * Matcher that checks to see if the acutal, a Jasmine spy, was called. +960 * Matcher that compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc. +961 * +962 * @param expected +963 */ +964 jasmine.Matchers.prototype.toEqual = function(expected) { +965 var mismatchKeys = []; +966 var mismatchValues = []; +967 +968 var formatMismatches = function(name, array) { +969 if (array.length == 0) return ''; +970 var errorOutput = '<br /><br />Different ' + name + ':<br />'; +971 for (var i = 0; i < array.length; i++) { +972 errorOutput += array[i] + '<br />'; +973 } +974 return errorOutput; +975 }; +976 +977 return this.report(this.env.equals_(this.actual, expected, mismatchKeys, mismatchValues), +978 'Expected<br /><br />' + jasmine.Matchers.pp(expected) +979 + '<br /><br />but got<br /><br />' + jasmine.Matchers.pp(this.actual) +980 + '<br />' +981 + formatMismatches('Keys', mismatchKeys) +982 + formatMismatches('Values', mismatchValues), { +983 matcherName: 'toEqual', expected: expected, actual: this.actual +984 }); +985 }; +986 /** @deprecated */ +987 jasmine.Matchers.prototype.should_equal = jasmine.Matchers.prototype.toEqual; +988 +989 /** +990 * Matcher that compares the actual to the expected using the ! of jasmine.Matchers.toEqual +991 * @param expected +992 */ +993 jasmine.Matchers.prototype.toNotEqual = function(expected) { +994 return this.report(!this.env.equals_(this.actual, expected), +995 'Expected ' + jasmine.Matchers.pp(expected) + ' to not equal ' + jasmine.Matchers.pp(this.actual) + ', but it does.'); +996 }; +997 /** @deprecated */ +998 jasmine.Matchers.prototype.should_not_equal = jasmine.Matchers.prototype.toNotEqual; +999 +1000 /** +1001 * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes +1002 * a pattern or a String. +1003 * +1004 * @param reg_exp +1005 */ +1006 jasmine.Matchers.prototype.toMatch = function(reg_exp) { +1007 return this.report((new RegExp(reg_exp).test(this.actual)), +1008 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to match ' + reg_exp + '.'); +1009 }; +1010 /** @deprecated */ +1011 jasmine.Matchers.prototype.should_match = jasmine.Matchers.prototype.toMatch; +1012 +1013 /** +1014 * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch +1015 * @param reg_exp +1016 */ +1017 jasmine.Matchers.prototype.toNotMatch = function(reg_exp) { +1018 return this.report((!new RegExp(reg_exp).test(this.actual)), +1019 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to not match ' + reg_exp + '.'); +1020 }; +1021 /** @deprecated */ +1022 jasmine.Matchers.prototype.should_not_match = jasmine.Matchers.prototype.toNotMatch; +1023 +1024 /** +1025 * Matcher that compares the acutal to undefined. +1026 */ +1027 jasmine.Matchers.prototype.toBeDefined = function() { +1028 return this.report((this.actual !== undefined), +1029 'Expected a value to be defined but it was undefined.'); +1030 }; +1031 /** @deprecated */ +1032 jasmine.Matchers.prototype.should_be_defined = jasmine.Matchers.prototype.toBeDefined; +1033 +1034 /** +1035 * Matcher that compares the actual to null. +1036 * 1037 */ -1038 jasmine.Matchers.prototype.wasCalled = function() { -1039 if (!this.actual || !this.actual.isSpy) { -1040 return this.report(false, 'Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); -1041 } -1042 if (arguments.length > 0) { -1043 return this.report(false, 'wasCalled matcher does not take arguments'); -1044 } -1045 return this.report((this.actual.wasCalled), -1046 'Expected spy "' + this.actual.identity + '" to have been called, but it was not.'); -1047 }; -1048 /** @deprecated */ -1049 jasmine.Matchers.prototype.was_called = jasmine.Matchers.prototype.wasCalled; -1050 -1051 /** -1052 * Matcher that checks to see if the acutal, a Jasmine spy, was not called. -1053 */ -1054 jasmine.Matchers.prototype.wasNotCalled = function() { -1055 if (!this.actual || !this.actual.isSpy) { -1056 return this.report(false, 'Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); -1057 } -1058 return this.report((!this.actual.wasCalled), -1059 'Expected spy "' + this.actual.identity + '" to not have been called, but it was.'); -1060 }; -1061 /** @deprecated */ -1062 jasmine.Matchers.prototype.was_not_called = jasmine.Matchers.prototype.wasNotCalled; -1063 -1064 /** -1065 * Matcher that checks to see if the acutal, a Jasmine spy, was called with a set of parameters. -1066 * -1067 * @example -1068 * -1069 */ -1070 jasmine.Matchers.prototype.wasCalledWith = function() { -1071 if (!this.actual || !this.actual.isSpy) { -1072 return this.report(false, 'Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.', { -1073 matcherName: 'wasCalledWith' -1074 }); -1075 } -1076 -1077 var args = jasmine.util.argsToArray(arguments); -1078 -1079 return this.report(this.env.contains_(this.actual.argsForCall, args), -1080 'Expected ' + jasmine.Matchers.pp(this.actual.argsForCall) + ' to contain ' + jasmine.Matchers.pp(args) + ', but it does not.', { -1081 matcherName: 'wasCalledWith', expected: args, actual: this.actual.argsForCall -1082 }); -1083 }; -1084 -1085 /** -1086 * Matcher that checks that the expected item is an element in the actual Array. -1087 * -1088 * @param {Object} item -1089 */ -1090 jasmine.Matchers.prototype.toContain = function(item) { -1091 return this.report(this.env.contains_(this.actual, item), -1092 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to contain ' + jasmine.Matchers.pp(item) + ', but it does not.', { -1093 matcherName: 'toContain', expected: item, actual: this.actual -1094 }); -1095 }; -1096 -1097 /** -1098 * Matcher that checks that the expected item is NOT an element in the actual Array. -1099 * -1100 * @param {Object} item -1101 */ -1102 jasmine.Matchers.prototype.toNotContain = function(item) { -1103 return this.report(!this.env.contains_(this.actual, item), -1104 'Expected ' + jasmine.Matchers.pp(this.actual) + ' not to contain ' + jasmine.Matchers.pp(item) + ', but it does.'); -1105 }; +1038 jasmine.Matchers.prototype.toBeNull = function() { +1039 return this.report((this.actual === null), +1040 'Expected a value to be null but it was ' + jasmine.Matchers.pp(this.actual) + '.'); +1041 }; +1042 /** @deprecated */ +1043 jasmine.Matchers.prototype.should_be_null = jasmine.Matchers.prototype.toBeNull; +1044 +1045 /** +1046 * Matcher that boolean not-nots the actual. +1047 */ +1048 jasmine.Matchers.prototype.toBeTruthy = function() { +1049 return this.report(!!this.actual, +1050 'Expected a value to be truthy but it was ' + jasmine.Matchers.pp(this.actual) + '.'); +1051 }; +1052 /** @deprecated */ +1053 jasmine.Matchers.prototype.should_be_truthy = jasmine.Matchers.prototype.toBeTruthy; +1054 +1055 /** +1056 * Matcher that boolean nots the actual. +1057 */ +1058 jasmine.Matchers.prototype.toBeFalsy = function() { +1059 return this.report(!this.actual, +1060 'Expected a value to be falsy but it was ' + jasmine.Matchers.pp(this.actual) + '.'); +1061 }; +1062 /** @deprecated */ +1063 jasmine.Matchers.prototype.should_be_falsy = jasmine.Matchers.prototype.toBeFalsy; +1064 +1065 /** +1066 * Matcher that checks to see if the acutal, a Jasmine spy, was called. +1067 */ +1068 jasmine.Matchers.prototype.wasCalled = function() { +1069 if (!this.actual || !this.actual.isSpy) { +1070 return this.report(false, 'Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); +1071 } +1072 if (arguments.length > 0) { +1073 return this.report(false, 'wasCalled matcher does not take arguments'); +1074 } +1075 return this.report((this.actual.wasCalled), +1076 'Expected spy "' + this.actual.identity + '" to have been called, but it was not.'); +1077 }; +1078 /** @deprecated */ +1079 jasmine.Matchers.prototype.was_called = jasmine.Matchers.prototype.wasCalled; +1080 +1081 /** +1082 * Matcher that checks to see if the acutal, a Jasmine spy, was not called. +1083 */ +1084 jasmine.Matchers.prototype.wasNotCalled = function() { +1085 if (!this.actual || !this.actual.isSpy) { +1086 return this.report(false, 'Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.'); +1087 } +1088 return this.report((!this.actual.wasCalled), +1089 'Expected spy "' + this.actual.identity + '" to not have been called, but it was.'); +1090 }; +1091 /** @deprecated */ +1092 jasmine.Matchers.prototype.was_not_called = jasmine.Matchers.prototype.wasNotCalled; +1093 +1094 /** +1095 * Matcher that checks to see if the acutal, a Jasmine spy, was called with a set of parameters. +1096 * +1097 * @example +1098 * +1099 */ +1100 jasmine.Matchers.prototype.wasCalledWith = function() { +1101 if (!this.actual || !this.actual.isSpy) { +1102 return this.report(false, 'Expected a spy, but got ' + jasmine.Matchers.pp(this.actual) + '.', { +1103 matcherName: 'wasCalledWith' +1104 }); +1105 } 1106 -1107 jasmine.Matchers.prototype.toBeLessThan = function(expected) { -1108 return this.report(this.actual < expected, -1109 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to be less than ' + jasmine.Matchers.pp(expected) + ', but it was not.'); -1110 }; -1111 -1112 jasmine.Matchers.prototype.toBeGreaterThan = function(expected) { -1113 return this.report(this.actual > expected, -1114 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to be greater than ' + jasmine.Matchers.pp(expected) + ', but it was not.'); -1115 }; -1116 -1117 /** -1118 * Matcher that checks that the expected exception was thrown by the actual. -1119 * -1120 * @param {String} expectedException -1121 */ -1122 jasmine.Matchers.prototype.toThrow = function(expectedException) { -1123 var exception = null; -1124 try { -1125 this.actual(); -1126 } catch (e) { -1127 exception = e; -1128 } -1129 if (expectedException !== undefined) { -1130 if (exception == null) { -1131 return this.report(false, "Expected function to throw " + jasmine.Matchers.pp(expectedException) + ", but it did not."); -1132 } -1133 return this.report( -1134 this.env.equals_( -1135 exception.message || exception, -1136 expectedException.message || expectedException), -1137 "Expected function to throw " + jasmine.Matchers.pp(expectedException) + ", but it threw " + jasmine.Matchers.pp(exception) + "."); -1138 } else { -1139 return this.report(exception != null, "Expected function to throw an exception, but it did not."); -1140 } -1141 }; -1142 -1143 jasmine.Matchers.Any = function(expectedClass) { -1144 this.expectedClass = expectedClass; +1107 var args = jasmine.util.argsToArray(arguments); +1108 +1109 return this.report(this.env.contains_(this.actual.argsForCall, args), +1110 'Expected ' + jasmine.Matchers.pp(this.actual.argsForCall) + ' to contain ' + jasmine.Matchers.pp(args) + ', but it does not.', { +1111 matcherName: 'wasCalledWith', expected: args, actual: this.actual.argsForCall +1112 }); +1113 }; +1114 +1115 /** +1116 * Matcher that checks that the expected item is an element in the actual Array. +1117 * +1118 * @param {Object} item +1119 */ +1120 jasmine.Matchers.prototype.toContain = function(item) { +1121 return this.report(this.env.contains_(this.actual, item), +1122 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to contain ' + jasmine.Matchers.pp(item) + ', but it does not.', { +1123 matcherName: 'toContain', expected: item, actual: this.actual +1124 }); +1125 }; +1126 +1127 /** +1128 * Matcher that checks that the expected item is NOT an element in the actual Array. +1129 * +1130 * @param {Object} item +1131 */ +1132 jasmine.Matchers.prototype.toNotContain = function(item) { +1133 return this.report(!this.env.contains_(this.actual, item), +1134 'Expected ' + jasmine.Matchers.pp(this.actual) + ' not to contain ' + jasmine.Matchers.pp(item) + ', but it does.'); +1135 }; +1136 +1137 jasmine.Matchers.prototype.toBeLessThan = function(expected) { +1138 return this.report(this.actual < expected, +1139 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to be less than ' + jasmine.Matchers.pp(expected) + ', but it was not.'); +1140 }; +1141 +1142 jasmine.Matchers.prototype.toBeGreaterThan = function(expected) { +1143 return this.report(this.actual > expected, +1144 'Expected ' + jasmine.Matchers.pp(this.actual) + ' to be greater than ' + jasmine.Matchers.pp(expected) + ', but it was not.'); 1145 }; 1146 -1147 jasmine.Matchers.Any.prototype.matches = function(other) { -1148 if (this.expectedClass == String) { -1149 return typeof other == 'string' || other instanceof String; -1150 } -1151 -1152 if (this.expectedClass == Number) { -1153 return typeof other == 'number' || other instanceof Number; -1154 } -1155 -1156 if (this.expectedClass == Function) { -1157 return typeof other == 'function' || other instanceof Function; +1147 /** +1148 * Matcher that checks that the expected exception was thrown by the actual. +1149 * +1150 * @param {String} expectedException +1151 */ +1152 jasmine.Matchers.prototype.toThrow = function(expectedException) { +1153 var exception = null; +1154 try { +1155 this.actual(); +1156 } catch (e) { +1157 exception = e; 1158 } -1159 -1160 if (this.expectedClass == Object) { -1161 return typeof other == 'object'; -1162 } -1163 -1164 return other instanceof this.expectedClass; -1165 }; -1166 -1167 jasmine.Matchers.Any.prototype.toString = function() { -1168 return '<jasmine.any(' + this.expectedClass + ')>'; -1169 }; -1170 -1171 /** -1172 * @constructor -1173 */ -1174 jasmine.MultiReporter = function() { -1175 this.subReporters_ = []; -1176 }; -1177 jasmine.util.inherit(jasmine.MultiReporter, jasmine.Reporter); -1178 -1179 jasmine.MultiReporter.prototype.addReporter = function(reporter) { -1180 this.subReporters_.push(reporter); -1181 }; -1182 -1183 (function() { -1184 var functionNames = ["reportRunnerStarting", "reportRunnerResults", "reportSuiteResults", "reportSpecResults", "log"]; -1185 for (var i = 0; i < functionNames.length; i++) { -1186 var functionName = functionNames[i]; -1187 jasmine.MultiReporter.prototype[functionName] = (function(functionName) { -1188 return function() { -1189 for (var j = 0; j < this.subReporters_.length; j++) { -1190 var subReporter = this.subReporters_[j]; -1191 if (subReporter[functionName]) { -1192 subReporter[functionName].apply(subReporter, arguments); -1193 } -1194 } -1195 }; -1196 })(functionName); -1197 } -1198 })(); -1199 /** -1200 * Holds results for a set of Jasmine spec. Allows for the results array to hold another jasmine.NestedResults -1201 * +1159 if (expectedException !== undefined) { +1160 if (exception == null) { +1161 return this.report(false, "Expected function to throw " + jasmine.Matchers.pp(expectedException) + ", but it did not."); +1162 } +1163 return this.report( +1164 this.env.equals_( +1165 exception.message || exception, +1166 expectedException.message || expectedException), +1167 "Expected function to throw " + jasmine.Matchers.pp(expectedException) + ", but it threw " + jasmine.Matchers.pp(exception) + "."); +1168 } else { +1169 return this.report(exception != null, "Expected function to throw an exception, but it did not."); +1170 } +1171 }; +1172 +1173 jasmine.Matchers.Any = function(expectedClass) { +1174 this.expectedClass = expectedClass; +1175 }; +1176 +1177 jasmine.Matchers.Any.prototype.matches = function(other) { +1178 if (this.expectedClass == String) { +1179 return typeof other == 'string' || other instanceof String; +1180 } +1181 +1182 if (this.expectedClass == Number) { +1183 return typeof other == 'number' || other instanceof Number; +1184 } +1185 +1186 if (this.expectedClass == Function) { +1187 return typeof other == 'function' || other instanceof Function; +1188 } +1189 +1190 if (this.expectedClass == Object) { +1191 return typeof other == 'object'; +1192 } +1193 +1194 return other instanceof this.expectedClass; +1195 }; +1196 +1197 jasmine.Matchers.Any.prototype.toString = function() { +1198 return '<jasmine.any(' + this.expectedClass + ')>'; +1199 }; +1200 +1201 /** 1202 * @constructor 1203 */ -1204 jasmine.NestedResults = function() { -1205 /** -1206 * The total count of results -1207 */ -1208 this.totalCount = 0; -1209 /** -1210 * Number of passed results -1211 */ -1212 this.passedCount = 0; -1213 /** -1214 * Number of failed results -1215 */ -1216 this.failedCount = 0; -1217 /** -1218 * Was this suite/spec skipped? -1219 */ -1220 this.skipped = false; -1221 /** -1222 * @ignore -1223 */ -1224 this.items_ = []; -1225 }; -1226 -1227 /** -1228 * Roll up the result counts. -1229 * -1230 * @param result -1231 */ -1232 jasmine.NestedResults.prototype.rollupCounts = function(result) { -1233 this.totalCount += result.totalCount; -1234 this.passedCount += result.passedCount; -1235 this.failedCount += result.failedCount; -1236 }; -1237 -1238 /** -1239 * Tracks a result's message. -1240 * @param message -1241 */ -1242 jasmine.NestedResults.prototype.log = function(message) { -1243 this.items_.push(new jasmine.MessageResult(message)); -1244 }; -1245 -1246 /** -1247 * Getter for the results: message & results. -1248 */ -1249 jasmine.NestedResults.prototype.getItems = function() { -1250 return this.items_; -1251 }; -1252 -1253 /** -1254 * Adds a result, tracking counts (total, passed, & failed) -1255 * @param {jasmine.ExpectationResult|jasmine.NestedResults} result -1256 */ -1257 jasmine.NestedResults.prototype.addResult = function(result) { -1258 if (result.type != 'MessageResult') { -1259 if (result.items_) { -1260 this.rollupCounts(result); -1261 } else { -1262 this.totalCount++; -1263 if (result.passed()) { -1264 this.passedCount++; -1265 } else { -1266 this.failedCount++; -1267 } -1268 } -1269 } -1270 this.items_.push(result); -1271 }; -1272 -1273 /** -1274 * @returns {Boolean} True if <b>everything</b> below passed -1275 */ -1276 jasmine.NestedResults.prototype.passed = function() { -1277 return this.passedCount === this.totalCount; -1278 }; -1279 /** -1280 * Base class for pretty printing for expectation results. -1281 */ -1282 jasmine.PrettyPrinter = function() { -1283 this.ppNestLevel_ = 0; -1284 }; -1285 -1286 /** -1287 * Formats a value in a nice, human-readable string. -1288 * -1289 * @param value -1290 * @returns {String} -1291 */ -1292 jasmine.PrettyPrinter.prototype.format = function(value) { -1293 if (this.ppNestLevel_ > 40) { -1294 // return '(jasmine.pp nested too deeply!)'; -1295 throw new Error('jasmine.PrettyPrinter: format() nested too deeply!'); -1296 } -1297 -1298 this.ppNestLevel_++; -1299 try { -1300 if (value === undefined) { -1301 this.emitScalar('undefined'); -1302 } else if (value === null) { -1303 this.emitScalar('null'); -1304 } else if (value.navigator && value.frames && value.setTimeout) { -1305 this.emitScalar('<window>'); -1306 } else if (value instanceof jasmine.Matchers.Any) { -1307 this.emitScalar(value.toString()); -1308 } else if (typeof value === 'string') { -1309 this.emitString(value); -1310 } else if (typeof value === 'function') { -1311 this.emitScalar('Function'); -1312 } else if (typeof value.nodeType === 'number') { -1313 this.emitScalar('HTMLNode'); -1314 } else if (value instanceof Date) { -1315 this.emitScalar('Date(' + value + ')'); -1316 } else if (value.__Jasmine_been_here_before__) { -1317 this.emitScalar('<circular reference: ' + (jasmine.isArray_(value) ? 'Array' : 'Object') + '>'); -1318 } else if (jasmine.isArray_(value) || typeof value == 'object') { -1319 value.__Jasmine_been_here_before__ = true; -1320 if (jasmine.isArray_(value)) { -1321 this.emitArray(value); -1322 } else { -1323 this.emitObject(value); -1324 } -1325 delete value.__Jasmine_been_here_before__; -1326 } else { -1327 this.emitScalar(value.toString()); -1328 } -1329 } finally { -1330 this.ppNestLevel_--; -1331 } -1332 }; -1333 -1334 jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) { -1335 for (var property in obj) { -1336 if (property == '__Jasmine_been_here_before__') continue; -1337 fn(property, obj.__lookupGetter__(property) != null); -1338 } -1339 }; -1340 -1341 jasmine.PrettyPrinter.prototype.emitArray = jasmine.unimplementedMethod_; -1342 jasmine.PrettyPrinter.prototype.emitObject = jasmine.unimplementedMethod_; -1343 jasmine.PrettyPrinter.prototype.emitScalar = jasmine.unimplementedMethod_; -1344 jasmine.PrettyPrinter.prototype.emitString = jasmine.unimplementedMethod_; -1345 -1346 jasmine.StringPrettyPrinter = function() { -1347 jasmine.PrettyPrinter.call(this); -1348 -1349 this.string = ''; -1350 }; -1351 jasmine.util.inherit(jasmine.StringPrettyPrinter, jasmine.PrettyPrinter); -1352 -1353 jasmine.StringPrettyPrinter.prototype.emitScalar = function(value) { -1354 this.append(value); -1355 }; -1356 -1357 jasmine.StringPrettyPrinter.prototype.emitString = function(value) { -1358 this.append("'" + value + "'"); -1359 }; -1360 -1361 jasmine.StringPrettyPrinter.prototype.emitArray = function(array) { -1362 this.append('[ '); -1363 for (var i = 0; i < array.length; i++) { -1364 if (i > 0) { -1365 this.append(', '); -1366 } -1367 this.format(array[i]); +1204 jasmine.MultiReporter = function() { +1205 this.subReporters_ = []; +1206 }; +1207 jasmine.util.inherit(jasmine.MultiReporter, jasmine.Reporter); +1208 +1209 jasmine.MultiReporter.prototype.addReporter = function(reporter) { +1210 this.subReporters_.push(reporter); +1211 }; +1212 +1213 (function() { +1214 var functionNames = ["reportRunnerStarting", "reportRunnerResults", "reportSuiteResults", "reportSpecResults", "log"]; +1215 for (var i = 0; i < functionNames.length; i++) { +1216 var functionName = functionNames[i]; +1217 jasmine.MultiReporter.prototype[functionName] = (function(functionName) { +1218 return function() { +1219 for (var j = 0; j < this.subReporters_.length; j++) { +1220 var subReporter = this.subReporters_[j]; +1221 if (subReporter[functionName]) { +1222 subReporter[functionName].apply(subReporter, arguments); +1223 } +1224 } +1225 }; +1226 })(functionName); +1227 } +1228 })(); +1229 /** +1230 * Holds results for a set of Jasmine spec. Allows for the results array to hold another jasmine.NestedResults +1231 * +1232 * @constructor +1233 */ +1234 jasmine.NestedResults = function() { +1235 /** +1236 * The total count of results +1237 */ +1238 this.totalCount = 0; +1239 /** +1240 * Number of passed results +1241 */ +1242 this.passedCount = 0; +1243 /** +1244 * Number of failed results +1245 */ +1246 this.failedCount = 0; +1247 /** +1248 * Was this suite/spec skipped? +1249 */ +1250 this.skipped = false; +1251 /** +1252 * @ignore +1253 */ +1254 this.items_ = []; +1255 }; +1256 +1257 /** +1258 * Roll up the result counts. +1259 * +1260 * @param result +1261 */ +1262 jasmine.NestedResults.prototype.rollupCounts = function(result) { +1263 this.totalCount += result.totalCount; +1264 this.passedCount += result.passedCount; +1265 this.failedCount += result.failedCount; +1266 }; +1267 +1268 /** +1269 * Tracks a result's message. +1270 * @param message +1271 */ +1272 jasmine.NestedResults.prototype.log = function(message) { +1273 this.items_.push(new jasmine.MessageResult(message)); +1274 }; +1275 +1276 /** +1277 * Getter for the results: message & results. +1278 */ +1279 jasmine.NestedResults.prototype.getItems = function() { +1280 return this.items_; +1281 }; +1282 +1283 /** +1284 * Adds a result, tracking counts (total, passed, & failed) +1285 * @param {jasmine.ExpectationResult|jasmine.NestedResults} result +1286 */ +1287 jasmine.NestedResults.prototype.addResult = function(result) { +1288 if (result.type != 'MessageResult') { +1289 if (result.items_) { +1290 this.rollupCounts(result); +1291 } else { +1292 this.totalCount++; +1293 if (result.passed()) { +1294 this.passedCount++; +1295 } else { +1296 this.failedCount++; +1297 } +1298 } +1299 } +1300 this.items_.push(result); +1301 }; +1302 +1303 /** +1304 * @returns {Boolean} True if <b>everything</b> below passed +1305 */ +1306 jasmine.NestedResults.prototype.passed = function() { +1307 return this.passedCount === this.totalCount; +1308 }; +1309 /** +1310 * Base class for pretty printing for expectation results. +1311 */ +1312 jasmine.PrettyPrinter = function() { +1313 this.ppNestLevel_ = 0; +1314 }; +1315 +1316 /** +1317 * Formats a value in a nice, human-readable string. +1318 * +1319 * @param value +1320 * @returns {String} +1321 */ +1322 jasmine.PrettyPrinter.prototype.format = function(value) { +1323 if (this.ppNestLevel_ > 40) { +1324 // return '(jasmine.pp nested too deeply!)'; +1325 throw new Error('jasmine.PrettyPrinter: format() nested too deeply!'); +1326 } +1327 +1328 this.ppNestLevel_++; +1329 try { +1330 if (value === undefined) { +1331 this.emitScalar('undefined'); +1332 } else if (value === null) { +1333 this.emitScalar('null'); +1334 } else if (value.navigator && value.frames && value.setTimeout) { +1335 this.emitScalar('<window>'); +1336 } else if (value instanceof jasmine.Matchers.Any) { +1337 this.emitScalar(value.toString()); +1338 } else if (typeof value === 'string') { +1339 this.emitString(value); +1340 } else if (typeof value === 'function') { +1341 this.emitScalar('Function'); +1342 } else if (typeof value.nodeType === 'number') { +1343 this.emitScalar('HTMLNode'); +1344 } else if (value instanceof Date) { +1345 this.emitScalar('Date(' + value + ')'); +1346 } else if (value.__Jasmine_been_here_before__) { +1347 this.emitScalar('<circular reference: ' + (jasmine.isArray_(value) ? 'Array' : 'Object') + '>'); +1348 } else if (jasmine.isArray_(value) || typeof value == 'object') { +1349 value.__Jasmine_been_here_before__ = true; +1350 if (jasmine.isArray_(value)) { +1351 this.emitArray(value); +1352 } else { +1353 this.emitObject(value); +1354 } +1355 delete value.__Jasmine_been_here_before__; +1356 } else { +1357 this.emitScalar(value.toString()); +1358 } +1359 } finally { +1360 this.ppNestLevel_--; +1361 } +1362 }; +1363 +1364 jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) { +1365 for (var property in obj) { +1366 if (property == '__Jasmine_been_here_before__') continue; +1367 fn(property, obj.__lookupGetter__(property) != null); 1368 } -1369 this.append(' ]'); -1370 }; -1371 -1372 jasmine.StringPrettyPrinter.prototype.emitObject = function(obj) { -1373 var self = this; -1374 this.append('{ '); -1375 var first = true; -1376 -1377 this.iterateObject(obj, function(property, isGetter) { -1378 if (first) { -1379 first = false; -1380 } else { -1381 self.append(', '); -1382 } -1383 -1384 self.append(property); -1385 self.append(' : '); -1386 if (isGetter) { -1387 self.append('<getter>'); -1388 } else { -1389 self.format(obj[property]); -1390 } -1391 }); -1392 -1393 this.append(' }'); -1394 }; -1395 -1396 jasmine.StringPrettyPrinter.prototype.append = function(value) { -1397 this.string += value; -1398 }; -1399 jasmine.Queue = function(env) { -1400 this.env = env; -1401 this.blocks = []; -1402 this.running = false; -1403 this.index = 0; -1404 this.offset = 0; -1405 }; +1369 }; +1370 +1371 jasmine.PrettyPrinter.prototype.emitArray = jasmine.unimplementedMethod_; +1372 jasmine.PrettyPrinter.prototype.emitObject = jasmine.unimplementedMethod_; +1373 jasmine.PrettyPrinter.prototype.emitScalar = jasmine.unimplementedMethod_; +1374 jasmine.PrettyPrinter.prototype.emitString = jasmine.unimplementedMethod_; +1375 +1376 jasmine.StringPrettyPrinter = function() { +1377 jasmine.PrettyPrinter.call(this); +1378 +1379 this.string = ''; +1380 }; +1381 jasmine.util.inherit(jasmine.StringPrettyPrinter, jasmine.PrettyPrinter); +1382 +1383 jasmine.StringPrettyPrinter.prototype.emitScalar = function(value) { +1384 this.append(value); +1385 }; +1386 +1387 jasmine.StringPrettyPrinter.prototype.emitString = function(value) { +1388 this.append("'" + value + "'"); +1389 }; +1390 +1391 jasmine.StringPrettyPrinter.prototype.emitArray = function(array) { +1392 this.append('[ '); +1393 for (var i = 0; i < array.length; i++) { +1394 if (i > 0) { +1395 this.append(', '); +1396 } +1397 this.format(array[i]); +1398 } +1399 this.append(' ]'); +1400 }; +1401 +1402 jasmine.StringPrettyPrinter.prototype.emitObject = function(obj) { +1403 var self = this; +1404 this.append('{ '); +1405 var first = true; 1406 -1407 jasmine.Queue.prototype.addBefore = function (block) { -1408 this.blocks.unshift(block); -1409 }; -1410 -1411 jasmine.Queue.prototype.add = function(block) { -1412 this.blocks.push(block); -1413 }; -1414 -1415 jasmine.Queue.prototype.insertNext = function (block) { -1416 this.blocks.splice((this.index + this.offset + 1), 0, block); -1417 this.offset++; -1418 }; -1419 -1420 jasmine.Queue.prototype.start = function(onComplete) { -1421 var self = this; -1422 self.running = true; -1423 self.onComplete = onComplete; -1424 if (self.blocks[0]) { -1425 self.blocks[0].execute(function () { -1426 self._next(); -1427 }); -1428 } else { -1429 self.finish(); -1430 } -1431 }; -1432 -1433 jasmine.Queue.prototype.isRunning = function () { -1434 return this.running; +1407 this.iterateObject(obj, function(property, isGetter) { +1408 if (first) { +1409 first = false; +1410 } else { +1411 self.append(', '); +1412 } +1413 +1414 self.append(property); +1415 self.append(' : '); +1416 if (isGetter) { +1417 self.append('<getter>'); +1418 } else { +1419 self.format(obj[property]); +1420 } +1421 }); +1422 +1423 this.append(' }'); +1424 }; +1425 +1426 jasmine.StringPrettyPrinter.prototype.append = function(value) { +1427 this.string += value; +1428 }; +1429 jasmine.Queue = function(env) { +1430 this.env = env; +1431 this.blocks = []; +1432 this.running = false; +1433 this.index = 0; +1434 this.offset = 0; 1435 }; 1436 -1437 jasmine.Queue.prototype._next = function () { -1438 var self = this; -1439 var doNext = function () { -1440 self.offset = 0; -1441 self.index++; -1442 if (self.index < self.blocks.length) { -1443 self.blocks[self.index].execute(function () { -1444 self._next(); -1445 }); -1446 } else { -1447 self.finish(); -1448 } -1449 }; -1450 var now = new Date().getTime(); -1451 if (this.env.updateInterval && now - this.env.lastUpdate > this.env.updateInterval) { -1452 this.env.lastUpdate = now; -1453 this.env.setTimeout(doNext, 0); -1454 } else { -1455 doNext(); -1456 } -1457 -1458 }; -1459 -1460 jasmine.Queue.prototype.finish = function () { -1461 this.running = false; -1462 if (this.onComplete) { -1463 this.onComplete(); -1464 } +1437 jasmine.Queue.prototype.addBefore = function (block) { +1438 this.blocks.unshift(block); +1439 }; +1440 +1441 jasmine.Queue.prototype.add = function(block) { +1442 this.blocks.push(block); +1443 }; +1444 +1445 jasmine.Queue.prototype.insertNext = function (block) { +1446 this.blocks.splice((this.index + this.offset + 1), 0, block); +1447 this.offset++; +1448 }; +1449 +1450 jasmine.Queue.prototype.start = function(onComplete) { +1451 var self = this; +1452 self.running = true; +1453 self.onComplete = onComplete; +1454 if (self.blocks[0]) { +1455 self.blocks[0].execute(function () { +1456 self._next(); +1457 }); +1458 } else { +1459 self.finish(); +1460 } +1461 }; +1462 +1463 jasmine.Queue.prototype.isRunning = function () { +1464 return this.running; 1465 }; 1466 -1467 jasmine.Queue.prototype.getResults = function () { -1468 var results = new jasmine.NestedResults(); -1469 for (var i = 0; i < this.blocks.length; i++) { -1470 if (this.blocks[i].getResults) { -1471 results.addResult(this.blocks[i].getResults()); -1472 } -1473 } -1474 return results; -1475 }; -1476 -1477 -1478 /* JasmineReporters.reporter -1479 * Base object that will get called whenever a Spec, Suite, or Runner is done. It is up to -1480 * descendants of this object to do something with the results (see json_reporter.js) -1481 */ -1482 jasmine.Reporters = {}; -1483 -1484 jasmine.Reporters.reporter = function(callbacks) { -1485 var that = { -1486 callbacks: callbacks || {}, +1467 jasmine.Queue.prototype._next = function () { +1468 var self = this; +1469 var doNext = function () { +1470 self.offset = 0; +1471 self.index++; +1472 if (self.index < self.blocks.length) { +1473 self.blocks[self.index].execute(function () { +1474 self._next(); +1475 }); +1476 } else { +1477 self.finish(); +1478 } +1479 }; +1480 var now = new Date().getTime(); +1481 if (this.env.updateInterval && now - this.env.lastUpdate > this.env.updateInterval) { +1482 this.env.lastUpdate = now; +1483 this.env.setTimeout(doNext, 0); +1484 } else { +1485 doNext(); +1486 } 1487 -1488 doCallback: function(callback, results) { -1489 if (callback) { -1490 callback(results); -1491 } -1492 }, -1493 -1494 reportRunnerResults: function(runner) { -1495 that.doCallback(that.callbacks.runnerCallback, runner); -1496 }, -1497 reportSuiteResults: function(suite) { -1498 that.doCallback(that.callbacks.suiteCallback, suite); -1499 }, -1500 reportSpecResults: function(spec) { -1501 that.doCallback(that.callbacks.specCallback, spec); -1502 }, -1503 log: function (str) { -1504 if (console && console.log) console.log(str); -1505 } -1506 }; +1488 }; +1489 +1490 jasmine.Queue.prototype.finish = function () { +1491 this.running = false; +1492 if (this.onComplete) { +1493 this.onComplete(); +1494 } +1495 }; +1496 +1497 jasmine.Queue.prototype.results = function () { +1498 var results = new jasmine.NestedResults(); +1499 for (var i = 0; i < this.blocks.length; i++) { +1500 if (this.blocks[i].results) { +1501 results.addResult(this.blocks[i].results()); +1502 } +1503 } +1504 return results; +1505 }; +1506 1507 -1508 return that; -1509 }; -1510 -1511 /** -1512 * Runner -1513 * -1514 * @constructor -1515 * @param {jasmine.Env} env -1516 */ -1517 jasmine.Runner = function(env) { -1518 var self = this; -1519 self.env = env; -1520 self.queue = new jasmine.Queue(env); -1521 self.suites_ = []; -1522 }; +1508 /* JasmineReporters.reporter +1509 * Base object that will get called whenever a Spec, Suite, or Runner is done. It is up to +1510 * descendants of this object to do something with the results (see json_reporter.js) +1511 */ +1512 jasmine.Reporters = {}; +1513 +1514 jasmine.Reporters.reporter = function(callbacks) { +1515 var that = { +1516 callbacks: callbacks || {}, +1517 +1518 doCallback: function(callback, results) { +1519 if (callback) { +1520 callback(results); +1521 } +1522 }, 1523 -1524 jasmine.Runner.prototype.execute = function() { -1525 var self = this; -1526 if (self.env.reporter.reportRunnerStarting) { -1527 self.env.reporter.reportRunnerStarting(this); -1528 } -1529 self.queue.start(function () { -1530 self.finishCallback(); -1531 }); -1532 }; -1533 -1534 jasmine.Runner.prototype.finishCallback = function() { -1535 this.env.reporter.reportRunnerResults(this); -1536 }; +1524 reportRunnerResults: function(runner) { +1525 that.doCallback(that.callbacks.runnerCallback, runner); +1526 }, +1527 reportSuiteResults: function(suite) { +1528 that.doCallback(that.callbacks.suiteCallback, suite); +1529 }, +1530 reportSpecResults: function(spec) { +1531 that.doCallback(that.callbacks.specCallback, spec); +1532 }, +1533 log: function (str) { +1534 if (console && console.log) console.log(str); +1535 } +1536 }; 1537 -1538 jasmine.Runner.prototype.addSuite = function(suite) { -1539 this.suites_.push(suite); -1540 }; -1541 -1542 jasmine.Runner.prototype.add = function(block) { -1543 if (block instanceof jasmine.Suite) { -1544 this.addSuite(block); -1545 } -1546 this.queue.add(block); -1547 }; -1548 -1549 /** @deprecated */ -1550 jasmine.Runner.prototype.getAllSuites = function() { -1551 return this.suites_; +1538 return that; +1539 }; +1540 +1541 /** +1542 * Runner +1543 * +1544 * @constructor +1545 * @param {jasmine.Env} env +1546 */ +1547 jasmine.Runner = function(env) { +1548 var self = this; +1549 self.env = env; +1550 self.queue = new jasmine.Queue(env); +1551 self.suites_ = []; 1552 }; 1553 -1554 -1555 jasmine.Runner.prototype.suites = function() { -1556 return this.suites_; -1557 }; -1558 -1559 jasmine.Runner.prototype.getResults = function() { -1560 return this.queue.getResults(); -1561 }; -1562 /** -1563 * Internal representation of a Jasmine specification, or test. -1564 * -1565 * @constructor -1566 * @param {jasmine.Env} env -1567 * @param {jasmine.Suite} suite -1568 * @param {String} description -1569 */ -1570 jasmine.Spec = function(env, suite, description) { -1571 var spec = this; -1572 spec.id = env.nextSpecId_++; -1573 spec.env = env; -1574 spec.suite = suite; -1575 spec.description = description; -1576 spec.queue = new jasmine.Queue(env); -1577 -1578 spec.afterCallbacks = []; -1579 spec.spies_ = []; -1580 -1581 spec.results = new jasmine.NestedResults(); -1582 spec.results.description = description; -1583 spec.matchersClass = null; -1584 }; -1585 -1586 jasmine.Spec.prototype.getFullName = function() { -1587 return this.suite.getFullName() + ' ' + this.description + '.'; -1588 }; -1589 -1590 jasmine.Spec.prototype.getResults = function() { -1591 return this.results; -1592 }; -1593 -1594 jasmine.Spec.prototype.runs = function (func) { -1595 var block = new jasmine.Block(this.env, func, this); -1596 this.addToQueue(block); -1597 return this; -1598 }; -1599 -1600 jasmine.Spec.prototype.addToQueue = function (block) { -1601 if (this.queue.isRunning()) { -1602 this.queue.insertNext(block); -1603 } else { -1604 this.queue.add(block); -1605 } -1606 }; -1607 -1608 /** -1609 * @private -1610 * @deprecated -1611 */ -1612 jasmine.Spec.prototype.expects_that = function(actual) { -1613 return this.expect(actual); -1614 }; -1615 -1616 /** -1617 * @private -1618 */ -1619 jasmine.Spec.prototype.expect = function(actual) { -1620 return new (this.getMatchersClass_())(this.env, actual, this.results); -1621 }; -1622 -1623 jasmine.Spec.prototype.waits = function(timeout) { -1624 var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this); -1625 this.addToQueue(waitsFunc); -1626 return this; -1627 }; -1628 -1629 jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessage) { -1630 var waitsForFunc = new jasmine.WaitsForBlock(this.env, timeout, latchFunction, timeoutMessage, this); -1631 this.addToQueue(waitsForFunc); -1632 return this; -1633 }; -1634 -1635 jasmine.Spec.prototype.failWithException = function (e) { -1636 this.results.addResult(new jasmine.ExpectationResult(false, jasmine.util.formatException(e), null)); -1637 }; -1638 -1639 jasmine.Spec.prototype.getMatchersClass_ = function() { -1640 return this.matchersClass || jasmine.Matchers; -1641 }; -1642 -1643 jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { -1644 var parent = this.getMatchersClass_(); -1645 var newMatchersClass = function() { -1646 parent.apply(this, arguments); -1647 }; -1648 jasmine.util.inherit(newMatchersClass, parent); -1649 for (var method in matchersPrototype) { -1650 newMatchersClass.prototype[method] = matchersPrototype[method]; -1651 } -1652 this.matchersClass = newMatchersClass; -1653 }; -1654 -1655 jasmine.Spec.prototype.finishCallback = function() { -1656 this.env.reporter.reportSpecResults(this); +1554 jasmine.Runner.prototype.execute = function() { +1555 var self = this; +1556 if (self.env.reporter.reportRunnerStarting) { +1557 self.env.reporter.reportRunnerStarting(this); +1558 } +1559 self.queue.start(function () { +1560 self.finishCallback(); +1561 }); +1562 }; +1563 +1564 jasmine.Runner.prototype.finishCallback = function() { +1565 this.env.reporter.reportRunnerResults(this); +1566 }; +1567 +1568 jasmine.Runner.prototype.addSuite = function(suite) { +1569 this.suites_.push(suite); +1570 }; +1571 +1572 jasmine.Runner.prototype.add = function(block) { +1573 if (block instanceof jasmine.Suite) { +1574 this.addSuite(block); +1575 } +1576 this.queue.add(block); +1577 }; +1578 +1579 /** @deprecated */ +1580 jasmine.Runner.prototype.getAllSuites = function() { +1581 return this.suites_; +1582 }; +1583 +1584 +1585 jasmine.Runner.prototype.suites = function() { +1586 return this.suites_; +1587 }; +1588 +1589 jasmine.Runner.prototype.results = function() { +1590 return this.queue.results(); +1591 }; +1592 +1593 /** @deprecated */ +1594 jasmine.Runner.prototype.getResults = function() { +1595 return this.queue.results(); +1596 }; +1597 /** +1598 * Internal representation of a Jasmine specification, or test. +1599 * +1600 * @constructor +1601 * @param {jasmine.Env} env +1602 * @param {jasmine.Suite} suite +1603 * @param {String} description +1604 */ +1605 jasmine.Spec = function(env, suite, description) { +1606 if (!env) { +1607 throw new Error('jasmine.Env() required'); +1608 }; +1609 if (!suite) { +1610 throw new Error('jasmine.Suite() required'); +1611 }; +1612 var spec = this; +1613 spec.id = env.nextSpecId ? env.nextSpecId() : null; +1614 spec.env = env; +1615 spec.suite = suite; +1616 spec.description = description; +1617 spec.queue = new jasmine.Queue(env); +1618 +1619 spec.afterCallbacks = []; +1620 spec.spies_ = []; +1621 +1622 spec.results_ = new jasmine.NestedResults(); +1623 spec.results_.description = description; +1624 spec.matchersClass = null; +1625 }; +1626 +1627 jasmine.Spec.prototype.getFullName = function() { +1628 return this.suite.getFullName() + ' ' + this.description + '.'; +1629 }; +1630 +1631 +1632 jasmine.Spec.prototype.results = function() { +1633 return this.results_; +1634 }; +1635 +1636 jasmine.Spec.prototype.log = function(message) { +1637 return this.results_.log(message); +1638 }; +1639 +1640 /** @deprecated */ +1641 jasmine.Spec.prototype.getResults = function() { +1642 return this.results_; +1643 }; +1644 +1645 jasmine.Spec.prototype.runs = function (func) { +1646 var block = new jasmine.Block(this.env, func, this); +1647 this.addToQueue(block); +1648 return this; +1649 }; +1650 +1651 jasmine.Spec.prototype.addToQueue = function (block) { +1652 if (this.queue.isRunning()) { +1653 this.queue.insertNext(block); +1654 } else { +1655 this.queue.add(block); +1656 } 1657 }; 1658 -1659 jasmine.Spec.prototype.finish = function(onComplete) { -1660 this.removeAllSpies(); -1661 this.finishCallback(); -1662 if (onComplete) { -1663 onComplete(); -1664 } +1659 /** +1660 * @private +1661 * @deprecated +1662 */ +1663 jasmine.Spec.prototype.expects_that = function(actual) { +1664 return this.expect(actual); 1665 }; 1666 -1667 jasmine.Spec.prototype.after = function(doAfter, test) { -1668 -1669 if (this.queue.isRunning()) { -1670 this.queue.add(new jasmine.Block(this.env, doAfter, this)); -1671 } else { -1672 this.afterCallbacks.unshift(doAfter); -1673 } -1674 }; -1675 -1676 jasmine.Spec.prototype.execute = function(onComplete) { -1677 var spec = this; -1678 if (!spec.env.specFilter(spec)) { -1679 spec.results.skipped = true; -1680 spec.finish(onComplete); -1681 return; -1682 } -1683 this.env.reporter.log('>> Jasmine Running ' + this.suite.description + ' ' + this.description + '...'); -1684 -1685 spec.env.currentSpec = spec; -1686 spec.env.currentlyRunningTests = true; -1687 -1688 spec.addBeforesAndAftersToQueue(); -1689 -1690 spec.queue.start(function () { -1691 spec.finish(onComplete); -1692 }); -1693 spec.env.currentlyRunningTests = false; -1694 }; -1695 -1696 jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { -1697 for (var suite = this.suite; suite; suite = suite.parentSuite) { -1698 if (suite.beforeQueue) { -1699 for (var i = 0; i < suite.beforeQueue.length; i++) -1700 this.queue.addBefore(new jasmine.Block(this.env, suite.beforeQueue[i], this)); -1701 } -1702 } -1703 for (i = 0; i < this.afterCallbacks.length; i++) { -1704 this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this)); -1705 } -1706 for (suite = this.suite; suite; suite = suite.parentSuite) { -1707 if (suite.afterQueue) { -1708 for (var j = 0; j < suite.afterQueue.length; j++) -1709 this.queue.add(new jasmine.Block(this.env, suite.afterQueue[j], this)); -1710 } -1711 } -1712 }; -1713 -1714 jasmine.Spec.prototype.explodes = function() { -1715 throw 'explodes function should not have been called'; -1716 }; -1717 -1718 jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { -1719 if (obj == undefined) { -1720 throw "spyOn could not find an object to spy upon for " + methodName + "()"; +1667 jasmine.Spec.prototype.expect = function(actual) { +1668 return new (this.getMatchersClass_())(this.env, actual, this.results_); +1669 }; +1670 +1671 jasmine.Spec.prototype.waits = function(timeout) { +1672 var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this); +1673 this.addToQueue(waitsFunc); +1674 return this; +1675 }; +1676 +1677 jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessage) { +1678 var waitsForFunc = new jasmine.WaitsForBlock(this.env, timeout, latchFunction, timeoutMessage, this); +1679 this.addToQueue(waitsForFunc); +1680 return this; +1681 }; +1682 +1683 jasmine.Spec.prototype.fail = function (e) { +1684 this.results_.addResult(new jasmine.ExpectationResult(false, e ? jasmine.util.formatException(e) : null, null)); +1685 }; +1686 +1687 jasmine.Spec.prototype.getMatchersClass_ = function() { +1688 return this.matchersClass || jasmine.Matchers; +1689 }; +1690 +1691 jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { +1692 var parent = this.getMatchersClass_(); +1693 var newMatchersClass = function() { +1694 parent.apply(this, arguments); +1695 }; +1696 jasmine.util.inherit(newMatchersClass, parent); +1697 for (var method in matchersPrototype) { +1698 newMatchersClass.prototype[method] = matchersPrototype[method]; +1699 } +1700 this.matchersClass = newMatchersClass; +1701 }; +1702 +1703 jasmine.Spec.prototype.finishCallback = function() { +1704 this.env.reporter.reportSpecResults(this); +1705 }; +1706 +1707 jasmine.Spec.prototype.finish = function(onComplete) { +1708 this.removeAllSpies(); +1709 this.finishCallback(); +1710 if (onComplete) { +1711 onComplete(); +1712 } +1713 }; +1714 +1715 jasmine.Spec.prototype.after = function(doAfter, test) { +1716 +1717 if (this.queue.isRunning()) { +1718 this.queue.add(new jasmine.Block(this.env, doAfter, this)); +1719 } else { +1720 this.afterCallbacks.unshift(doAfter); 1721 } -1722 -1723 if (!ignoreMethodDoesntExist && obj[methodName] === undefined) { -1724 throw methodName + '() method does not exist'; -1725 } -1726 -1727 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { -1728 throw new Error(methodName + ' has already been spied upon'); -1729 } -1730 -1731 var spyObj = jasmine.createSpy(methodName); +1722 }; +1723 +1724 jasmine.Spec.prototype.execute = function(onComplete) { +1725 var spec = this; +1726 if (!spec.env.specFilter(spec)) { +1727 spec.results_.skipped = true; +1728 spec.finish(onComplete); +1729 return; +1730 } +1731 this.env.reporter.log('>> Jasmine Running ' + this.suite.description + ' ' + this.description + '...'); 1732 -1733 this.spies_.push(spyObj); -1734 spyObj.baseObj = obj; -1735 spyObj.methodName = methodName; -1736 spyObj.originalValue = obj[methodName]; +1733 spec.env.currentSpec = spec; +1734 spec.env.currentlyRunningTests = true; +1735 +1736 spec.addBeforesAndAftersToQueue(); 1737 -1738 obj[methodName] = spyObj; -1739 -1740 return spyObj; -1741 }; -1742 -1743 jasmine.Spec.prototype.removeAllSpies = function() { -1744 for (var i = 0; i < this.spies_.length; i++) { -1745 var spy = this.spies_[i]; -1746 spy.baseObj[spy.methodName] = spy.originalValue; -1747 } -1748 this.spies_ = []; -1749 }; -1750 -1751 /** -1752 * Internal representation of a Jasmine suite. -1753 * -1754 * @constructor -1755 * @param {jasmine.Env} env -1756 * @param {String} description -1757 * @param {Function} specDefinitions -1758 * @param {jasmine.Suite} parentSuite -1759 */ -1760 jasmine.Suite = function(env, description, specDefinitions, parentSuite) { -1761 var self = this; -1762 self.id = env.nextSuiteId_++; -1763 self.description = description; -1764 self.queue = new jasmine.Queue(env); -1765 self.parentSuite = parentSuite; -1766 self.env = env; -1767 self.beforeQueue = []; -1768 self.afterQueue = []; -1769 self.specs_ = []; -1770 }; -1771 -1772 jasmine.Suite.prototype.getFullName = function() { -1773 var fullName = this.description; -1774 for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { -1775 fullName = parentSuite.description + ' ' + fullName; -1776 } -1777 return fullName; -1778 }; -1779 -1780 jasmine.Suite.prototype.finish = function(onComplete) { -1781 this.env.reporter.reportSuiteResults(this); -1782 this.finished = true; -1783 if (typeof(onComplete) == 'function') { -1784 onComplete(); -1785 } -1786 }; +1738 spec.queue.start(function () { +1739 spec.finish(onComplete); +1740 }); +1741 spec.env.currentlyRunningTests = false; +1742 }; +1743 +1744 jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { +1745 for (var suite = this.suite; suite; suite = suite.parentSuite) { +1746 if (suite.beforeQueue) { +1747 for (var i = 0; i < suite.beforeQueue.length; i++) +1748 this.queue.addBefore(new jasmine.Block(this.env, suite.beforeQueue[i], this)); +1749 } +1750 } +1751 for (i = 0; i < this.afterCallbacks.length; i++) { +1752 this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this)); +1753 } +1754 for (suite = this.suite; suite; suite = suite.parentSuite) { +1755 if (suite.afterQueue) { +1756 for (var j = 0; j < suite.afterQueue.length; j++) +1757 this.queue.add(new jasmine.Block(this.env, suite.afterQueue[j], this)); +1758 } +1759 } +1760 }; +1761 +1762 jasmine.Spec.prototype.explodes = function() { +1763 throw 'explodes function should not have been called'; +1764 }; +1765 +1766 jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { +1767 if (obj == undefined) { +1768 throw "spyOn could not find an object to spy upon for " + methodName + "()"; +1769 } +1770 +1771 if (!ignoreMethodDoesntExist && obj[methodName] === undefined) { +1772 throw methodName + '() method does not exist'; +1773 } +1774 +1775 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { +1776 throw new Error(methodName + ' has already been spied upon'); +1777 } +1778 +1779 var spyObj = jasmine.createSpy(methodName); +1780 +1781 this.spies_.push(spyObj); +1782 spyObj.baseObj = obj; +1783 spyObj.methodName = methodName; +1784 spyObj.originalValue = obj[methodName]; +1785 +1786 obj[methodName] = spyObj; 1787 -1788 jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) { -1789 beforeEachFunction.typeName = 'beforeEach'; -1790 this.beforeQueue.push(beforeEachFunction); -1791 }; -1792 -1793 jasmine.Suite.prototype.afterEach = function(afterEachFunction) { -1794 afterEachFunction.typeName = 'afterEach'; -1795 this.afterQueue.push(afterEachFunction); -1796 }; -1797 -1798 jasmine.Suite.prototype.getResults = function() { -1799 return this.queue.getResults(); -1800 }; -1801 -1802 jasmine.Suite.prototype.add = function(block) { -1803 if (block instanceof jasmine.Suite) { -1804 this.env.currentRunner.addSuite(block); -1805 } else { -1806 this.specs_.push(block); -1807 } -1808 this.queue.add(block); -1809 }; -1810 -1811 /** @deprecated */ -1812 jasmine.Suite.prototype.specCount = function() { -1813 return this.specs_.length; -1814 }; -1815 -1816 jasmine.Suite.prototype.specs = function() { -1817 return this.specs_; +1788 return spyObj; +1789 }; +1790 +1791 jasmine.Spec.prototype.removeAllSpies = function() { +1792 for (var i = 0; i < this.spies_.length; i++) { +1793 var spy = this.spies_[i]; +1794 spy.baseObj[spy.methodName] = spy.originalValue; +1795 } +1796 this.spies_ = []; +1797 }; +1798 +1799 /** +1800 * Internal representation of a Jasmine suite. +1801 * +1802 * @constructor +1803 * @param {jasmine.Env} env +1804 * @param {String} description +1805 * @param {Function} specDefinitions +1806 * @param {jasmine.Suite} parentSuite +1807 */ +1808 jasmine.Suite = function(env, description, specDefinitions, parentSuite) { +1809 var self = this; +1810 self.id = env.nextSuiteId ? env.nextSuiteId() : null; +1811 self.description = description; +1812 self.queue = new jasmine.Queue(env); +1813 self.parentSuite = parentSuite; +1814 self.env = env; +1815 self.beforeQueue = []; +1816 self.afterQueue = []; +1817 self.specs_ = []; 1818 }; 1819 -1820 jasmine.Suite.prototype.execute = function(onComplete) { -1821 var self = this; -1822 this.queue.start(function () { -1823 self.finish(onComplete); -1824 }); -1825 }; -1826 jasmine.WaitsBlock = function(env, timeout, spec) { -1827 this.timeout = timeout; -1828 jasmine.Block.call(this, env, null, spec); -1829 }; -1830 -1831 jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block); -1832 -1833 jasmine.WaitsBlock.prototype.execute = function (onComplete) { -1834 this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...'); -1835 this.env.setTimeout(function () { -1836 onComplete(); -1837 }, this.timeout); -1838 }; -1839 jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) { -1840 this.timeout = timeout; -1841 this.latchFunction = latchFunction; -1842 this.message = message; -1843 this.totalTimeSpentWaitingForLatch = 0; -1844 jasmine.Block.call(this, env, null, spec); -1845 }; -1846 -1847 jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block); -1848 -1849 jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 100; +1820 jasmine.Suite.prototype.getFullName = function() { +1821 var fullName = this.description; +1822 for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { +1823 fullName = parentSuite.description + ' ' + fullName; +1824 } +1825 return fullName; +1826 }; +1827 +1828 jasmine.Suite.prototype.finish = function(onComplete) { +1829 this.env.reporter.reportSuiteResults(this); +1830 this.finished = true; +1831 if (typeof(onComplete) == 'function') { +1832 onComplete(); +1833 } +1834 }; +1835 +1836 jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) { +1837 beforeEachFunction.typeName = 'beforeEach'; +1838 this.beforeQueue.push(beforeEachFunction); +1839 }; +1840 +1841 jasmine.Suite.prototype.afterEach = function(afterEachFunction) { +1842 afterEachFunction.typeName = 'afterEach'; +1843 this.afterQueue.push(afterEachFunction); +1844 }; +1845 +1846 /** @deprecated */ +1847 jasmine.Suite.prototype.getResults = function() { +1848 return this.queue.results(); +1849 }; 1850 -1851 jasmine.WaitsForBlock.prototype.execute = function (onComplete) { -1852 var self = this; -1853 self.env.reporter.log('>> Jasmine waiting for ' + (self.message || 'something to happen')); -1854 var latchFunctionResult; -1855 try { -1856 latchFunctionResult = self.latchFunction.apply(self.spec); -1857 } catch (e) { -1858 self.fail(e); -1859 onComplete(); -1860 return; -1861 } -1862 -1863 if (latchFunctionResult) { -1864 onComplete(); -1865 } else if (self.totalTimeSpentWaitingForLatch >= self.timeout) { -1866 var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen'); -1867 self.fail({ -1868 name: 'timeout', -1869 message: message -1870 }); -1871 self.spec._next(); -1872 } else { -1873 self.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT; -1874 self.env.setTimeout(function () { self.execute(onComplete); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT); -1875 } -1876 }; -1877 // Mock setTimeout, clearTimeout -1878 // Contributed by Pivotal Computer Systems, www.pivotalsf.com -1879 -1880 jasmine.FakeTimer = function() { -1881 this.reset(); -1882 -1883 var self = this; -1884 self.setTimeout = function(funcToCall, millis) { -1885 self.timeoutsMade++; -1886 self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false); -1887 return self.timeoutsMade; -1888 }; -1889 -1890 self.setInterval = function(funcToCall, millis) { -1891 self.timeoutsMade++; -1892 self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true); -1893 return self.timeoutsMade; -1894 }; -1895 -1896 self.clearTimeout = function(timeoutKey) { -1897 self.scheduledFunctions[timeoutKey] = undefined; -1898 }; -1899 -1900 self.clearInterval = function(timeoutKey) { -1901 self.scheduledFunctions[timeoutKey] = undefined; -1902 }; -1903 -1904 }; -1905 -1906 jasmine.FakeTimer.prototype.reset = function() { -1907 this.timeoutsMade = 0; -1908 this.scheduledFunctions = {}; -1909 this.nowMillis = 0; -1910 }; -1911 -1912 jasmine.FakeTimer.prototype.tick = function(millis) { -1913 var oldMillis = this.nowMillis; -1914 var newMillis = oldMillis + millis; -1915 this.runFunctionsWithinRange(oldMillis, newMillis); -1916 this.nowMillis = newMillis; -1917 }; -1918 -1919 jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) { -1920 var scheduledFunc; -1921 var funcsToRun = []; -1922 for (var timeoutKey in this.scheduledFunctions) { -1923 scheduledFunc = this.scheduledFunctions[timeoutKey]; -1924 if (scheduledFunc != undefined && -1925 scheduledFunc.runAtMillis >= oldMillis && -1926 scheduledFunc.runAtMillis <= nowMillis) { -1927 funcsToRun.push(scheduledFunc); -1928 this.scheduledFunctions[timeoutKey] = undefined; -1929 } -1930 } -1931 -1932 if (funcsToRun.length > 0) { -1933 funcsToRun.sort(function(a, b) { -1934 return a.runAtMillis - b.runAtMillis; -1935 }); -1936 for (var i = 0; i < funcsToRun.length; ++i) { -1937 try { -1938 var funcToRun = funcsToRun[i]; -1939 this.nowMillis = funcToRun.runAtMillis; -1940 funcToRun.funcToCall(); -1941 if (funcToRun.recurring) { -1942 this.scheduleFunction(funcToRun.timeoutKey, -1943 funcToRun.funcToCall, -1944 funcToRun.millis, -1945 true); -1946 } -1947 } catch(e) { -1948 } -1949 } -1950 this.runFunctionsWithinRange(oldMillis, nowMillis); -1951 } -1952 }; -1953 -1954 jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) { -1955 this.scheduledFunctions[timeoutKey] = { -1956 runAtMillis: this.nowMillis + millis, -1957 funcToCall: funcToCall, -1958 recurring: recurring, -1959 timeoutKey: timeoutKey, -1960 millis: millis -1961 }; -1962 }; -1963 +1851 jasmine.Suite.prototype.results = function() { +1852 return this.queue.results(); +1853 }; +1854 +1855 jasmine.Suite.prototype.add = function(block) { +1856 if (block instanceof jasmine.Suite) { +1857 this.env.currentRunner.addSuite(block); +1858 } else { +1859 this.specs_.push(block); +1860 } +1861 this.queue.add(block); +1862 }; +1863 +1864 /** @deprecated */ +1865 jasmine.Suite.prototype.specCount = function() { +1866 return this.specs_.length; +1867 }; +1868 +1869 jasmine.Suite.prototype.specs = function() { +1870 return this.specs_; +1871 }; +1872 +1873 jasmine.Suite.prototype.execute = function(onComplete) { +1874 var self = this; +1875 this.queue.start(function () { +1876 self.finish(onComplete); +1877 }); +1878 }; +1879 jasmine.WaitsBlock = function(env, timeout, spec) { +1880 this.timeout = timeout; +1881 jasmine.Block.call(this, env, null, spec); +1882 }; +1883 +1884 jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block); +1885 +1886 jasmine.WaitsBlock.prototype.execute = function (onComplete) { +1887 this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...'); +1888 this.env.setTimeout(function () { +1889 onComplete(); +1890 }, this.timeout); +1891 }; +1892 jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) { +1893 this.timeout = timeout; +1894 this.latchFunction = latchFunction; +1895 this.message = message; +1896 this.totalTimeSpentWaitingForLatch = 0; +1897 jasmine.Block.call(this, env, null, spec); +1898 }; +1899 +1900 jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block); +1901 +1902 jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 100; +1903 +1904 jasmine.WaitsForBlock.prototype.execute = function (onComplete) { +1905 var self = this; +1906 self.env.reporter.log('>> Jasmine waiting for ' + (self.message || 'something to happen')); +1907 var latchFunctionResult; +1908 try { +1909 latchFunctionResult = self.latchFunction.apply(self.spec); +1910 } catch (e) { +1911 self.spec.fail(e); +1912 onComplete(); +1913 return; +1914 } +1915 +1916 if (latchFunctionResult) { +1917 onComplete(); +1918 } else if (self.totalTimeSpentWaitingForLatch >= self.timeout) { +1919 var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen'); +1920 self.spec.fail({ +1921 name: 'timeout', +1922 message: message +1923 }); +1924 self.spec._next(); +1925 } else { +1926 self.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT; +1927 self.env.setTimeout(function () { self.execute(onComplete); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT); +1928 } +1929 }; +1930 // Mock setTimeout, clearTimeout +1931 // Contributed by Pivotal Computer Systems, www.pivotalsf.com +1932 +1933 jasmine.FakeTimer = function() { +1934 this.reset(); +1935 +1936 var self = this; +1937 self.setTimeout = function(funcToCall, millis) { +1938 self.timeoutsMade++; +1939 self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false); +1940 return self.timeoutsMade; +1941 }; +1942 +1943 self.setInterval = function(funcToCall, millis) { +1944 self.timeoutsMade++; +1945 self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true); +1946 return self.timeoutsMade; +1947 }; +1948 +1949 self.clearTimeout = function(timeoutKey) { +1950 self.scheduledFunctions[timeoutKey] = undefined; +1951 }; +1952 +1953 self.clearInterval = function(timeoutKey) { +1954 self.scheduledFunctions[timeoutKey] = undefined; +1955 }; +1956 +1957 }; +1958 +1959 jasmine.FakeTimer.prototype.reset = function() { +1960 this.timeoutsMade = 0; +1961 this.scheduledFunctions = {}; +1962 this.nowMillis = 0; +1963 }; 1964 -1965 jasmine.Clock = { -1966 defaultFakeTimer: new jasmine.FakeTimer(), -1967 -1968 reset: function() { -1969 jasmine.Clock.assertInstalled(); -1970 jasmine.Clock.defaultFakeTimer.reset(); -1971 }, -1972 -1973 tick: function(millis) { -1974 jasmine.Clock.assertInstalled(); -1975 jasmine.Clock.defaultFakeTimer.tick(millis); -1976 }, -1977 -1978 runFunctionsWithinRange: function(oldMillis, nowMillis) { -1979 jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis); -1980 }, -1981 -1982 scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) { -1983 jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring); -1984 }, -1985 -1986 useMock: function() { -1987 var spec = jasmine.getEnv().currentSpec; -1988 spec.after(jasmine.Clock.uninstallMock); -1989 -1990 jasmine.Clock.installMock(); -1991 }, -1992 -1993 installMock: function() { -1994 jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer; -1995 }, -1996 -1997 uninstallMock: function() { -1998 jasmine.Clock.assertInstalled(); -1999 jasmine.Clock.installed = jasmine.Clock.real; -2000 }, -2001 -2002 real: { -2003 setTimeout: window.setTimeout, -2004 clearTimeout: window.clearTimeout, -2005 setInterval: window.setInterval, -2006 clearInterval: window.clearInterval -2007 }, -2008 -2009 assertInstalled: function() { -2010 if (jasmine.Clock.installed != jasmine.Clock.defaultFakeTimer) { -2011 throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()"); -2012 } -2013 }, -2014 -2015 installed: null -2016 }; -2017 jasmine.Clock.installed = jasmine.Clock.real; -2018 -2019 window.setTimeout = function(funcToCall, millis) { -2020 return jasmine.Clock.installed.setTimeout.apply(this, arguments); -2021 }; -2022 -2023 window.setInterval = function(funcToCall, millis) { -2024 return jasmine.Clock.installed.setInterval.apply(this, arguments); -2025 }; -2026 -2027 window.clearTimeout = function(timeoutKey) { -2028 return jasmine.Clock.installed.clearTimeout.apply(this, arguments); -2029 }; +1965 jasmine.FakeTimer.prototype.tick = function(millis) { +1966 var oldMillis = this.nowMillis; +1967 var newMillis = oldMillis + millis; +1968 this.runFunctionsWithinRange(oldMillis, newMillis); +1969 this.nowMillis = newMillis; +1970 }; +1971 +1972 jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) { +1973 var scheduledFunc; +1974 var funcsToRun = []; +1975 for (var timeoutKey in this.scheduledFunctions) { +1976 scheduledFunc = this.scheduledFunctions[timeoutKey]; +1977 if (scheduledFunc != undefined && +1978 scheduledFunc.runAtMillis >= oldMillis && +1979 scheduledFunc.runAtMillis <= nowMillis) { +1980 funcsToRun.push(scheduledFunc); +1981 this.scheduledFunctions[timeoutKey] = undefined; +1982 } +1983 } +1984 +1985 if (funcsToRun.length > 0) { +1986 funcsToRun.sort(function(a, b) { +1987 return a.runAtMillis - b.runAtMillis; +1988 }); +1989 for (var i = 0; i < funcsToRun.length; ++i) { +1990 try { +1991 var funcToRun = funcsToRun[i]; +1992 this.nowMillis = funcToRun.runAtMillis; +1993 funcToRun.funcToCall(); +1994 if (funcToRun.recurring) { +1995 this.scheduleFunction(funcToRun.timeoutKey, +1996 funcToRun.funcToCall, +1997 funcToRun.millis, +1998 true); +1999 } +2000 } catch(e) { +2001 } +2002 } +2003 this.runFunctionsWithinRange(oldMillis, nowMillis); +2004 } +2005 }; +2006 +2007 jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) { +2008 this.scheduledFunctions[timeoutKey] = { +2009 runAtMillis: this.nowMillis + millis, +2010 funcToCall: funcToCall, +2011 recurring: recurring, +2012 timeoutKey: timeoutKey, +2013 millis: millis +2014 }; +2015 }; +2016 +2017 +2018 jasmine.Clock = { +2019 defaultFakeTimer: new jasmine.FakeTimer(), +2020 +2021 reset: function() { +2022 jasmine.Clock.assertInstalled(); +2023 jasmine.Clock.defaultFakeTimer.reset(); +2024 }, +2025 +2026 tick: function(millis) { +2027 jasmine.Clock.assertInstalled(); +2028 jasmine.Clock.defaultFakeTimer.tick(millis); +2029 }, 2030 -2031 window.clearInterval = function(timeoutKey) { -2032 return jasmine.Clock.installed.clearInterval.apply(this, arguments); -2033 }; +2031 runFunctionsWithinRange: function(oldMillis, nowMillis) { +2032 jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis); +2033 }, 2034 -2035 \ No newline at end of file +2035 scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) { +2036 jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring); +2037 }, +2038 +2039 useMock: function() { +2040 var spec = jasmine.getEnv().currentSpec; +2041 spec.after(jasmine.Clock.uninstallMock); +2042 +2043 jasmine.Clock.installMock(); +2044 }, +2045 +2046 installMock: function() { +2047 jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer; +2048 }, +2049 +2050 uninstallMock: function() { +2051 jasmine.Clock.assertInstalled(); +2052 jasmine.Clock.installed = jasmine.Clock.real; +2053 }, +2054 +2055 real: { +2056 setTimeout: window.setTimeout, +2057 clearTimeout: window.clearTimeout, +2058 setInterval: window.setInterval, +2059 clearInterval: window.clearInterval +2060 }, +2061 +2062 assertInstalled: function() { +2063 if (jasmine.Clock.installed != jasmine.Clock.defaultFakeTimer) { +2064 throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()"); +2065 } +2066 }, +2067 +2068 installed: null +2069 }; +2070 jasmine.Clock.installed = jasmine.Clock.real; +2071 +2072 window.setTimeout = function(funcToCall, millis) { +2073 return jasmine.Clock.installed.setTimeout.apply(this, arguments); +2074 }; +2075 +2076 window.setInterval = function(funcToCall, millis) { +2077 return jasmine.Clock.installed.setInterval.apply(this, arguments); +2078 }; +2079 +2080 window.clearTimeout = function(timeoutKey) { +2081 return jasmine.Clock.installed.clearTimeout.apply(this, arguments); +2082 }; +2083 +2084 window.clearInterval = function(timeoutKey) { +2085 return jasmine.Clock.installed.clearInterval.apply(this, arguments); +2086 }; +2087 +2088 \ No newline at end of file diff --git a/lib/TrivialReporter.js b/lib/TrivialReporter.js index 5b26409..20a209c 100644 --- a/lib/TrivialReporter.js +++ b/lib/TrivialReporter.js @@ -52,7 +52,7 @@ jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) { }; jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) { - var results = runner.getResults(); + var results = runner.results(); var className = (results.failedCount > 0) ? "runner failed" : "runner passed"; this.runnerDiv.setAttribute("class", className); var message = results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s"); @@ -61,7 +61,7 @@ jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) { }; jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) { - var results = suite.getResults(); + var results = suite.results(); var status = results.passed() ? 'passed' : 'failed'; if (results.totalCount == 0) { // todo: change this to check results.skipped status = 'skipped'; @@ -70,7 +70,7 @@ jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) { }; jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) { - var results = spec.getResults(); + var results = spec.results(); var status = results.passed() ? 'passed' : 'failed'; if (results.skipped) { status = 'skipped'; diff --git a/lib/jasmine-0.9.0.js b/lib/jasmine-0.9.0.js index 21ca905..bae3404 100644 --- a/lib/jasmine-0.9.0.js +++ b/lib/jasmine-0.9.0.js @@ -323,7 +323,7 @@ jasmine.createSpyObj = function(baseName, methodNames) { }; jasmine.log = function(message) { - jasmine.getEnv().currentSpec.getResults().log(message); + jasmine.getEnv().currentSpec.log(message); }; /** @@ -517,7 +517,7 @@ jasmine.version_= { "major": 0, "minor": 9, "build": 0, - "revision": 1252545255 + "revision": 1254161532 }; /** * @namespace @@ -610,6 +610,9 @@ jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout; jasmine.Env.prototype.setInterval = jasmine.setInterval; jasmine.Env.prototype.clearInterval = jasmine.clearInterval; +/** + * @returns an object containing jasmine version build info, if set. + */ jasmine.Env.prototype.version = function () { if (jasmine.version_) { return jasmine.version_; @@ -618,6 +621,20 @@ jasmine.Env.prototype.version = function () { } }; +/** + * @returns a sequential integer starting at 0 + */ +jasmine.Env.prototype.nextSpecId = function () { + return this.nextSpecId_++; +}; + +/** + * @returns a sequential integer starting at 0 + */ +jasmine.Env.prototype.nextSuiteId = function () { + return this.nextSuiteId_++; +}; + /** * Register a reporter to receive status updates from Jasmine. * @param {jasmine.Reporter} reporter An object which will receive status updates. @@ -678,7 +695,7 @@ jasmine.Env.prototype.it = function(description, func) { jasmine.Env.prototype.xit = function(desc, func) { return { - id: this.nextSpecId_++, + id: this.nextSpecId(), runs: function() { } }; @@ -820,14 +837,10 @@ jasmine.Block.prototype.execute = function(onComplete) { try { this.func.apply(this.spec); } catch (e) { - this.fail(e); + this.spec.fail(e); } onComplete(); }; - -jasmine.Block.prototype.fail = function(e) { - this.spec.results.addResult(new jasmine.ExpectationResult(false, jasmine.util.formatException(e), null)); -}; /** JavaScript API reporter. * * @constructor @@ -835,8 +848,8 @@ jasmine.Block.prototype.fail = function(e) { jasmine.JsApiReporter = function() { this.started = false; this.finished = false; - this.suites = []; - this.results = {}; + this.suites_ = []; + this.results_ = {}; }; jasmine.JsApiReporter.prototype.reportRunnerStarting = function(runner) { @@ -844,10 +857,14 @@ jasmine.JsApiReporter.prototype.reportRunnerStarting = function(runner) { var suites = runner.suites(); for (var i = 0; i < suites.length; i++) { var suite = suites[i]; - this.suites.push(this.summarize_(suite)); + this.suites_.push(this.summarize_(suite)); } }; +jasmine.JsApiReporter.prototype.suites = function() { + return this.suites_; +}; + jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) { var isSuite = suiteOrSpec instanceof jasmine.Suite var summary = { @@ -865,6 +882,14 @@ jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) { return summary; }; +jasmine.JsApiReporter.prototype.results = function() { + return this.results_; +}; + +jasmine.JsApiReporter.prototype.resultsForSpec = function(specId) { + return this.results_[specId]; +}; + //noinspection JSUnusedLocalSymbols jasmine.JsApiReporter.prototype.reportRunnerResults = function(runner) { this.finished = true; @@ -876,9 +901,9 @@ jasmine.JsApiReporter.prototype.reportSuiteResults = function(suite) { //noinspection JSUnusedLocalSymbols jasmine.JsApiReporter.prototype.reportSpecResults = function(spec) { - this.results[spec.id] = { - messages: spec.results.getItems(), - result: spec.results.failedCount > 0 ? "failed" : "passed" + this.results_[spec.id] = { + messages: spec.results().getItems(), + result: spec.results().failedCount > 0 ? "failed" : "passed" }; }; @@ -890,19 +915,24 @@ jasmine.Matchers = function(env, actual, results) { this.env = env; this.actual = actual; this.passing_message = 'Passed.'; - this.results = results || new jasmine.NestedResults(); + this.results_ = results || new jasmine.NestedResults(); }; jasmine.Matchers.pp = function(str) { return jasmine.util.htmlEscape(jasmine.pp(str)); }; +/** @deprecated */ jasmine.Matchers.prototype.getResults = function() { - return this.results; + return this.results_; +}; + +jasmine.Matchers.prototype.results = function() { + return this.results_; }; jasmine.Matchers.prototype.report = function(result, failing_message, details) { - this.results.addResult(new jasmine.ExpectationResult(result, result ? this.passing_message : failing_message, details)); + this.results_.addResult(new jasmine.ExpectationResult(result, result ? this.passing_message : failing_message, details)); return result; }; @@ -1464,11 +1494,11 @@ jasmine.Queue.prototype.finish = function () { } }; -jasmine.Queue.prototype.getResults = function () { +jasmine.Queue.prototype.results = function () { var results = new jasmine.NestedResults(); for (var i = 0; i < this.blocks.length; i++) { - if (this.blocks[i].getResults) { - results.addResult(this.blocks[i].getResults()); + if (this.blocks[i].results) { + results.addResult(this.blocks[i].results()); } } return results; @@ -1556,8 +1586,13 @@ jasmine.Runner.prototype.suites = function() { return this.suites_; }; +jasmine.Runner.prototype.results = function() { + return this.queue.results(); +}; + +/** @deprecated */ jasmine.Runner.prototype.getResults = function() { - return this.queue.getResults(); + return this.queue.results(); }; /** * Internal representation of a Jasmine specification, or test. @@ -1568,8 +1603,14 @@ jasmine.Runner.prototype.getResults = function() { * @param {String} description */ jasmine.Spec = function(env, suite, description) { + if (!env) { + throw new Error('jasmine.Env() required'); + }; + if (!suite) { + throw new Error('jasmine.Suite() required'); + }; var spec = this; - spec.id = env.nextSpecId_++; + spec.id = env.nextSpecId ? env.nextSpecId() : null; spec.env = env; spec.suite = suite; spec.description = description; @@ -1578,8 +1619,8 @@ jasmine.Spec = function(env, suite, description) { spec.afterCallbacks = []; spec.spies_ = []; - spec.results = new jasmine.NestedResults(); - spec.results.description = description; + spec.results_ = new jasmine.NestedResults(); + spec.results_.description = description; spec.matchersClass = null; }; @@ -1587,8 +1628,18 @@ jasmine.Spec.prototype.getFullName = function() { return this.suite.getFullName() + ' ' + this.description + '.'; }; + +jasmine.Spec.prototype.results = function() { + return this.results_; +}; + +jasmine.Spec.prototype.log = function(message) { + return this.results_.log(message); +}; + +/** @deprecated */ jasmine.Spec.prototype.getResults = function() { - return this.results; + return this.results_; }; jasmine.Spec.prototype.runs = function (func) { @@ -1613,11 +1664,8 @@ jasmine.Spec.prototype.expects_that = function(actual) { return this.expect(actual); }; -/** - * @private - */ jasmine.Spec.prototype.expect = function(actual) { - return new (this.getMatchersClass_())(this.env, actual, this.results); + return new (this.getMatchersClass_())(this.env, actual, this.results_); }; jasmine.Spec.prototype.waits = function(timeout) { @@ -1632,8 +1680,8 @@ jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessag return this; }; -jasmine.Spec.prototype.failWithException = function (e) { - this.results.addResult(new jasmine.ExpectationResult(false, jasmine.util.formatException(e), null)); +jasmine.Spec.prototype.fail = function (e) { + this.results_.addResult(new jasmine.ExpectationResult(false, e ? jasmine.util.formatException(e) : null, null)); }; jasmine.Spec.prototype.getMatchersClass_ = function() { @@ -1676,7 +1724,7 @@ jasmine.Spec.prototype.after = function(doAfter, test) { jasmine.Spec.prototype.execute = function(onComplete) { var spec = this; if (!spec.env.specFilter(spec)) { - spec.results.skipped = true; + spec.results_.skipped = true; spec.finish(onComplete); return; } @@ -1759,7 +1807,7 @@ jasmine.Spec.prototype.removeAllSpies = function() { */ jasmine.Suite = function(env, description, specDefinitions, parentSuite) { var self = this; - self.id = env.nextSuiteId_++; + self.id = env.nextSuiteId ? env.nextSuiteId() : null; self.description = description; self.queue = new jasmine.Queue(env); self.parentSuite = parentSuite; @@ -1795,8 +1843,13 @@ jasmine.Suite.prototype.afterEach = function(afterEachFunction) { this.afterQueue.push(afterEachFunction); }; +/** @deprecated */ jasmine.Suite.prototype.getResults = function() { - return this.queue.getResults(); + return this.queue.results(); +}; + +jasmine.Suite.prototype.results = function() { + return this.queue.results(); }; jasmine.Suite.prototype.add = function(block) { @@ -1855,7 +1908,7 @@ jasmine.WaitsForBlock.prototype.execute = function (onComplete) { try { latchFunctionResult = self.latchFunction.apply(self.spec); } catch (e) { - self.fail(e); + self.spec.fail(e); onComplete(); return; } @@ -1864,7 +1917,7 @@ jasmine.WaitsForBlock.prototype.execute = function (onComplete) { onComplete(); } else if (self.totalTimeSpentWaitingForLatch >= self.timeout) { var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen'); - self.fail({ + self.spec.fail({ name: 'timeout', message: message }); diff --git a/spec/suites/EnvSpec.js b/spec/suites/EnvSpec.js index 3a05d3c..833c24f 100644 --- a/spec/suites/EnvSpec.js +++ b/spec/suites/EnvSpec.js @@ -1,4 +1,22 @@ describe("jasmine.Env", function() { + + describe('ids', function () { + var env; + beforeEach(function() { + env = new jasmine.Env(); + }); + it('nextSpecId should return consecutive integers, starting at 0', function () { + expect(env.nextSpecId()).toEqual(0); + expect(env.nextSpecId()).toEqual(1); + expect(env.nextSpecId()).toEqual(2); + }); + + it('nextSuiteId should return consecutive integers, starting at 0', function () { + expect(env.nextSuiteId()).toEqual(0); + expect(env.nextSuiteId()).toEqual(1); + expect(env.nextSuiteId()).toEqual(2); + }); + }); describe("reporting", function() { var env; var fakeReporter; diff --git a/spec/suites/ExceptionsSpec.js b/spec/suites/ExceptionsSpec.js index 9b9e5e2..f53814d 100644 --- a/spec/suites/ExceptionsSpec.js +++ b/spec/suites/ExceptionsSpec.js @@ -76,7 +76,7 @@ describe('Exceptions:', function() { suite.execute(); fakeTimer.tick(2500); - var suiteResults = suite.getResults(); + var suiteResults = suite.results(); var specResults = suiteResults.getItems(); expect(suiteResults.passed()).toEqual(false); diff --git a/spec/suites/JsApiReporterSpec.js b/spec/suites/JsApiReporterSpec.js new file mode 100644 index 0000000..68cfef5 --- /dev/null +++ b/spec/suites/JsApiReporterSpec.js @@ -0,0 +1,47 @@ +describe('JsApiReporterSpec', function () { + + + describe('results', function () { + var reporter, spec1, spec2, expectedSpec1Results, expectedSpec2Results; + + beforeEach(function() { + var env = new jasmine.Env(); + var suite = new jasmine.Suite(env); + spec1 = new jasmine.Spec(env, suite); + spec1.runs(function () { + this.expect(true).toEqual(true); + }); + expectedSpec1Results = { + messages: spec1.results().getItems(), + result: "passed" + }; + spec2 = new jasmine.Spec(env, suite); + spec2.runs(function () { + this.expect(true).toEqual(false); + }); + expectedSpec2Results = { + messages: spec2.results().getItems(), + result: "failed" + }; + + spec1.execute(); + spec2.execute(); + + reporter = new jasmine.JsApiReporter(); + reporter.reportSpecResults(spec1); + reporter.reportSpecResults(spec2); + }); + + it('resultForSpec() should return the result for the given spec', function () { + expect(reporter.resultsForSpec(spec1.id)).toEqual(expectedSpec1Results); + expect(reporter.resultsForSpec(spec2.id)).toEqual(expectedSpec2Results); + + }); + + it('results() should return a hash of all results, indexed by spec id', function () { + expect(reporter.results()[spec1.id]).toEqual(expectedSpec1Results); + expect(reporter.results()[spec2.id]).toEqual(expectedSpec2Results); + }); + + }); +}); \ No newline at end of file diff --git a/spec/suites/MatchersSpec.js b/spec/suites/MatchersSpec.js index 91fcd17..7ea452a 100644 --- a/spec/suites/MatchersSpec.js +++ b/spec/suites/MatchersSpec.js @@ -12,8 +12,8 @@ describe("jasmine.Matchers", function() { function detailsFor(actual, matcherName, matcherArgs) { var matcher = match(actual); matcher[matcherName].apply(matcher, matcherArgs); - expect(matcher.getResults().getItems().length).toEqual(1); - return matcher.getResults().getItems()[0].details; + expect(matcher.results().getItems().length).toEqual(1); + return matcher.results().getItems()[0].details; } it("toEqual with primitives, objects, dates, html nodes, etc.", function() { @@ -222,7 +222,7 @@ describe("jasmine.Matchers", function() { expected = match(TestClass.someFunction); expect(expected.wasCalledWith('c', 'b', 'a')).toEqual(false); - expect(expected.getResults().getItems()[0].passed()).toEqual(false); + expect(expected.results().getItems()[0].passed()).toEqual(false); TestClass.someFunction.reset(); TestClass.someFunction('a', 'b', 'c'); diff --git a/spec/suites/RunnerSpec.js b/spec/suites/RunnerSpec.js index 1618b9a..e193d07 100644 --- a/spec/suites/RunnerSpec.js +++ b/spec/suites/RunnerSpec.js @@ -31,7 +31,7 @@ describe('RunnerTest', function() { env.currentRunner.execute(); - var runnerResults = env.currentRunner.getResults(); + var runnerResults = env.currentRunner.results(); expect(runnerResults.totalCount).toEqual(2); expect(runnerResults.passedCount).toEqual(1); expect(runnerResults.failedCount).toEqual(1); @@ -57,7 +57,7 @@ describe('RunnerTest', function() { env.currentRunner.execute(); - var runnerResults = env.currentRunner.getResults(); + var runnerResults = env.currentRunner.results(); expect(runnerResults.totalCount).toEqual(1); expect(runnerResults.passedCount).toEqual(0); expect(runnerResults.failedCount).toEqual(1); @@ -82,7 +82,7 @@ describe('RunnerTest', function() { env.currentRunner.execute(); - var results = env.currentRunner.getResults(); + var results = env.currentRunner.results(); expect(results.totalCount).toEqual(2); expect(results.passedCount).toEqual(1); expect(results.failedCount).toEqual(1); @@ -119,7 +119,7 @@ describe('RunnerTest', function() { //This blows up the JSApiReporter. //expect(fakeReporter.reportRunnerResults).wasCalledWith(env.currentRunner); expect(fakeReporter.reportRunnerResults).wasCalled(); - expect(fakeReporter.reportRunnerResults.mostRecentCall.args[0].getResults()).toEqual(env.currentRunner.getResults()); + expect(fakeReporter.reportRunnerResults.mostRecentCall.args[0].results()).toEqual(env.currentRunner.results()); }); diff --git a/spec/suites/SpecRunningSpec.js b/spec/suites/SpecRunningSpec.js index dc25e37..e360e07 100644 --- a/spec/suites/SpecRunningSpec.js +++ b/spec/suites/SpecRunningSpec.js @@ -67,13 +67,13 @@ describe("jasmine spec running", function () { expect(specWithNoBody.description).toEqual('new spec'); - expect(specWithExpectation.results.getItems().length).toEqual(1); // "Results aren't there after a spec was executed" - expect(specWithExpectation.results.getItems()[0].passed()).toEqual(true); // "Results has a result, but it's true" - expect(specWithExpectation.results.description).toEqual('spec with an expectation'); // "Spec's results did not get the spec's description" + expect(specWithExpectation.results().getItems().length).toEqual(1); // "Results aren't there after a spec was executed" + expect(specWithExpectation.results().getItems()[0].passed()).toEqual(true); // "Results has a result, but it's true" + expect(specWithExpectation.results().description).toEqual('spec with an expectation'); // "Spec's results did not get the spec's description" - expect(specWithFailingExpectations.results.getItems()[0].passed()).toEqual(false); // "Expectation that failed, passed" + expect(specWithFailingExpectations.results().getItems()[0].passed()).toEqual(false); // "Expectation that failed, passed" - expect(specWithMultipleExpectations.results.getItems().length).toEqual(2); // "Spec doesn't support multiple expectations" + expect(specWithMultipleExpectations.results().getItems().length).toEqual(2); // "Spec doesn't support multiple expectations" }); it("should work without a runs block", function() { @@ -89,10 +89,10 @@ describe("jasmine spec running", function () { another_spec.execute(); another_spec.done = true; - expect(another_spec.results.getItems().length).toEqual(2); - expect(another_spec.results.getItems()[0].passed()).toEqual(true); // "In a spec without a run block, expected first expectation result to be true but was false" - expect(another_spec.results.getItems()[1].passed()).toEqual(false); // "In a spec without a run block, expected second expectation result to be false but was true"; - expect(another_spec.results.description).toEqual('spec with an expectation'); // "In a spec without a run block, results did not include the spec's description"; + expect(another_spec.results().getItems().length).toEqual(2); + expect(another_spec.results().getItems()[0].passed()).toEqual(true); // "In a spec without a run block, expected first expectation result to be true but was false" + expect(another_spec.results().getItems()[1].passed()).toEqual(false); // "In a spec without a run block, expected second expectation result to be false but was true"; + expect(another_spec.results().description).toEqual('spec with an expectation'); // "In a spec without a run block, results did not include the spec's description"; }); it('should queue waits and runs that it encounters while executing specs', function() { @@ -141,8 +141,8 @@ describe("jasmine spec running", function () { a_spec.execute(); - expect(a_spec.results.getItems().length).toEqual(1); // 'No call to waits(): Spec queue did not run all functions'; - expect(a_spec.results.getItems()[0].passed()).toEqual(true); // 'No call to waits(): Queued expectation failed'; + expect(a_spec.results().getItems().length).toEqual(1); // 'No call to waits(): Spec queue did not run all functions'; + expect(a_spec.results().getItems()[0].passed()).toEqual(true); // 'No call to waits(): Queued expectation failed'; foo = 0; env.describe('test async spec', function() { @@ -161,15 +161,15 @@ describe("jasmine spec running", function () { a_spec.execute(); - expect(a_spec.results.getItems().length).toEqual(0); + expect(a_spec.results().getItems().length).toEqual(0); fakeTimer.tick(500); - expect(a_spec.results.getItems().length).toEqual(0); + expect(a_spec.results().getItems().length).toEqual(0); fakeTimer.tick(500); - expect(a_spec.results.getItems().length).toEqual(1); // 'Calling waits(): Spec queue did not run all functions'; + expect(a_spec.results().getItems().length).toEqual(1); // 'Calling waits(): Spec queue did not run all functions'; - expect(a_spec.results.getItems()[0].passed()).toEqual(true); // 'Calling waits(): Queued expectation failed'; + expect(a_spec.results().getItems()[0].passed()).toEqual(true); // 'Calling waits(): Queued expectation failed'; var bar = 0; var another_spec; @@ -199,8 +199,8 @@ describe("jasmine spec running", function () { fakeTimer.tick(1000); - expect(another_spec.results.getItems().length).toEqual(1); - expect(another_spec.results.getItems()[0].passed()).toEqual(true); + expect(another_spec.results().getItems().length).toEqual(1); + expect(another_spec.results().getItems()[0].passed()).toEqual(true); var baz = 0; var yet_another_spec; @@ -225,8 +225,8 @@ describe("jasmine spec running", function () { fakeTimer.tick(150); - expect(yet_another_spec.results.getItems().length).toEqual(1); - expect(yet_another_spec.results.getItems()[0].passed()).toEqual(false); + expect(yet_another_spec.results().getItems().length).toEqual(1); + expect(yet_another_spec.results().getItems()[0].passed()).toEqual(false); }); it("testAsyncSpecsWithMockSuite", function () { @@ -254,8 +254,8 @@ describe("jasmine spec running", function () { another_spec.execute(); fakeTimer.tick(2000); - expect(another_spec.results.getItems().length).toEqual(1); - expect(another_spec.results.getItems()[0].passed()).toEqual(true); + expect(another_spec.results().getItems().length).toEqual(1); + expect(another_spec.results().getItems()[0].passed()).toEqual(true); }); it("testWaitsFor", function() { @@ -304,7 +304,7 @@ describe("jasmine spec running", function () { spec.execute(); fakeTimer.tick(1000); - var actual = spec.results.getItems()[0].message; + var actual = spec.results().getItems()[0].message; var expected = 'timeout: timed out after 500 msec waiting for my awesome condition'; expect(actual).toEqual(expected); }); @@ -334,7 +334,7 @@ describe("jasmine spec running", function () { expect(runsBlockExecuted).toEqual(false); fakeTimer.tick(400); expect(runsBlockExecuted).toEqual(false); - var actual = spec.results.getItems()[0].message; + var actual = spec.results().getItems()[0].message; var expected = 'timeout: timed out after 500 msec waiting for something to happen'; expect(actual).toEqual(expected, 'expected "' + expected + '" but found "' + actual + '"'); @@ -425,8 +425,8 @@ describe("jasmine spec running", function () { var suite = suiteWithBefore; - expect(suite.getResults().getItems()[0].passed()).toEqual(true); // "testBeforeAndAfterCallbacks: the first spec's foo should have been 2"); - expect(suite.getResults().getItems()[1].passed()).toEqual(true); // "testBeforeAndAfterCallbacks: the second spec's this.foo should have been 2"); + expect(suite.results().getItems()[0].passed()).toEqual(true); // "testBeforeAndAfterCallbacks: the first spec's foo should have been 2"); + expect(suite.results().getItems()[1].passed()).toEqual(true); // "testBeforeAndAfterCallbacks: the second spec's this.foo should have been 2"); var foo = 1; @@ -453,8 +453,8 @@ describe("jasmine spec running", function () { suite = suiteWithAfter; expect(suite.afterEach.length).toEqual(1); - expect(suite.getResults().getItems()[0].passed()).toEqual(true); - expect(suite.getResults().getItems()[1].passed()).toEqual(true); + expect(suite.results().getItems()[0].passed()).toEqual(true); + expect(suite.results().getItems()[1].passed()).toEqual(true); expect(foo).toEqual(0); }); @@ -809,7 +809,7 @@ describe("jasmine spec running", function () { suite.execute(); expect(report).toEqual("firstsecond"); - var suiteResults = suite.getResults(); + var suiteResults = suite.results(); expect(suiteResults.getItems()[0].getItems()[0].passed()).toEqual(false); expect(suiteResults.getItems()[1].getItems()[0].passed()).toEqual(true); }); @@ -848,7 +848,7 @@ describe("jasmine spec running", function () { expect(report).toEqual("firstsecondthird"); // "all tests should run"); //After each errors should not go in spec results because it confuses the count. - var suiteResults = suite.getResults(); + var suiteResults = suite.results(); expect(suiteResults.getItems().length).toEqual(3, 'testAfterExecutesSafely should have results for three specs'); expect(suiteResults.getItems()[0].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 1st spec should pass"); @@ -973,7 +973,7 @@ describe("jasmine spec running", function () { env.execute(); - var runnerResults = env.currentRunner.getResults(); + var runnerResults = env.currentRunner.results(); expect(runnerResults.totalCount).toEqual(3); expect(runnerResults.passedCount).toEqual(3); expect(runnerResults.failedCount).toEqual(0); @@ -1011,7 +1011,7 @@ describe("jasmine spec running", function () { suite.execute(); fakeTimer.tick(600); expect(spec.foo).toEqual(2); - var suiteResults = suite.getResults(); + var suiteResults = suite.results(); expect(suiteResults.getItems()[0].getItems().length).toEqual(2); expect(suiteResults.getItems()[0].getItems()[0].passed()).toEqual(false); expect(suiteResults.getItems()[0].getItems()[1].passed()).toEqual(true); diff --git a/spec/suites/SpecSpec.js b/spec/suites/SpecSpec.js new file mode 100644 index 0000000..ba060ef --- /dev/null +++ b/spec/suites/SpecSpec.js @@ -0,0 +1,109 @@ +describe('Spec', function () { + var env, suite; + beforeEach(function() { + env = new jasmine.Env(); + suite = new jasmine.Suite(env, 'suite 1'); + }); + + describe('initialization', function () { + + it('should raise an error if an env is not passed', function () { + try { + new jasmine.Spec(); + } + catch (e) { + expect(e.message).toEqual('jasmine.Env() required'); + } + }); + + it('should raise an error if a suite is not passed', function () { + try { + new jasmine.Spec(env); + } + catch (e) { + expect(e.message).toEqual('jasmine.Suite() required'); + } + }); + + it('should assign sequential ids for specs belonging to the same env', function () { + var spec1 = new jasmine.Spec(env, suite); + var spec2 = new jasmine.Spec(env, suite); + var spec3 = new jasmine.Spec(env, suite); + expect(spec1.id).toEqual(0); + expect(spec2.id).toEqual(1); + expect(spec3.id).toEqual(2); + }); + + }); + + it('getFullName returns suite & spec description', function () { + var spec = new jasmine.Spec(env, suite, 'spec 1'); + expect(spec.getFullName()).toEqual('suite 1 spec 1.') + }); + + describe('results', function () { + var spec, results; + beforeEach(function () { + spec = new jasmine.Spec(env, suite); + results = spec.results(); + expect(results.totalCount).toEqual(0); + spec.runs(function () { + this.expect(true).toEqual(true); + this.expect(true).toEqual(true); + }); + }); + + + it('results shows the total number of expectations for each spec after execution', function () { + expect(results.totalCount).toEqual(0); + spec.execute(); + expect(results.totalCount).toEqual(2); + }); + + it('results shows the number of passed expectations for each spec after execution', function () { + expect(results.passedCount).toEqual(0); + spec.execute(); + expect(results.passedCount).toEqual(2); + }); + + it('results shows the number of failed expectations for each spec after execution', function () { + spec.runs(function () { + this.expect(true).toEqual(false); + }); + expect(results.failedCount).toEqual(0); + spec.execute(); + expect(results.failedCount).toEqual(1); + }); + + describe('results.passed', function () { + it('is true if all spec expectations pass', function () { + spec.runs(function () { + this.expect(true).toEqual(true); + }); + spec.execute(); + expect(results.passed()).toEqual(true); + }); + + it('is false if one spec expectation fails', function () { + spec.runs(function () { + this.expect(true).toEqual(false); + }); + spec.execute(); + expect(results.passed()).toEqual(false); + }); + + it('a spec with no expectations will return true', function () { + var specWithoutExpectations = new jasmine.Spec(env, suite); + specWithoutExpectations.runs(function() { + + }); + specWithoutExpectations.execute(); + expect(results.passed()).toEqual(true); + }); + + it('an unexecuted spec will return true', function () { + expect(results.passed()).toEqual(true); + }); + }); + }); +}); \ No newline at end of file diff --git a/spec/suites/TrivialReporterSpec.js b/spec/suites/TrivialReporterSpec.js index 24b3a9b..750c33f 100644 --- a/spec/suites/TrivialReporterSpec.js +++ b/spec/suites/TrivialReporterSpec.js @@ -31,4 +31,5 @@ describe("TrivialReporter", function() { expect(divs.length).toEqual(2); expect(divs[1].innerHTML).toContain("suite 1"); }); + }); \ No newline at end of file diff --git a/src/Block.js b/src/Block.js index b9f8f86..75964a1 100644 --- a/src/Block.js +++ b/src/Block.js @@ -16,11 +16,7 @@ jasmine.Block.prototype.execute = function(onComplete) { try { this.func.apply(this.spec); } catch (e) { - this.fail(e); + this.spec.fail(e); } onComplete(); -}; - -jasmine.Block.prototype.fail = function(e) { - this.spec.results.addResult(new jasmine.ExpectationResult(false, jasmine.util.formatException(e), null)); }; \ No newline at end of file diff --git a/src/Env.js b/src/Env.js index e0247e0..d518520 100644 --- a/src/Env.js +++ b/src/Env.js @@ -30,6 +30,9 @@ jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout; jasmine.Env.prototype.setInterval = jasmine.setInterval; jasmine.Env.prototype.clearInterval = jasmine.clearInterval; +/** + * @returns an object containing jasmine version build info, if set. + */ jasmine.Env.prototype.version = function () { if (jasmine.version_) { return jasmine.version_; @@ -38,6 +41,20 @@ jasmine.Env.prototype.version = function () { } }; +/** + * @returns a sequential integer starting at 0 + */ +jasmine.Env.prototype.nextSpecId = function () { + return this.nextSpecId_++; +}; + +/** + * @returns a sequential integer starting at 0 + */ +jasmine.Env.prototype.nextSuiteId = function () { + return this.nextSuiteId_++; +}; + /** * Register a reporter to receive status updates from Jasmine. * @param {jasmine.Reporter} reporter An object which will receive status updates. @@ -98,7 +115,7 @@ jasmine.Env.prototype.it = function(description, func) { jasmine.Env.prototype.xit = function(desc, func) { return { - id: this.nextSpecId_++, + id: this.nextSpecId(), runs: function() { } }; diff --git a/src/JsApiReporter.js b/src/JsApiReporter.js index b5bcafc..9003cf9 100644 --- a/src/JsApiReporter.js +++ b/src/JsApiReporter.js @@ -5,8 +5,8 @@ jasmine.JsApiReporter = function() { this.started = false; this.finished = false; - this.suites = []; - this.results = {}; + this.suites_ = []; + this.results_ = {}; }; jasmine.JsApiReporter.prototype.reportRunnerStarting = function(runner) { @@ -14,10 +14,14 @@ jasmine.JsApiReporter.prototype.reportRunnerStarting = function(runner) { var suites = runner.suites(); for (var i = 0; i < suites.length; i++) { var suite = suites[i]; - this.suites.push(this.summarize_(suite)); + this.suites_.push(this.summarize_(suite)); } }; +jasmine.JsApiReporter.prototype.suites = function() { + return this.suites_; +}; + jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) { var isSuite = suiteOrSpec instanceof jasmine.Suite var summary = { @@ -35,6 +39,14 @@ jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) { return summary; }; +jasmine.JsApiReporter.prototype.results = function() { + return this.results_; +}; + +jasmine.JsApiReporter.prototype.resultsForSpec = function(specId) { + return this.results_[specId]; +}; + //noinspection JSUnusedLocalSymbols jasmine.JsApiReporter.prototype.reportRunnerResults = function(runner) { this.finished = true; @@ -46,9 +58,9 @@ jasmine.JsApiReporter.prototype.reportSuiteResults = function(suite) { //noinspection JSUnusedLocalSymbols jasmine.JsApiReporter.prototype.reportSpecResults = function(spec) { - this.results[spec.id] = { - messages: spec.results.getItems(), - result: spec.results.failedCount > 0 ? "failed" : "passed" + this.results_[spec.id] = { + messages: spec.results().getItems(), + result: spec.results().failedCount > 0 ? "failed" : "passed" }; }; diff --git a/src/Matchers.js b/src/Matchers.js index 6319433..6733d58 100644 --- a/src/Matchers.js +++ b/src/Matchers.js @@ -2,19 +2,24 @@ jasmine.Matchers = function(env, actual, results) { this.env = env; this.actual = actual; this.passing_message = 'Passed.'; - this.results = results || new jasmine.NestedResults(); + this.results_ = results || new jasmine.NestedResults(); }; jasmine.Matchers.pp = function(str) { return jasmine.util.htmlEscape(jasmine.pp(str)); }; +/** @deprecated */ jasmine.Matchers.prototype.getResults = function() { - return this.results; + return this.results_; +}; + +jasmine.Matchers.prototype.results = function() { + return this.results_; }; jasmine.Matchers.prototype.report = function(result, failing_message, details) { - this.results.addResult(new jasmine.ExpectationResult(result, result ? this.passing_message : failing_message, details)); + this.results_.addResult(new jasmine.ExpectationResult(result, result ? this.passing_message : failing_message, details)); return result; }; diff --git a/src/Queue.js b/src/Queue.js index 018021b..27d3737 100644 --- a/src/Queue.js +++ b/src/Queue.js @@ -66,11 +66,11 @@ jasmine.Queue.prototype.finish = function () { } }; -jasmine.Queue.prototype.getResults = function () { +jasmine.Queue.prototype.results = function () { var results = new jasmine.NestedResults(); for (var i = 0; i < this.blocks.length; i++) { - if (this.blocks[i].getResults) { - results.addResult(this.blocks[i].getResults()); + if (this.blocks[i].results) { + results.addResult(this.blocks[i].results()); } } return results; diff --git a/src/Runner.js b/src/Runner.js index 8dc28c1..5c53599 100644 --- a/src/Runner.js +++ b/src/Runner.js @@ -46,6 +46,11 @@ jasmine.Runner.prototype.suites = function() { return this.suites_; }; +jasmine.Runner.prototype.results = function() { + return this.queue.results(); +}; + +/** @deprecated */ jasmine.Runner.prototype.getResults = function() { - return this.queue.getResults(); + return this.queue.results(); }; \ No newline at end of file diff --git a/src/Spec.js b/src/Spec.js index ca84436..964f9cb 100644 --- a/src/Spec.js +++ b/src/Spec.js @@ -7,8 +7,14 @@ * @param {String} description */ jasmine.Spec = function(env, suite, description) { + if (!env) { + throw new Error('jasmine.Env() required'); + }; + if (!suite) { + throw new Error('jasmine.Suite() required'); + }; var spec = this; - spec.id = env.nextSpecId_++; + spec.id = env.nextSpecId ? env.nextSpecId() : null; spec.env = env; spec.suite = suite; spec.description = description; @@ -17,8 +23,8 @@ jasmine.Spec = function(env, suite, description) { spec.afterCallbacks = []; spec.spies_ = []; - spec.results = new jasmine.NestedResults(); - spec.results.description = description; + spec.results_ = new jasmine.NestedResults(); + spec.results_.description = description; spec.matchersClass = null; }; @@ -26,8 +32,18 @@ jasmine.Spec.prototype.getFullName = function() { return this.suite.getFullName() + ' ' + this.description + '.'; }; + +jasmine.Spec.prototype.results = function() { + return this.results_; +}; + +jasmine.Spec.prototype.log = function(message) { + return this.results_.log(message); +}; + +/** @deprecated */ jasmine.Spec.prototype.getResults = function() { - return this.results; + return this.results_; }; jasmine.Spec.prototype.runs = function (func) { @@ -52,11 +68,8 @@ jasmine.Spec.prototype.expects_that = function(actual) { return this.expect(actual); }; -/** - * @private - */ jasmine.Spec.prototype.expect = function(actual) { - return new (this.getMatchersClass_())(this.env, actual, this.results); + return new (this.getMatchersClass_())(this.env, actual, this.results_); }; jasmine.Spec.prototype.waits = function(timeout) { @@ -71,8 +84,8 @@ jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessag return this; }; -jasmine.Spec.prototype.failWithException = function (e) { - this.results.addResult(new jasmine.ExpectationResult(false, jasmine.util.formatException(e), null)); +jasmine.Spec.prototype.fail = function (e) { + this.results_.addResult(new jasmine.ExpectationResult(false, e ? jasmine.util.formatException(e) : null, null)); }; jasmine.Spec.prototype.getMatchersClass_ = function() { @@ -115,7 +128,7 @@ jasmine.Spec.prototype.after = function(doAfter, test) { jasmine.Spec.prototype.execute = function(onComplete) { var spec = this; if (!spec.env.specFilter(spec)) { - spec.results.skipped = true; + spec.results_.skipped = true; spec.finish(onComplete); return; } diff --git a/src/Suite.js b/src/Suite.js index d60ee81..fadcc1a 100644 --- a/src/Suite.js +++ b/src/Suite.js @@ -9,7 +9,7 @@ */ jasmine.Suite = function(env, description, specDefinitions, parentSuite) { var self = this; - self.id = env.nextSuiteId_++; + self.id = env.nextSuiteId ? env.nextSuiteId() : null; self.description = description; self.queue = new jasmine.Queue(env); self.parentSuite = parentSuite; @@ -45,8 +45,13 @@ jasmine.Suite.prototype.afterEach = function(afterEachFunction) { this.afterQueue.push(afterEachFunction); }; +/** @deprecated */ jasmine.Suite.prototype.getResults = function() { - return this.queue.getResults(); + return this.queue.results(); +}; + +jasmine.Suite.prototype.results = function() { + return this.queue.results(); }; jasmine.Suite.prototype.add = function(block) { diff --git a/src/WaitsForBlock.js b/src/WaitsForBlock.js index 9332773..927a38d 100644 --- a/src/WaitsForBlock.js +++ b/src/WaitsForBlock.js @@ -17,7 +17,7 @@ jasmine.WaitsForBlock.prototype.execute = function (onComplete) { try { latchFunctionResult = self.latchFunction.apply(self.spec); } catch (e) { - self.fail(e); + self.spec.fail(e); onComplete(); return; } @@ -26,7 +26,7 @@ jasmine.WaitsForBlock.prototype.execute = function (onComplete) { onComplete(); } else if (self.totalTimeSpentWaitingForLatch >= self.timeout) { var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen'); - self.fail({ + self.spec.fail({ name: 'timeout', message: message }); diff --git a/src/base.js b/src/base.js index 81f3f57..ce0afd3 100755 --- a/src/base.js +++ b/src/base.js @@ -323,7 +323,7 @@ jasmine.createSpyObj = function(baseName, methodNames) { }; jasmine.log = function(message) { - jasmine.getEnv().currentSpec.getResults().log(message); + jasmine.getEnv().currentSpec.log(message); }; /**