Permalink
Browse files

Fixed "contains" and "containsInAnyOrder" to describe mismatch if ite…

…m is not a collection.
  • Loading branch information...
1 parent 7728942 commit acded9ad341dc049c7b3a78d0e2814dd86156256 @jonreid jonreid committed Jan 24, 2011
View
@@ -6,6 +6,7 @@ Hamcrest information: http://code.google.com/p/hamcrest/
== Version 1.3 == *IN PROGRESS*
* Improved descriptions and mismatch descriptions of several matchers, including:
+ - Fixed "contains" and "containsInAnyOrder" to describe mismatch if item is not a collection.
- Fixed "describedAs" and "is" to use their nested matchers to generate mismatch descriptions.
- "sameInstance" is more readable, and includes object memory addresses.
- If object has a count, "hasCount" mismatch describes actual count.
@@ -132,7 +132,10 @@ - (BOOL) matches:(id)collection
- (BOOL) matches:(id)collection describingMismatchTo:(id<HCDescription, NSObject>)mismatchDescription
{
if (![collection conformsToProtocol:@protocol(NSFastEnumeration)])
+ {
+ [super describeMismatchOf:collection to:mismatchDescription];
return NO;
+ }
HCMatchingInAnyOrder *matchSequence =
[[[HCMatchingInAnyOrder alloc] initWithMatchers:matchers
@@ -136,7 +136,10 @@ - (BOOL) matches:(id)collection
- (BOOL) matches:(id)collection describingMismatchTo:(id<HCDescription, NSObject>)mismatchDescription
{
if (![collection conformsToProtocol:@protocol(NSFastEnumeration)])
+ {
+ [super describeMismatchOf:collection to:mismatchDescription];
return NO;
+ }
HCMatchSequence *matchSequence =
[[[HCMatchSequence alloc] initWithMatchers:matchers
@@ -116,4 +116,10 @@ - (void) testDescribeMismatch
([NSArray arrayWithObjects:@"a", @"c", nil]));
}
+
+- (void) testDescribeMismatchOfNonCollection
+{
+ assertDescribeMismatch(@"was nil", (containsInAnyOrder(@"a", @"b", nil)), nil);
+}
+
@end
@@ -114,4 +114,10 @@ - (void) testDescribeMismatch
([NSArray arrayWithObjects:@"a", @"c", nil]));
}
+
+- (void) testDescribeMismatchOfNonCollection
+{
+ assertDescribeMismatch(@"was nil", (contains(@"a", @"b", nil)), nil);
+}
+
@end
@@ -93,4 +93,10 @@ - (void) testDescribeMismatch
assertDescribeMismatch(@"was \"bad\"", (onlyContains(@"a", @"b", nil)), @"bad");
}
+
+- (void) testDescribeMismatchOfNonCollection
+{
+ assertDescribeMismatch(@"was nil", (onlyContains(@"a", @"b", nil)), nil);
+}
+
@end

0 comments on commit acded9a

Please sign in to comment.