From 118324b4510c48bd1fc7286c5fc388da841d864a Mon Sep 17 00:00:00 2001 From: ragaskar Date: Fri, 6 May 2011 19:07:00 -0400 Subject: [PATCH] Don't show 'Jasmine waiting for...' console messages unless jasmine.VERBOSE is set to true --- spec/suites/WaitsForBlockSpec.js | 33 +++++++++++++++++++++++++++++++- src/WaitsBlock.js | 4 +++- src/WaitsForBlock.js | 6 ++++-- src/base.js | 8 +++++++- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/spec/suites/WaitsForBlockSpec.js b/spec/suites/WaitsForBlockSpec.js index 6927194..e180721 100644 --- a/spec/suites/WaitsForBlockSpec.js +++ b/spec/suites/WaitsForBlockSpec.js @@ -10,6 +10,37 @@ describe('WaitsForBlock', function () { onComplete = jasmine.createSpy("onComplete"); }); + describe("jasmine.VERBOSE", function() { + var jasmineVerboseOriginal; + beforeEach(function() { + jasmineVerboseOriginal = jasmine.VERBOSE; + spyOn(env.reporter, 'log'); + + }); + it('do not show information if jasmine.VERBOSE is set to false', function () { + jasmine.VERBOSE = false; + var latchFunction = function() { + return true; + }; + var block = new jasmine.WaitsForBlock(env, timeout, latchFunction, message, spec); + expect(env.reporter.log).not.toHaveBeenCalled(); + block.execute(onComplete); + expect(env.reporter.log).not.toHaveBeenCalled(); + jasmine.VERBOSE = jasmineVerboseOriginal; + }); + it('show information if jasmine.VERBOSE is set to true', function () { + jasmine.VERBOSE = true; + var latchFunction = function() { + return true; + }; + var block = new jasmine.WaitsForBlock(env, timeout, latchFunction, message, spec); + expect(env.reporter.log).not.toHaveBeenCalled(); + block.execute(onComplete); + expect(env.reporter.log).toHaveBeenCalled(); + jasmine.VERBOSE = jasmineVerboseOriginal; + }); + }); + it('onComplete should be called if the latchFunction returns true', function () { var latchFunction = function() { return true; @@ -84,4 +115,4 @@ describe('WaitsForBlock', function () { expect(onComplete).toHaveBeenCalled(); }); }); -}); \ No newline at end of file +}); diff --git a/src/WaitsBlock.js b/src/WaitsBlock.js index 151c051..4900805 100644 --- a/src/WaitsBlock.js +++ b/src/WaitsBlock.js @@ -6,7 +6,9 @@ jasmine.WaitsBlock = function(env, timeout, spec) { jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block); jasmine.WaitsBlock.prototype.execute = function (onComplete) { - this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...'); + if (jasmine.VERBOSE) { + this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...'); + } this.env.setTimeout(function () { onComplete(); }, this.timeout); diff --git a/src/WaitsForBlock.js b/src/WaitsForBlock.js index 793ca3e..9a72954 100644 --- a/src/WaitsForBlock.js +++ b/src/WaitsForBlock.js @@ -21,7 +21,9 @@ jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block); jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 10; jasmine.WaitsForBlock.prototype.execute = function(onComplete) { - this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen')); + if (jasmine.VERBOSE) { + this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen')); + } var latchFunctionResult; try { latchFunctionResult = this.latchFunction.apply(this.spec); @@ -49,4 +51,4 @@ jasmine.WaitsForBlock.prototype.execute = function(onComplete) { self.execute(onComplete); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT); } -}; \ No newline at end of file +}; diff --git a/src/base.js b/src/base.js index d0fafda..cd7e778 100755 --- a/src/base.js +++ b/src/base.js @@ -22,6 +22,12 @@ jasmine.unimplementedMethod_ = function() { */ jasmine.undefined = jasmine.___undefined___; +/** + * Show diagnostic messages in the console if set to true + * + */ +jasmine.VERBOSE = false; + /** * Default interval in milliseconds for event loop yields (e.g. to allow network activity or to refresh the screen with the HTML-based runner). Small values here may result in slow test running. Zero means no updates until all tests have completed. * @@ -599,4 +605,4 @@ jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() { if (!xhr) throw new Error("This browser does not support XMLHttpRequest."); return xhr; -} : XMLHttpRequest; \ No newline at end of file +} : XMLHttpRequest;