From d721418490e4c103b5bc64fbf69552f856088865 Mon Sep 17 00:00:00 2001 From: martyhines Date: Wed, 31 Jul 2013 10:40:28 -0400 Subject: [PATCH 1/4] Updated contribute.markdown links --- README.markdown | 2 +- Release.markdown | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index 3953cb0c..4b157cd8 100644 --- a/README.markdown +++ b/README.markdown @@ -9,7 +9,7 @@ Documentation & guides live here: [http://pivotal.github.com/jasmine/](http://pi ## Contributing -Please read the [contributors' guide](https://github.com/pivotal/jasmine/blob/master/Contribute.markdown) +Please read the [contributors' guide](https://github.com/pivotal/jasmine/blob/master/CONTRIBUTING.md) ## Support diff --git a/Release.markdown b/Release.markdown index 64774697..bc52df8f 100644 --- a/Release.markdown +++ b/Release.markdown @@ -3,7 +3,7 @@ ## Development ___Jasmine Core Maintainers Only___ -Follow the instructions in `Contribute.markdown` during development. +Follow the instructions in `CONTRIBUTING.md` during development. ### Git Rules From 4c4317b80e0daa50fe3558f35e8f64019aca1c2b Mon Sep 17 00:00:00 2001 From: Sheel Choksi Date: Sat, 3 Aug 2013 11:45:13 -0700 Subject: [PATCH 2/4] Update BrowserFlags to include Firefox - DRYs up the browser checking code - Adds in Firefox as another flag - Makes it possible to do checks like `if (env.ieVersion)` to target all IE versions --- spec/helpers/BrowserFlags.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/spec/helpers/BrowserFlags.js b/spec/helpers/BrowserFlags.js index fdd80dc4..c8300b62 100644 --- a/spec/helpers/BrowserFlags.js +++ b/spec/helpers/BrowserFlags.js @@ -1,19 +1,23 @@ (function(env) { - env.ieVersion = (function() { + function browserVersion(matchFn) { var userAgent = jasmine.getGlobal().navigator.userAgent; - if (!userAgent) { return Number.MAX_VALUE; } + if (!userAgent) { return void 0; } - var match = /MSIE ([0-9]{1,}[\.0-9]{0,})/.exec(userAgent); + var match = matchFn(userAgent); - return match ? parseFloat(match[1]) : Number.MAX_VALUE; - })(); + return match ? parseFloat(match[1]) : void 0; + } - env.safariVersion = (function() { - var userAgent = jasmine.getGlobal().navigator.userAgent; - if (!userAgent) { return Number.MAX_VALUE; } + env.ieVersion = browserVersion(function(userAgent) { + return /MSIE ([0-9]{1,}[\.0-9]{0,})/.exec(userAgent); + }); - var match = /Safari/.exec(userAgent) && /Version\/([0-9]{0,})/.exec(userAgent); + env.safariVersion = browserVersion(function(userAgent) { + return /Safari/.exec(userAgent) && /Version\/([0-9]{0,})/.exec(userAgent); + }); + + env.firefoxVersion = browserVersion(function(userAgent) { + return /Firefox\/([0-9]{0,})/.exec(userAgent); + }); - return match ? parseFloat(match[1]) : Number.MAX_VALUE; - })(); })(jasmine.getEnv()); From 0f42f2709a0b23ca978e4de54380b52977bf51cf Mon Sep 17 00:00:00 2001 From: Sheel Choksi Date: Sat, 3 Aug 2013 11:49:20 -0700 Subject: [PATCH 3/4] Update PrettyPrinter to better check for an Object Includes test case to fix FF as suggested by @ondras Fixes #409 --- lib/jasmine-core/jasmine.js | 2 +- spec/html/PrettyPrintHtmlSpec.js | 7 +++++++ src/core/PrettyPrinter.js | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index d5068882..8c16214c 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -1323,7 +1323,7 @@ getJasmineRequireObj().pp = function(j$) { this.emitScalar('Date(' + value + ')'); } else if (value.__Jasmine_been_here_before__) { this.emitScalar(''); - } else if (j$.isArray_(value) || typeof value == 'object') { + } else if (j$.isArray_(value) || j$.isA_('Object', value)) { value.__Jasmine_been_here_before__ = true; if (j$.isArray_(value)) { this.emitArray(value); diff --git a/spec/html/PrettyPrintHtmlSpec.js b/spec/html/PrettyPrintHtmlSpec.js index 371fe76f..8fd40548 100644 --- a/spec/html/PrettyPrintHtmlSpec.js +++ b/spec/html/PrettyPrintHtmlSpec.js @@ -5,4 +5,11 @@ describe("j$.pp (HTML Dependent)", function () { expect(j$.pp(sampleNode)).toEqual("HTMLNode"); expect(j$.pp({foo: sampleNode})).toEqual("{ foo : HTMLNode }"); }); + + it("should print Firefox's wrapped native objects correctly", function() { + if(jasmine.getEnv().firefoxVersion) { + try { new CustomEvent(); } catch(e) { var err = e; }; + expect(j$.pp(err)).toMatch(/Exception.*Not enough arguments/); + } + }); }); diff --git a/src/core/PrettyPrinter.js b/src/core/PrettyPrinter.js index 08d2f41c..31e953f5 100644 --- a/src/core/PrettyPrinter.js +++ b/src/core/PrettyPrinter.js @@ -29,7 +29,7 @@ getJasmineRequireObj().pp = function(j$) { this.emitScalar('Date(' + value + ')'); } else if (value.__Jasmine_been_here_before__) { this.emitScalar(''); - } else if (j$.isArray_(value) || typeof value == 'object') { + } else if (j$.isArray_(value) || j$.isA_('Object', value)) { value.__Jasmine_been_here_before__ = true; if (j$.isArray_(value)) { this.emitArray(value); From 5ba6e51e1cc837b5133ba4e740381f598bb9dedb Mon Sep 17 00:00:00 2001 From: Sheel Choksi Date: Mon, 26 Aug 2013 22:46:12 -0700 Subject: [PATCH 4/4] Restore custom failure messages for toHaveBeenCalledWith As pointed out by @tjgrathwell --- lib/jasmine-core/jasmine.js | 25 +++++++++++-------- .../core/matchers/toHaveBeenCalledWithSpec.js | 13 +++------- src/core/matchers/toHaveBeenCalledWith.js | 25 +++++++++++-------- 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 8c16214c..31ad40d6 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -2114,21 +2114,26 @@ getJasmineRequireObj().toHaveBeenCalledWith = function(j$) { compare: function() { var args = Array.prototype.slice.call(arguments, 0), actual = args[0], - expectedArgs = args.slice(1); + expectedArgs = args.slice(1), + result = { pass: false }; if (!j$.isSpy(actual)) { throw new Error('Expected a spy, but got ' + j$.pp(actual) + '.'); } - return { - pass: util.contains(actual.calls.allArgs(), expectedArgs) - }; - }, - message: function(actual) { - return { - affirmative: "Expected spy " + actual.and.identity() + " to have been called.", - negative: "Expected spy " + actual.and.identity() + " not to have been called." - }; + if (!actual.calls.any()) { + result.message = "Expected spy " + actual.and.identity() + " to have been called with " + j$.pp(expectedArgs) + " but it was never called."; + return result; + } + + if (util.contains(actual.calls.allArgs(), expectedArgs)) { + result.pass = true; + result.message = "Expected spy " + actual.and.identity() + " not to have been called with " + j$.pp(expectedArgs) + " but it was."; + } else { + result.message = "Expected spy " + actual.and.identity() + " to have been called with " + j$.pp(expectedArgs) + " but actual calls were " + j$.pp(actual.calls.allArgs()).replace(/^\[ | \]$/g, '') + "."; + } + + return result; } }; } diff --git a/spec/core/matchers/toHaveBeenCalledWithSpec.js b/spec/core/matchers/toHaveBeenCalledWithSpec.js index 3bac22c9..3e6a35a6 100644 --- a/spec/core/matchers/toHaveBeenCalledWithSpec.js +++ b/spec/core/matchers/toHaveBeenCalledWithSpec.js @@ -11,6 +11,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."); }); it("fails when the actual was not called", function() { @@ -23,6 +24,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."); }); it("fails when the actual was called with different parameters", function() { @@ -34,9 +36,11 @@ describe("toHaveBeenCalledWith", function() { result; calledSpy('a'); + calledSpy('c', 'd'); 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' ]."); }); it("throws an exception when the actual is not a spy", function() { @@ -45,13 +49,4 @@ describe("toHaveBeenCalledWith", function() { expect(function() { matcher.compare(fn) }).toThrow(new Error("Expected a spy, but got Function.")); }); - - it("has a custom message on failure", function() { - var matcher = j$.matchers.toHaveBeenCalledWith(), - spy = j$.createSpy('sample-spy'), - messages = matcher.message(spy); - - expect(messages.affirmative).toEqual("Expected spy sample-spy to have been called.") - expect(messages.negative).toEqual("Expected spy sample-spy not to have been called.") - }); }); diff --git a/src/core/matchers/toHaveBeenCalledWith.js b/src/core/matchers/toHaveBeenCalledWith.js index 0c655333..da9ccf37 100644 --- a/src/core/matchers/toHaveBeenCalledWith.js +++ b/src/core/matchers/toHaveBeenCalledWith.js @@ -5,21 +5,26 @@ getJasmineRequireObj().toHaveBeenCalledWith = function(j$) { compare: function() { var args = Array.prototype.slice.call(arguments, 0), actual = args[0], - expectedArgs = args.slice(1); + expectedArgs = args.slice(1), + result = { pass: false }; if (!j$.isSpy(actual)) { throw new Error('Expected a spy, but got ' + j$.pp(actual) + '.'); } - return { - pass: util.contains(actual.calls.allArgs(), expectedArgs) - }; - }, - message: function(actual) { - return { - affirmative: "Expected spy " + actual.and.identity() + " to have been called.", - negative: "Expected spy " + actual.and.identity() + " not to have been called." - }; + if (!actual.calls.any()) { + result.message = "Expected spy " + actual.and.identity() + " to have been called with " + j$.pp(expectedArgs) + " but it was never called."; + return result; + } + + if (util.contains(actual.calls.allArgs(), expectedArgs)) { + result.pass = true; + result.message = "Expected spy " + actual.and.identity() + " not to have been called with " + j$.pp(expectedArgs) + " but it was."; + } else { + result.message = "Expected spy " + actual.and.identity() + " to have been called with " + j$.pp(expectedArgs) + " but actual calls were " + j$.pp(actual.calls.allArgs()).replace(/^\[ | \]$/g, '') + "."; + } + + return result; } }; }