From 662b4b94f4492d09e244dcba162a8b1a880b656b Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Tue, 7 Jul 2009 23:06:18 -0700 Subject: [PATCH 01/11] jasmine.Spec.prototype.(expect|waits|waitFor) shouldn't be deprecated. --- src/Spec.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Spec.js b/src/Spec.js index aef5ac2..70c8469 100644 --- a/src/Spec.js +++ b/src/Spec.js @@ -56,7 +56,6 @@ jasmine.Spec.prototype.expects_that = function(actual) { /** * @private - * @deprecated */ jasmine.Spec.prototype.expect = function(actual) { return new jasmine.Matchers(this.env, actual, this.results); @@ -64,7 +63,6 @@ jasmine.Spec.prototype.expect = function(actual) { /** * @private - * @deprecated */ jasmine.Spec.prototype.waits = function(timeout) { this.currentTimeout = timeout; @@ -74,7 +72,6 @@ jasmine.Spec.prototype.waits = function(timeout) { /** * @private - * @deprecated */ jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, message) { this.currentTimeout = timeout; From 378d6bb4ff8e625636e19fa21aa16e131ee60e8a Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Tue, 7 Jul 2009 23:06:41 -0700 Subject: [PATCH 02/11] jasmine.Spec.prototype.(expect|waits|waitFor) shouldn't be deprecated. --- lib/jasmine.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/jasmine.js b/lib/jasmine.js index f1579fa..7ba8707 100644 --- a/lib/jasmine.js +++ b/lib/jasmine.js @@ -1658,7 +1658,6 @@ jasmine.Spec.prototype.expects_that = function(actual) { /** * @private - * @deprecated */ jasmine.Spec.prototype.expect = function(actual) { return new jasmine.Matchers(this.env, actual, this.results); @@ -1666,7 +1665,6 @@ jasmine.Spec.prototype.expect = function(actual) { /** * @private - * @deprecated */ jasmine.Spec.prototype.waits = function(timeout) { this.currentTimeout = timeout; @@ -1676,7 +1674,6 @@ jasmine.Spec.prototype.waits = function(timeout) { /** * @private - * @deprecated */ jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, message) { this.currentTimeout = timeout; From ed00c13b15b2d8af792225ed8b17f77402e3ba25 Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Tue, 7 Jul 2009 23:57:03 -0700 Subject: [PATCH 03/11] Provide a way to add more matchers in a spec or suite without affecting later specs or suites. --- lib/jasmine.js | 19 ++++++++++++++++++- spec/suites/SpecRunningTest.js | 32 ++++++++++++++++++++++++++++++++ src/Spec.js | 19 ++++++++++++++++++- 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/lib/jasmine.js b/lib/jasmine.js index 7ba8707..39d74ab 100644 --- a/lib/jasmine.js +++ b/lib/jasmine.js @@ -1623,6 +1623,7 @@ jasmine.Spec = function(env, suite, description) { this.results = new jasmine.NestedResults(); this.results.description = description; this.runs = this.addToQueue; + this.matchersClass = null; }; jasmine.Spec.prototype.getFullName = function() { @@ -1660,7 +1661,7 @@ jasmine.Spec.prototype.expects_that = function(actual) { * @private */ jasmine.Spec.prototype.expect = function(actual) { - return new jasmine.Matchers(this.env, actual, this.results); + return new (this.getMatchersClass_())(this.env, actual, this.results); }; /** @@ -1682,6 +1683,22 @@ jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, message) { return this; }; +jasmine.Spec.prototype.getMatchersClass_ = function(matcherPrototype) { + return this.matchersClass || jasmine.Matchers; +}; + +jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { + var parent = this.getMatchersClass_(); + var newMatchersClass = function() { + parent.apply(this, arguments); + }; + jasmine.util.inherit(newMatchersClass, parent); + for (var method in matchersPrototype) { + newMatchersClass.prototype[method] = matchersPrototype[method]; + } + this.matchersClass = newMatchersClass; +}; + jasmine.Spec.prototype.resetTimeout = function() { this.currentTimeout = 0; this.currentLatchFunction = undefined; diff --git a/spec/suites/SpecRunningTest.js b/spec/suites/SpecRunningTest.js index d74f5f3..ca84e1d 100644 --- a/spec/suites/SpecRunningTest.js +++ b/spec/suites/SpecRunningTest.js @@ -728,4 +728,36 @@ describe("jasmine spec running", function () { expect(exceptionMessage).toEqual('explodes function should not have been called'); }); + + it("should be easy to add more matchers local to a spec, suite, etc.", function() { + var spec1, spec2, spec1Matcher, spec2Matcher; + + var suite = env.describe('some suite', function() { + env.beforeEach(function() { + this.addMatchers({ matcherForSuite: function(expected) { + return "matcherForSuite: actual: " + this.actual + "; expected: " + expected; + } }); + }); + + spec1 = env.it('spec with an expectation').runs(function () { + this.addMatchers( { matcherForSpec: function(expected) { + return "matcherForSpec: actual: " + this.actual + "; expected: " + expected; + } }); + spec1Matcher = this.expect("xxx"); + }); + + spec2 = env.it('spec with failing expectation').runs(function () { + spec2Matcher = this.expect("yyy"); + }); + }); + + suite.execute(); + + expect(spec1Matcher.matcherForSuite("expected")).toEqual("matcherForSuite: actual: xxx; expected: expected"); + expect(spec1Matcher.matcherForSpec("expected")).toEqual("matcherForSpec: actual: xxx; expected: expected"); + + expect(spec2Matcher.matcherForSuite("expected")).toEqual("matcherForSuite: actual: yyy; expected: expected"); + expect(spec2Matcher.matcherForSpec).toBe(undefined); + }); + }); diff --git a/src/Spec.js b/src/Spec.js index 70c8469..d566660 100644 --- a/src/Spec.js +++ b/src/Spec.js @@ -21,6 +21,7 @@ jasmine.Spec = function(env, suite, description) { this.results = new jasmine.NestedResults(); this.results.description = description; this.runs = this.addToQueue; + this.matchersClass = null; }; jasmine.Spec.prototype.getFullName = function() { @@ -58,7 +59,7 @@ jasmine.Spec.prototype.expects_that = function(actual) { * @private */ jasmine.Spec.prototype.expect = function(actual) { - return new jasmine.Matchers(this.env, actual, this.results); + return new (this.getMatchersClass_())(this.env, actual, this.results); }; /** @@ -80,6 +81,22 @@ jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, message) { return this; }; +jasmine.Spec.prototype.getMatchersClass_ = function(matcherPrototype) { + return this.matchersClass || jasmine.Matchers; +}; + +jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { + var parent = this.getMatchersClass_(); + var newMatchersClass = function() { + parent.apply(this, arguments); + }; + jasmine.util.inherit(newMatchersClass, parent); + for (var method in matchersPrototype) { + newMatchersClass.prototype[method] = matchersPrototype[method]; + } + this.matchersClass = newMatchersClass; +}; + jasmine.Spec.prototype.resetTimeout = function() { this.currentTimeout = 0; this.currentLatchFunction = undefined; From 6b32586e1f8b8a382c6892e2204d16be43bb06b3 Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Tue, 7 Jul 2009 23:59:38 -0700 Subject: [PATCH 04/11] Remove unused parameter. --- lib/jasmine.js | 2 +- src/Spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/jasmine.js b/lib/jasmine.js index 39d74ab..79be747 100644 --- a/lib/jasmine.js +++ b/lib/jasmine.js @@ -1683,7 +1683,7 @@ jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, message) { return this; }; -jasmine.Spec.prototype.getMatchersClass_ = function(matcherPrototype) { +jasmine.Spec.prototype.getMatchersClass_ = function() { return this.matchersClass || jasmine.Matchers; }; diff --git a/src/Spec.js b/src/Spec.js index d566660..3138da0 100644 --- a/src/Spec.js +++ b/src/Spec.js @@ -81,7 +81,7 @@ jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, message) { return this; }; -jasmine.Spec.prototype.getMatchersClass_ = function(matcherPrototype) { +jasmine.Spec.prototype.getMatchersClass_ = function() { return this.matchersClass || jasmine.Matchers; }; From 687b94374ce7822a22ec603a1ddb08a0574975b7 Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Wed, 8 Jul 2009 00:07:29 -0700 Subject: [PATCH 05/11] Clarification re spy properties. --- README.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.markdown b/README.markdown index d469e77..8ddf9ae 100644 --- a/README.markdown +++ b/README.markdown @@ -347,6 +347,8 @@ There are spy-specfic matchers that are very handy. `wasNotCalledWith(arguments)` returns true if the object is a spy and was not called with the passed arguments +Spies can be trained to respond in a variety of ways when invoked: + `andCallThrough()`: spies on AND calls the original function spied on `andReturn(arguments)`: returns passed arguments when spy is called @@ -355,6 +357,8 @@ There are spy-specfic matchers that are very handy. `andCallFake(function)`: calls passed function when spy is called +Spies have some useful properties: + `callCount`: returns number of times spy was called `mostRecentCall.args`: returns argument array from last call to spy. From 521f839753d8651f1015a2d3a36834b0aaa9238b Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Wed, 8 Jul 2009 11:04:35 -0700 Subject: [PATCH 06/11] Remove cruft from elsewhere. --- lib/TrivialReporter.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/TrivialReporter.js b/lib/TrivialReporter.js index a7bd114..5d10f5d 100644 --- a/lib/TrivialReporter.js +++ b/lib/TrivialReporter.js @@ -18,11 +18,7 @@ jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarA if (attr == 'className') { el.setAttribute('class', attrs[attr]); } else { - if (attr.indexOf('x-') == 0) { - el.setAttribute(attr, attrs[attr]); - } else { - el[attr] = attrs[attr]; - } + el[attr] = attrs[attr]; } } From a6aa9c652b299e14ac569969c64eab8f9e5a66a9 Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Wed, 8 Jul 2009 17:55:25 -0700 Subject: [PATCH 07/11] Allow for registration of multiple Reporter with Jasmine. --- lib/jasmine.js | 44 +++++++++++++++++++++++++++++--- spec/runner.html | 5 ++-- spec/suites/MultiReporterTest.js | 13 ++++++++++ src/Env.js | 14 ++++++++++ src/MultiReporter.js | 24 +++++++++++++++++ src/Spec.js | 4 +-- src/Suite.js | 2 +- 7 files changed, 98 insertions(+), 8 deletions(-) create mode 100644 spec/suites/MultiReporterTest.js create mode 100644 src/MultiReporter.js diff --git a/lib/jasmine.js b/lib/jasmine.js index 79be747..899340f 100644 --- a/lib/jasmine.js +++ b/lib/jasmine.js @@ -567,12 +567,18 @@ jasmine.util.argsToArray = function(args) { return arrayOfArgs; }; +/** + * Environment for Jasmine + * @ + */ jasmine.Env = function() { this.currentSpec = null; this.currentSuite = null; this.currentRunner = new jasmine.Runner(this); this.currentlyRunningTests = false; + this.reporter = new jasmine.MultiReporter(); + this.updateInterval = 0; this.lastUpdate = 0; this.specFilter = function() { @@ -589,6 +595,14 @@ jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout; jasmine.Env.prototype.setInterval = jasmine.setInterval; jasmine.Env.prototype.clearInterval = jasmine.clearInterval; +/** + * Register a reporter to receive status updates from Jasmine. + * @param {Object} reporter An object which will receive status updates. + */ +jasmine.Env.prototype.addReporter = function(reporter) { + this.reporter.addReporter(reporter); +}; + jasmine.Env.prototype.execute = function() { this.currentRunner.execute(); }; @@ -1260,6 +1274,30 @@ window.clearInterval = function(timeoutKey) { return jasmine.Clock.installed.clearInterval.apply(this, arguments); }; +/** + * @constructor + */ +jasmine.MultiReporter = function() { + this.subReporters_ = []; +}; + +jasmine.MultiReporter.prototype.addReporter = function(reporter) { + this.subReporters_.push(reporter); +}; + +(function() { + var functionNames = ["reportRunnerResults", "reportSuiteResults", "reportSpecResults", "log"]; + for (var i = 0; i < functionNames.length; i++) { + var functionName = functionNames[i]; + jasmine.MultiReporter.prototype[functionName] = (function(functionName) { + return function() { + for (var j = 0; j < this.subReporters_.length; j++) { + this.subReporters_[j][functionName].apply(this.subReporters_[j], arguments); + } + }; + })(functionName); + } +})(); /** * Holds results for a set of Jasmine spec. Allows for the results array to hold another jasmine.NestedResults * @@ -1602,8 +1640,8 @@ jasmine.Runner.prototype.getResults = function() { }; /** * Internal representation of a Jasmine specification, or test. - * @private - * @constructs + * + * @constructor * @param {jasmine.Env} env * @param {jasmine.Suite} suite * @param {String} description @@ -1806,7 +1844,7 @@ jasmine.Spec.prototype.removeAllSpies = function() { }; /** - * For storing & executing a Jasmine suite. + * Internal representation of a Jasmine suite. * * @constructor * @param {jasmine.Env} env diff --git a/spec/runner.html b/spec/runner.html index fe4bbd8..e09e0ad 100644 --- a/spec/runner.html +++ b/spec/runner.html @@ -11,6 +11,7 @@ + @@ -28,6 +29,7 @@ jasmine.include('suites/ExceptionsTest.js', true); jasmine.include('suites/JsonReporterTest.js', true); jasmine.include('suites/MatchersTest.js', true); + jasmine.include('suites/MultiReporterTest.js', true); jasmine.include('suites/NestedResultsTest.js', true); jasmine.include('suites/PrettyPrintTest.js', true); jasmine.include('suites/ReporterTest.js', true); @@ -66,9 +68,8 @@ var jasmineEnv = jasmine.getEnv(); - jasmineEnv.reporter = new jasmine.TrivialReporter(); + jasmineEnv.addReporter(new jasmine.TrivialReporter()); jasmineEnv.execute(); - console.log('env', jasmineEnv); diff --git a/spec/suites/MultiReporterTest.js b/spec/suites/MultiReporterTest.js new file mode 100644 index 0000000..cb4174e --- /dev/null +++ b/spec/suites/MultiReporterTest.js @@ -0,0 +1,13 @@ +describe("MultiReporter", function() { + it("should delegate to any and all subreporters", function() { + var multiReporter = new jasmine.MultiReporter(); + var fakeReporter1 = jasmine.createSpyObj("fakeReporter1", ["reportSpecResults"]); + var fakeReporter2 = jasmine.createSpyObj("fakeReporter2", ["reportSpecResults"]); + multiReporter.addReporter(fakeReporter1); + multiReporter.addReporter(fakeReporter2); + + multiReporter.reportSpecResults('blah', 'foo'); + expect(fakeReporter1.reportSpecResults).wasCalledWith('blah', 'foo'); + expect(fakeReporter2.reportSpecResults).wasCalledWith('blah', 'foo'); + }); +}); \ No newline at end of file diff --git a/src/Env.js b/src/Env.js index 0708a8c..77d2742 100644 --- a/src/Env.js +++ b/src/Env.js @@ -1,9 +1,15 @@ +/** + * Environment for Jasmine + * @ + */ jasmine.Env = function() { this.currentSpec = null; this.currentSuite = null; this.currentRunner = new jasmine.Runner(this); this.currentlyRunningTests = false; + this.reporter = new jasmine.MultiReporter(); + this.updateInterval = 0; this.lastUpdate = 0; this.specFilter = function() { @@ -20,6 +26,14 @@ jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout; jasmine.Env.prototype.setInterval = jasmine.setInterval; jasmine.Env.prototype.clearInterval = jasmine.clearInterval; +/** + * Register a reporter to receive status updates from Jasmine. + * @param {Object} reporter An object which will receive status updates. + */ +jasmine.Env.prototype.addReporter = function(reporter) { + this.reporter.addReporter(reporter); +}; + jasmine.Env.prototype.execute = function() { this.currentRunner.execute(); }; diff --git a/src/MultiReporter.js b/src/MultiReporter.js new file mode 100644 index 0000000..0f49401 --- /dev/null +++ b/src/MultiReporter.js @@ -0,0 +1,24 @@ +/** + * @constructor + */ +jasmine.MultiReporter = function() { + this.subReporters_ = []; +}; + +jasmine.MultiReporter.prototype.addReporter = function(reporter) { + this.subReporters_.push(reporter); +}; + +(function() { + var functionNames = ["reportRunnerResults", "reportSuiteResults", "reportSpecResults", "log"]; + for (var i = 0; i < functionNames.length; i++) { + var functionName = functionNames[i]; + jasmine.MultiReporter.prototype[functionName] = (function(functionName) { + return function() { + for (var j = 0; j < this.subReporters_.length; j++) { + this.subReporters_[j][functionName].apply(this.subReporters_[j], arguments); + } + }; + })(functionName); + } +})(); diff --git a/src/Spec.js b/src/Spec.js index 3138da0..d4d0361 100644 --- a/src/Spec.js +++ b/src/Spec.js @@ -1,7 +1,7 @@ /** * Internal representation of a Jasmine specification, or test. - * @private - * @constructs + * + * @constructor * @param {jasmine.Env} env * @param {jasmine.Suite} suite * @param {String} description diff --git a/src/Suite.js b/src/Suite.js index aa206d4..fe43110 100644 --- a/src/Suite.js +++ b/src/Suite.js @@ -1,5 +1,5 @@ /** - * For storing & executing a Jasmine suite. + * Internal representation of a Jasmine suite. * * @constructor * @param {jasmine.Env} env From 0c24c2df2ec5b60ca1a443f6b78dfb4fb6d88b3d Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Wed, 8 Jul 2009 18:01:05 -0700 Subject: [PATCH 08/11] jasmine.Env should always have a reporter now, no need to check. --- lib/jasmine.js | 16 ++++------------ spec/suites/SpyTest.js | 2 +- src/QueuedFunction.js | 4 +--- src/Runner.js | 4 +--- src/Spec.js | 4 +--- src/Suite.js | 4 +--- 6 files changed, 9 insertions(+), 25 deletions(-) diff --git a/lib/jasmine.js b/lib/jasmine.js index 899340f..bb44280 100644 --- a/lib/jasmine.js +++ b/lib/jasmine.js @@ -1519,9 +1519,7 @@ jasmine.QueuedFunction.prototype.next = function() { }; jasmine.QueuedFunction.prototype.safeExecute = function() { - if (this.env.reporter) { - this.env.reporter.log('>> Jasmine Running ' + this.spec.suite.description + ' ' + this.spec.description + '...'); - } + this.env.reporter.log('>> Jasmine Running ' + this.spec.suite.description + ' ' + this.spec.description + '...'); try { this.func.apply(this.spec); @@ -1626,9 +1624,7 @@ jasmine.Runner = function(env) { jasmine.util.inherit(jasmine.Runner, jasmine.ActionCollection); jasmine.Runner.prototype.finishCallback = function() { - if (this.env.reporter) { - this.env.reporter.reportRunnerResults(this); - } + this.env.reporter.reportRunnerResults(this); }; jasmine.Runner.prototype.getResults = function() { @@ -1743,9 +1739,7 @@ jasmine.Spec.prototype.resetTimeout = function() { }; jasmine.Spec.prototype.finishCallback = function() { - if (this.env.reporter) { - this.env.reporter.reportSpecResults(this); - } + this.env.reporter.reportSpecResults(this); }; jasmine.Spec.prototype.finish = function() { @@ -1873,9 +1867,7 @@ jasmine.Suite.prototype.getFullName = function() { }; jasmine.Suite.prototype.finishCallback = function() { - if (this.env.reporter) { - this.env.reporter.reportSuiteResults(this); - } + this.env.reporter.reportSuiteResults(this); }; jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) { diff --git a/spec/suites/SpyTest.js b/spec/suites/SpyTest.js index 0e8347b..1e782fb 100644 --- a/spec/suites/SpyTest.js +++ b/spec/suites/SpyTest.js @@ -143,7 +143,7 @@ describe('Spies', function () { }); it('calls removeAllSpies during spec finish', function() { - var test = new jasmine.Spec({}, {}, 'sample test'); + var test = new jasmine.Spec(new jasmine.Env(), {}, 'sample test'); this.spyOn(test, 'removeAllSpies'); diff --git a/src/QueuedFunction.js b/src/QueuedFunction.js index f2fc777..e4845c3 100644 --- a/src/QueuedFunction.js +++ b/src/QueuedFunction.js @@ -24,9 +24,7 @@ jasmine.QueuedFunction.prototype.next = function() { }; jasmine.QueuedFunction.prototype.safeExecute = function() { - if (this.env.reporter) { - this.env.reporter.log('>> Jasmine Running ' + this.spec.suite.description + ' ' + this.spec.description + '...'); - } + this.env.reporter.log('>> Jasmine Running ' + this.spec.suite.description + ' ' + this.spec.description + '...'); try { this.func.apply(this.spec); diff --git a/src/Runner.js b/src/Runner.js index 22a1996..2dfc138 100644 --- a/src/Runner.js +++ b/src/Runner.js @@ -12,9 +12,7 @@ jasmine.Runner = function(env) { jasmine.util.inherit(jasmine.Runner, jasmine.ActionCollection); jasmine.Runner.prototype.finishCallback = function() { - if (this.env.reporter) { - this.env.reporter.reportRunnerResults(this); - } + this.env.reporter.reportRunnerResults(this); }; jasmine.Runner.prototype.getResults = function() { diff --git a/src/Spec.js b/src/Spec.js index d4d0361..d754382 100644 --- a/src/Spec.js +++ b/src/Spec.js @@ -103,9 +103,7 @@ jasmine.Spec.prototype.resetTimeout = function() { }; jasmine.Spec.prototype.finishCallback = function() { - if (this.env.reporter) { - this.env.reporter.reportSpecResults(this); - } + this.env.reporter.reportSpecResults(this); }; jasmine.Spec.prototype.finish = function() { diff --git a/src/Suite.js b/src/Suite.js index fe43110..60ac46c 100644 --- a/src/Suite.js +++ b/src/Suite.js @@ -28,9 +28,7 @@ jasmine.Suite.prototype.getFullName = function() { }; jasmine.Suite.prototype.finishCallback = function() { - if (this.env.reporter) { - this.env.reporter.reportSuiteResults(this); - } + this.env.reporter.reportSuiteResults(this); }; jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) { From e1408a9f5858a2fc249315fa713db2850aec79a2 Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Wed, 8 Jul 2009 18:18:17 -0700 Subject: [PATCH 09/11] Add jasmine.Reporter no-op base class for reporters. --- Rakefile | 2 +- lib/jasmine.js | 29 +++++++++++++++++++++++++++-- spec/runner.html | 3 ++- spec/suites/EnvTest.js | 21 +++++++++++++++++++++ spec/suites/MultiReporterTest.js | 2 +- src/Env.js | 5 +++-- src/MultiReporter.js | 1 + src/Reporter.js | 23 +++++++++++++++++++++++ 8 files changed, 79 insertions(+), 7 deletions(-) create mode 100644 spec/suites/EnvTest.js create mode 100644 src/Reporter.js diff --git a/Rakefile b/Rakefile index bcadfe1..64d7cdb 100644 --- a/Rakefile +++ b/Rakefile @@ -2,7 +2,7 @@ desc 'Builds lib/jasmine from source' task :build do # these files must be better - sources = ["src/base.js", "src/util.js", "src/Env.js"] + sources = ["src/base.js", "src/util.js", "src/Env.js", "src/ActionCollection.js", "src/Reporter.js"] sources += Dir.glob('src/*.js').reject{|f| sources.include?(f)} diff --git a/lib/jasmine.js b/lib/jasmine.js index bb44280..41dbad1 100644 --- a/lib/jasmine.js +++ b/lib/jasmine.js @@ -569,7 +569,8 @@ jasmine.util.argsToArray = function(args) { /** * Environment for Jasmine - * @ + * + * @constructor */ jasmine.Env = function() { this.currentSpec = null; @@ -597,7 +598,7 @@ jasmine.Env.prototype.clearInterval = jasmine.clearInterval; /** * Register a reporter to receive status updates from Jasmine. - * @param {Object} reporter An object which will receive status updates. + * @param {jasmine.Reporter} reporter An object which will receive status updates. */ jasmine.Env.prototype.addReporter = function(reporter) { this.reporter.addReporter(reporter); @@ -844,6 +845,29 @@ jasmine.ActionCollection.prototype.waitForDone = function(action) { } }, 150); }; +/** No-op base class for Jasmine reporters. + * + * @constructor + */ +jasmine.Reporter = function() { +}; + +//noinspection JSUnusedLocalSymbols +jasmine.Reporter.prototype.reportRunnerResults = function(runner) { +}; + +//noinspection JSUnusedLocalSymbols +jasmine.Reporter.prototype.reportSuiteResults = function(suite) { +}; + +//noinspection JSUnusedLocalSymbols +jasmine.Reporter.prototype.reportSpecResults = function(spec) { +}; + +//noinspection JSUnusedLocalSymbols +jasmine.Reporter.prototype.log = function (str) { +}; + jasmine.Matchers = function(env, actual, results) { this.env = env; this.actual = actual; @@ -1280,6 +1304,7 @@ window.clearInterval = function(timeoutKey) { jasmine.MultiReporter = function() { this.subReporters_ = []; }; +jasmine.util.inherit(jasmine.MultiReporter, jasmine.Reporter); jasmine.MultiReporter.prototype.addReporter = function(reporter) { this.subReporters_.push(reporter); diff --git a/spec/runner.html b/spec/runner.html index e09e0ad..41c87bd 100644 --- a/spec/runner.html +++ b/spec/runner.html @@ -10,6 +10,7 @@ + @@ -22,11 +23,11 @@ -