Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rename hashContaining to objectContaining, since this is javascript. …

…Also call the toString from prettyPrinter
  • Loading branch information...
commit 7158fc24262db0318f4595e7bec0531e1970e5d0 1 parent 992367d
@slackersoft slackersoft authored
View
14 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.any(' + this.expectedClass + ')>';
};
-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 "<jasmine.hashContaining(" + jasmine.pp(this.sample) + ")>";
};
/**
View
12 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("<jasmine.hashContaining({ })>");
+ expect(containing.toString()).toEqual("<jasmine.objectContaining({ })>");
});
});
@@ -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("<jasmine.hashContaining(" + jasmine.pp({foo:"fooVal", bar:"barVal"}) + ")>");
+ expect(containing.toString()).toEqual("<jasmine.objectContaining(" + jasmine.pp({foo:"fooVal", bar:"barVal"}) + ")>");
});
});
@@ -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"}));
});
});
});
View
7 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();
+ });
});
View
4 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);
}
View
8 src/core/Matchers.js
@@ -369,11 +369,11 @@ jasmine.Matchers.Any.prototype.toString = function() {
return '<jasmine.any(' + this.expectedClass + ')>';
};
-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.hashContaining(" + jasmine.pp(this.sample) + ")>";
+jasmine.Matchers.ObjectContaining.prototype.toString = function () {
+ return "<jasmine.objectContaining(" + jasmine.pp(this.sample) + ")>";
};
View
2  src/core/PrettyPrinter.js
@@ -25,6 +25,8 @@ jasmine.PrettyPrinter.prototype.format = function(value) {
this.emitScalar('<global>');
} 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)) {
View
8 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);
};
/**
Please sign in to comment.
Something went wrong with that request. Please try again.