From a9eaa66da59755c865847ba4aed2a92f76ee8aaa Mon Sep 17 00:00:00 2001 From: "Davis W. Frank" Date: Sun, 9 Dec 2012 09:29:05 -0800 Subject: [PATCH] removing the exception formatter from the util namespace --- lib/jasmine-core/jasmine.js | 16 ++++++++++++++-- pages | 1 + spec/core/ExceptionFormatterSpec.js | 26 ++++++++++++++++++++++++++ spec/core/ExceptionsSpec.js | 26 -------------------------- spec/runner.html | 1 + src/core/Env.js | 2 +- src/core/ExceptionFormatter.js | 12 ++++++++++++ tasks/jasmine_dev/sources.rb | 1 + 8 files changed, 56 insertions(+), 29 deletions(-) create mode 160000 pages create mode 100644 spec/core/ExceptionFormatterSpec.js create mode 100644 src/core/ExceptionFormatter.js diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 8ad75ad9..73a7031a 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -439,7 +439,19 @@ jasmine.util.argsToArray = function(args) { var arrayOfArgs = []; for (var i = 0; i < args.length; i++) arrayOfArgs.push(args[i]); return arrayOfArgs; -};//TODO: expectation result may make more sense as a presentation of an expectation. +};jasmine.exceptionMessageFor = function(e) { + var message = e.name + + ': ' + + e.message + + ' in ' + + (e.fileName || e.sourceURL || '') + + ' (line ' + + (e.line || e.lineNumber || '') + + ')'; + + return message; +}; +//TODO: expectation result may make more sense as a presentation of an expectation. jasmine.buildExpectationResult = function(params) { return { type: 'expect', @@ -527,7 +539,7 @@ jasmine.buildExpectationResult = function(params) { } }; - var exceptionFormatter = jasmine.util.formatException; + var exceptionFormatter = jasmine.exceptionMessageFor; var specConstructor = jasmine.Spec; diff --git a/pages b/pages new file mode 160000 index 00000000..39dcf87b --- /dev/null +++ b/pages @@ -0,0 +1 @@ +Subproject commit 39dcf87b563e7cb0435208af562cc8ea033a47ff diff --git a/spec/core/ExceptionFormatterSpec.js b/spec/core/ExceptionFormatterSpec.js new file mode 100644 index 00000000..c3052c8c --- /dev/null +++ b/spec/core/ExceptionFormatterSpec.js @@ -0,0 +1,26 @@ +describe("ExceptionFormatter", function() { + + it('formats Firefox exception messages', function() { + var sampleFirefoxException = { + fileName: 'foo.js', + line: '1978', + message: 'you got your foo in my bar', + name: 'A Classic Mistake' + }, + message = jasmine.exceptionMessageFor(sampleFirefoxException); + + expect(message).toEqual('A Classic Mistake: you got your foo in my bar in foo.js (line 1978)'); + }); + + it('formats Webkit exception messages', function() { + var sampleWebkitException = { + sourceURL: 'foo.js', + lineNumber: '1978', + message: 'you got your foo in my bar', + name: 'A Classic Mistake' + }, + message = jasmine.exceptionMessageFor(sampleWebkitException); + + expect(message).toEqual('A Classic Mistake: you got your foo in my bar in foo.js (line 1978)'); + }); +}); \ No newline at end of file diff --git a/spec/core/ExceptionsSpec.js b/spec/core/ExceptionsSpec.js index d7dda80a..e06b1275 100644 --- a/spec/core/ExceptionsSpec.js +++ b/spec/core/ExceptionsSpec.js @@ -6,32 +6,6 @@ describe('Exceptions:', function() { env.updateInterval = 0; }); - it('jasmine.formatException formats Firefox exception messages as expected', function() { - var sampleFirefoxException = { - fileName: 'foo.js', - line: '1978', - message: 'you got your foo in my bar', - name: 'A Classic Mistake' - }; - - var expected = 'A Classic Mistake: you got your foo in my bar in foo.js (line 1978)'; - - expect(jasmine.util.formatException(sampleFirefoxException)).toEqual(expected); - }); - - it('jasmine.formatException formats Webkit exception messages as expected', function() { - var sampleWebkitException = { - sourceURL: 'foo.js', - lineNumber: '1978', - message: 'you got your foo in my bar', - name: 'A Classic Mistake' - }; - - var expected = 'A Classic Mistake: you got your foo in my bar in foo.js (line 1978)'; - - expect(jasmine.util.formatException(sampleWebkitException)).toEqual(expected); - }); - describe('with break on exception', function() { it('should not catch the exception', function() { env.catchExceptions(false); diff --git a/spec/runner.html b/spec/runner.html index b462dac5..0db56a4a 100644 --- a/spec/runner.html +++ b/spec/runner.html @@ -30,6 +30,7 @@ + diff --git a/src/core/Env.js b/src/core/Env.js index 3e3a05da..20ee75a1 100644 --- a/src/core/Env.js +++ b/src/core/Env.js @@ -74,7 +74,7 @@ } }; - var exceptionFormatter = jasmine.util.formatException; + var exceptionFormatter = jasmine.exceptionMessageFor; var specConstructor = jasmine.Spec; diff --git a/src/core/ExceptionFormatter.js b/src/core/ExceptionFormatter.js new file mode 100644 index 00000000..7cb6032c --- /dev/null +++ b/src/core/ExceptionFormatter.js @@ -0,0 +1,12 @@ +jasmine.exceptionMessageFor = function(e) { + var message = e.name + + ': ' + + e.message + + ' in ' + + (e.fileName || e.sourceURL || '') + + ' (line ' + + (e.line || e.lineNumber || '') + + ')'; + + return message; +}; diff --git a/tasks/jasmine_dev/sources.rb b/tasks/jasmine_dev/sources.rb index caf0cb1a..87aee274 100644 --- a/tasks/jasmine_dev/sources.rb +++ b/tasks/jasmine_dev/sources.rb @@ -3,6 +3,7 @@ class JasmineDev < Thor :core => [ "base.js", "util.js", + "ExceptionFormatter.js", "ExpectationResult.js", "Env.js", "Reporter.js",