Skip to content
Browse files

Updated jshamcrest

  • Loading branch information...
1 parent bc96fdf commit 12935bca5c9bcb8c8289cac3dd332146ba39ff42 @cleishm committed
Showing with 44 additions and 9 deletions.
  1. +44 −9 lib/jshamcrest.js
View
53 lib/jshamcrest.js
@@ -1,5 +1,5 @@
/*
- * JsHamcrest v0.6.2
+ * JsHamcrest v0.6.3
* http://jshamcrest.destaquenet.com
*
* Library of matcher objects for JavaScript.
@@ -7,15 +7,15 @@
* Copyright (c) 2009-2010 Daniel Fernandes Martins
* Licensed under the BSD license.
*
- * Revision: 40a0bcaf1807573802fb6f5bb7d6e2502a38f325
- * Date: Thu Sep 30 15:32:06 2010 -0300
+ * Revision: 194255813953ee1dd8e2ef5e825bf8e01f10a94a
+ * Date: Tue May 24 09:41:00 2011 -0700
*/
JsHamcrest = {
/**
* Library version.
*/
- version: '0.6.2',
+ version: '0.6.3',
/**
* Returns whether the given object is a matcher.
@@ -720,17 +720,25 @@ JsHamcrest.Matchers.emailAddress = function() {
/**
* The actual value has a member with the given name.
*/
-JsHamcrest.Matchers.hasMember = function(memberName) {
+JsHamcrest.Matchers.hasMember = function(memberName, matcherOrValue) {
+ var undefined;
+ if (matcherOrValue === undefined) {
+ matcherOrValue = JsHamcrest.Matchers.anything();
+ } else if (!JsHamcrest.isMatcher(matcherOrValue)) {
+ matcherOrValue = JsHamcrest.Matchers.equalTo(matcherOrValue);
+ }
+
return new JsHamcrest.SimpleMatcher({
matches: function(actual) {
- if (actual) {
- return memberName in actual;
+ if (actual && memberName in actual) {
+ return matcherOrValue.matches(actual[memberName]);
}
return false;
},
describeTo: function(description) {
- description.append('has member ').appendLiteral(memberName);
+ description.append('has member ').appendLiteral(memberName)
+ .append(' (').appendDescriptionOf(matcherOrValue).append(')');
}
});
};
@@ -1266,7 +1274,7 @@ JsHamcrest.Integration = (function() {
JsHamcrest.Integration.copyMembers(target);
- // Assertion method exposed to jsUnity.
+ // Assertion method exposed to Screw.Unit.
target.assertThat = function(actual, matcher, message) {
return JsHamcrest.Operators.assert(actual, matcher, {
message: message,
@@ -1275,6 +1283,33 @@ JsHamcrest.Integration = (function() {
}
});
};
+ },
+
+ /**
+ * Jasmine integration.
+ */
+ jasmine: function(params) {
+ params = params ? params : {};
+ var target = params.scope || self;
+
+ JsHamcrest.Integration.copyMembers(target);
+
+ // Assertion method exposed to Jasmine.
+ target.assertThat = function(actual, matcher, message) {
+ return JsHamcrest.Operators.assert(actual, matcher, {
+ message: message,
+ fail: function(message) {
+ jasmine.getEnv().currentSpec.addMatcherResult(
+ new jasmine.ExpectationResult({passed:false, message:message})
+ );
+ },
+ pass: function(message) {
+ jasmine.getEnv().currentSpec.addMatcherResult(
+ new jasmine.ExpectationResult({passed:true, message:message})
+ );
+ }
+ });
+ };
}
};
})();

0 comments on commit 12935bc

Please sign in to comment.
Something went wrong with that request. Please try again.