Permalink
Browse files

removing the exception formatter from the util namespace

  • Loading branch information...
1 parent 30bf565 commit a9eaa66da59755c865847ba4aed2a92f76ee8aaa Davis W. Frank committed Dec 9, 2012
@@ -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;
1 pages
Submodule pages added at 39dcf8
@@ -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)');
+ });
+});
@@ -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);
View
@@ -30,6 +30,7 @@
<script type="text/javascript" src=".././spec/core/CustomMatchersSpec.js"></script>
<script type="text/javascript" src=".././spec/core/EnvSpec.js"></script>
<script type="text/javascript" src=".././spec/core/ExceptionsSpec.js"></script>
+ <script type="text/javascript" src=".././spec/core/ExceptionFormatterSpec.js"></script>
<script type="text/javascript" src=".././spec/core/ExpectationResultSpec.js"></script>
<script type="text/javascript" src=".././spec/core/JsApiReporterSpec.js"></script>
<script type="text/javascript" src=".././spec/core/MatchersSpec.js"></script>
View
@@ -74,7 +74,7 @@
}
};
- var exceptionFormatter = jasmine.util.formatException;
+ var exceptionFormatter = jasmine.exceptionMessageFor;
var specConstructor = jasmine.Spec;
@@ -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;
+};
@@ -3,6 +3,7 @@ class JasmineDev < Thor
:core => [
"base.js",
"util.js",
+ "ExceptionFormatter.js",
"ExpectationResult.js",
"Env.js",
"Reporter.js",

1 comment on commit a9eaa66

Contributor

ragaskar commented on a9eaa66 Dec 10, 2012

thumbs up, except I think naming-pattern-wise we should name the file after the method or class (I know we haven't been doing this, but it helps with discoverability).

Please sign in to comment.