diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 2f48e945..eea53a21 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -5106,15 +5106,32 @@ getJasmineRequireObj().toHaveBeenCalledWith = function(j$) { } if (!actual.calls.any()) { - result.message = function() { return 'Expected spy ' + actual.and.identity + ' to have been called with ' + j$.pp(expectedArgs) + ' but it was never called.'; }; + result.message = function() { + return 'Expected spy ' + actual.and.identity + ' to have been called with:\n' + + ' ' + j$.pp(expectedArgs) + + '\nbut it was never called.'; + }; return result; } if (util.contains(actual.calls.allArgs(), expectedArgs, customEqualityTesters)) { result.pass = true; - result.message = function() { return 'Expected spy ' + actual.and.identity + ' not to have been called with ' + j$.pp(expectedArgs) + ' but it was.'; }; + result.message = function() { + return 'Expected spy ' + actual.and.identity + ' not to have been called with:\n' + + ' ' + j$.pp(expectedArgs) + + '\nbut it was.'; + }; } else { - result.message = function() { return 'Expected spy ' + actual.and.identity + ' to have been called with ' + j$.pp(expectedArgs) + ' but actual calls were ' + j$.pp(actual.calls.allArgs()).replace(/^\[ | \]$/g, '') + '.'; }; + result.message = function() { + var prettyPrintedCalls = actual.calls.allArgs().map(function(argsForCall) { + return ' ' + j$.pp(argsForCall); + }); + + return 'Expected spy ' + actual.and.identity + ' to have been called with:\n' + + ' ' + j$.pp(expectedArgs) + '\n' + '' + + 'but actual calls were:\n' + + prettyPrintedCalls.join(',\n') + '.'; + }; } return result; diff --git a/spec/core/matchers/toHaveBeenCalledWithSpec.js b/spec/core/matchers/toHaveBeenCalledWithSpec.js index 110e3dc2..534eca46 100644 --- a/spec/core/matchers/toHaveBeenCalledWithSpec.js +++ b/spec/core/matchers/toHaveBeenCalledWithSpec.js @@ -12,7 +12,7 @@ describe("toHaveBeenCalledWith", function() { result = matcher.compare(calledSpy, 'a', 'b'); expect(result.pass).toBe(true); - expect(result.message()).toEqual("Expected spy called-spy not to have been called with [ 'a', 'b' ] but it was."); + expect(result.message()).toEqual("Expected spy called-spy not to have been called with:\n [ 'a', 'b' ]\nbut it was."); }); it("passes through the custom equality testers", function() { @@ -39,7 +39,7 @@ describe("toHaveBeenCalledWith", function() { result = matcher.compare(uncalledSpy); expect(result.pass).toBe(false); - expect(result.message()).toEqual("Expected spy uncalled spy to have been called with [ ] but it was never called."); + expect(result.message()).toEqual("Expected spy uncalled spy to have been called with:\n [ ]\nbut it was never called."); }); it("fails when the actual was called with different parameters", function() { @@ -55,7 +55,7 @@ describe("toHaveBeenCalledWith", function() { result = matcher.compare(calledSpy, 'a', 'b'); expect(result.pass).toBe(false); - expect(result.message()).toEqual("Expected spy called spy to have been called with [ 'a', 'b' ] but actual calls were [ 'a' ], [ 'c', 'd' ]."); + expect(result.message()).toEqual("Expected spy called spy to have been called with:\n [ 'a', 'b' ]\nbut actual calls were:\n [ 'a' ],\n [ 'c', 'd' ]."); }); it("throws an exception when the actual is not a spy", function() { diff --git a/src/core/matchers/toHaveBeenCalledWith.js b/src/core/matchers/toHaveBeenCalledWith.js index 05ddd4e2..79197813 100644 --- a/src/core/matchers/toHaveBeenCalledWith.js +++ b/src/core/matchers/toHaveBeenCalledWith.js @@ -24,15 +24,32 @@ getJasmineRequireObj().toHaveBeenCalledWith = function(j$) { } if (!actual.calls.any()) { - result.message = function() { return 'Expected spy ' + actual.and.identity + ' to have been called with ' + j$.pp(expectedArgs) + ' but it was never called.'; }; + result.message = function() { + return 'Expected spy ' + actual.and.identity + ' to have been called with:\n' + + ' ' + j$.pp(expectedArgs) + + '\nbut it was never called.'; + }; return result; } if (util.contains(actual.calls.allArgs(), expectedArgs, customEqualityTesters)) { result.pass = true; - result.message = function() { return 'Expected spy ' + actual.and.identity + ' not to have been called with ' + j$.pp(expectedArgs) + ' but it was.'; }; + result.message = function() { + return 'Expected spy ' + actual.and.identity + ' not to have been called with:\n' + + ' ' + j$.pp(expectedArgs) + + '\nbut it was.'; + }; } else { - result.message = function() { return 'Expected spy ' + actual.and.identity + ' to have been called with ' + j$.pp(expectedArgs) + ' but actual calls were ' + j$.pp(actual.calls.allArgs()).replace(/^\[ | \]$/g, '') + '.'; }; + result.message = function() { + var prettyPrintedCalls = actual.calls.allArgs().map(function(argsForCall) { + return ' ' + j$.pp(argsForCall); + }); + + return 'Expected spy ' + actual.and.identity + ' to have been called with:\n' + + ' ' + j$.pp(expectedArgs) + '\n' + '' + + 'but actual calls were:\n' + + prettyPrintedCalls.join(',\n') + '.'; + }; } return result;