diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 2093f95d..f1099d17 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -207,8 +207,8 @@ jasmine.any = function(clazz) { * @param sample {Object} sample * @returns matchable object for the sample */ -jasmine.hashContaining = function (sample) { - return new jasmine.Matchers.HashContaining(sample); +jasmine.objectContaining = function (sample) { + return new jasmine.Matchers.ObjectContaining(sample); }; /** @@ -937,11 +937,11 @@ jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) { return b.matches(a); } - if (a instanceof jasmine.Matchers.HashContaining) { + if (a instanceof jasmine.Matchers.ObjectContaining) { return a.matches(b); } - if (b instanceof jasmine.Matchers.HashContaining) { + if (b instanceof jasmine.Matchers.ObjectContaining) { return b.matches(a); } @@ -1500,11 +1500,11 @@ jasmine.Matchers.Any.prototype.toString = function() { return ''; }; -jasmine.Matchers.HashContaining = function (sample) { +jasmine.Matchers.ObjectContaining = function (sample) { this.sample = sample; }; -jasmine.Matchers.HashContaining.prototype.matches = function(other, mismatchKeys, mismatchValues) { +jasmine.Matchers.ObjectContaining.prototype.matches = function(other, mismatchKeys, mismatchValues) { mismatchKeys = mismatchKeys || []; mismatchValues = mismatchValues || []; @@ -1526,7 +1526,7 @@ jasmine.Matchers.HashContaining.prototype.matches = function(other, mismatchKeys return (mismatchKeys.length === 0 && mismatchValues.length === 0); }; -jasmine.Matchers.HashContaining.prototype.toString = function () { +jasmine.Matchers.ObjectContaining.prototype.toString = function () { return ""; }; /** diff --git a/spec/core/MatchersSpec.js b/spec/core/MatchersSpec.js index e655bf0a..ceaafc01 100644 --- a/spec/core/MatchersSpec.js +++ b/spec/core/MatchersSpec.js @@ -834,14 +834,14 @@ describe("jasmine.Matchers", function() { describe("with an empty hash", function () { var containing; beforeEach(function () { - containing = new jasmine.Matchers.HashContaining({}); + containing = new jasmine.Matchers.ObjectContaining({}); }); it("matches everything", function () { expect(containing.matches("foo", [], [])).toBe(true); }); it("says it didn't expect to contain anything", function () { - expect(containing.toString()).toEqual(""); + expect(containing.toString()).toEqual(""); }); }); @@ -850,7 +850,7 @@ describe("jasmine.Matchers", function() { beforeEach(function () { mismatchKeys = []; mismatchValues = []; - containing = new jasmine.Matchers.HashContaining({foo: "fooVal", bar: "barVal"}); + containing = new jasmine.Matchers.ObjectContaining({foo: "fooVal", bar: "barVal"}); }); it("doesn't match an empty object", function () { @@ -894,7 +894,7 @@ describe("jasmine.Matchers", function() { }); it("says what it expects to contain", function () { - expect(containing.toString()).toEqual(""); + expect(containing.toString()).toEqual(""); }); }); @@ -905,11 +905,11 @@ describe("jasmine.Matchers", function() { method({a:"b", c:"d"}); }); it("works correctly for positive matches", function () { - expect(method).toHaveBeenCalledWith(jasmine.hashContaining({a:"b"})); + expect(method).toHaveBeenCalledWith(jasmine.objectContaining({a:"b"})); }); it("works correctly for negative matches", function () { - expect(method).not.toHaveBeenCalledWith(jasmine.hashContaining({z:"x"})); + expect(method).not.toHaveBeenCalledWith(jasmine.objectContaining({z:"x"})); }); }); }); diff --git a/spec/core/PrettyPrintSpec.js b/spec/core/PrettyPrintSpec.js index 37f71041..2faea310 100644 --- a/spec/core/PrettyPrintSpec.js +++ b/spec/core/PrettyPrintSpec.js @@ -83,5 +83,12 @@ describe("jasmine.pp", function () { expect(jasmine.pp(jasmine.createSpy("something"))).toEqual("spy on something"); }); + it("calls toString for ObjectContaining objects", function () { + var containing = new jasmine.Matchers.ObjectContaining({}); + spyOn(containing, "toString").andReturn("stringified!"); + + expect(jasmine.pp(containing)).toEqual("stringified!"); + expect(containing.toString).toHaveBeenCalled(); + }); }); diff --git a/src/core/Env.js b/src/core/Env.js index bf72c88c..e9a672de 100644 --- a/src/core/Env.js +++ b/src/core/Env.js @@ -238,11 +238,11 @@ jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) { return b.matches(a); } - if (a instanceof jasmine.Matchers.HashContaining) { + if (a instanceof jasmine.Matchers.ObjectContaining) { return a.matches(b); } - if (b instanceof jasmine.Matchers.HashContaining) { + if (b instanceof jasmine.Matchers.ObjectContaining) { return b.matches(a); } diff --git a/src/core/Matchers.js b/src/core/Matchers.js index 122e32b4..ddcc6600 100644 --- a/src/core/Matchers.js +++ b/src/core/Matchers.js @@ -369,11 +369,11 @@ jasmine.Matchers.Any.prototype.toString = function() { return ''; }; -jasmine.Matchers.HashContaining = function (sample) { +jasmine.Matchers.ObjectContaining = function (sample) { this.sample = sample; }; -jasmine.Matchers.HashContaining.prototype.matches = function(other, mismatchKeys, mismatchValues) { +jasmine.Matchers.ObjectContaining.prototype.matches = function(other, mismatchKeys, mismatchValues) { mismatchKeys = mismatchKeys || []; mismatchValues = mismatchValues || []; @@ -395,6 +395,6 @@ jasmine.Matchers.HashContaining.prototype.matches = function(other, mismatchKeys return (mismatchKeys.length === 0 && mismatchValues.length === 0); }; -jasmine.Matchers.HashContaining.prototype.toString = function () { - return ""; +jasmine.Matchers.ObjectContaining.prototype.toString = function () { + return ""; }; diff --git a/src/core/PrettyPrinter.js b/src/core/PrettyPrinter.js index 7d890c02..d44bb24d 100644 --- a/src/core/PrettyPrinter.js +++ b/src/core/PrettyPrinter.js @@ -25,6 +25,8 @@ jasmine.PrettyPrinter.prototype.format = function(value) { this.emitScalar(''); } else if (value instanceof jasmine.Matchers.Any) { this.emitScalar(value.toString()); + } else if (value instanceof jasmine.Matchers.ObjectContaining) { + this.emitScalar(value.toString()); } else if (typeof value === 'string') { this.emitString(value); } else if (jasmine.isSpy(value)) { diff --git a/src/core/base.js b/src/core/base.js index cf84c07d..3a61b3d8 100755 --- a/src/core/base.js +++ b/src/core/base.js @@ -197,18 +197,18 @@ jasmine.any = function(clazz) { }; /** - * Returns a matchable subset of a hash/JSON object. For use in expectations when you don't care about all of the + * Returns a matchable subset of a JSON object. For use in expectations when you don't care about all of the * attributes on the object. * * @example * // don't care about any other attributes than foo. - * expect(mySpy).toHaveBeenCalledWith(jasmine.hashContaining({foo: "bar"}); + * expect(mySpy).toHaveBeenCalledWith(jasmine.objectContaining({foo: "bar"}); * * @param sample {Object} sample * @returns matchable object for the sample */ -jasmine.hashContaining = function (sample) { - return new jasmine.Matchers.HashContaining(sample); +jasmine.objectContaining = function (sample) { + return new jasmine.Matchers.ObjectContaining(sample); }; /**