Permalink
Browse files

Added a new Hamcrest matcher for explicit use of hamcrest matchers.

  • Loading branch information...
1 parent 665b6c4 commit 43b8407fc911fad82d397fb57972a61c7fafe60b Luke Redpath committed Jan 24, 2011
Showing with 123 additions and 1 deletion.
  1. +10 −0 Kiwi.xcodeproj/project.pbxproj
  2. +1 −1 Kiwi/KWHCMatcher.h
  3. +22 −0 Kiwi/KWHamcrestMatcher.h
  4. +52 −0 Kiwi/KWHamcrestMatcher.m
  5. +1 −0 Kiwi/Kiwi.h
  6. +37 −0 Tests/KWHamcrestMatcherTest.m
@@ -26,6 +26,8 @@
A352E9E812EDC30A0049C691 /* KWHaveValueMatcherTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A352E9E712EDC30A0049C691 /* KWHaveValueMatcherTest.m */; };
A352E9EB12EDC33C0049C691 /* KWHaveValueMatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = A352E9EA12EDC33C0049C691 /* KWHaveValueMatcher.m */; };
A352EA0E12EDC6F20049C691 /* NSObject+KiwiAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = A352EA0D12EDC6F20049C691 /* NSObject+KiwiAdditions.m */; };
+ A352EA1912EDC8160049C691 /* KWHamcrestMatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = A352EA1812EDC8160049C691 /* KWHamcrestMatcher.m */; };
+ A352EA1B12EDC8380049C691 /* KWHamcrestMatcherTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A352EA1A12EDC8380049C691 /* KWHamcrestMatcherTest.m */; };
A38083D612E4A3DA009CB99A /* KWHCMatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = A3A1753E12E49505004DFD70 /* KWHCMatcher.h */; };
A3A1739C12E47068004DFD70 /* ExampleAsyncSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = A3A1739B12E47068004DFD70 /* ExampleAsyncSpec.m */; };
A3A1754112E4966F004DFD70 /* Robot.m in Sources */ = {isa = PBXBuildFile; fileRef = A3A1754012E4966F004DFD70 /* Robot.m */; };
@@ -231,6 +233,9 @@
A352E9EA12EDC33C0049C691 /* KWHaveValueMatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWHaveValueMatcher.m; sourceTree = "<group>"; };
A352EA0C12EDC6F20049C691 /* NSObject+KiwiAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+KiwiAdditions.h"; sourceTree = "<group>"; };
A352EA0D12EDC6F20049C691 /* NSObject+KiwiAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+KiwiAdditions.m"; sourceTree = "<group>"; };
+ A352EA1712EDC8160049C691 /* KWHamcrestMatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWHamcrestMatcher.h; sourceTree = "<group>"; };
+ A352EA1812EDC8160049C691 /* KWHamcrestMatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWHamcrestMatcher.m; sourceTree = "<group>"; };
+ A352EA1A12EDC8380049C691 /* KWHamcrestMatcherTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWHamcrestMatcherTest.m; sourceTree = "<group>"; };
A3A1739B12E47068004DFD70 /* ExampleAsyncSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleAsyncSpec.m; sourceTree = "<group>"; };
A3A1753E12E49505004DFD70 /* KWHCMatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWHCMatcher.h; sourceTree = "<group>"; };
A3A1753F12E4966F004DFD70 /* Robot.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Robot.h; sourceTree = "<group>"; };
@@ -644,6 +649,8 @@
A3A1757612E49900004DFD70 /* KWBeNonNilMatcher.m */,
A352E9E912EDC33C0049C691 /* KWHaveValueMatcher.h */,
A352E9EA12EDC33C0049C691 /* KWHaveValueMatcher.m */,
+ A352EA1712EDC8160049C691 /* KWHamcrestMatcher.h */,
+ A352EA1812EDC8160049C691 /* KWHamcrestMatcher.m */,
);
name = Matchers;
sourceTree = "<group>";
@@ -775,6 +782,7 @@
F5C36E91115C9F0700425FDA /* KWReceiveMatcherTest.m */,
F553B6641175D48C004FCA2E /* KWRespondToSelectorMatcherTest.m */,
A352E9E712EDC30A0049C691 /* KWHaveValueMatcherTest.m */,
+ A352EA1A12EDC8380049C691 /* KWHamcrestMatcherTest.m */,
);
name = Matchers;
sourceTree = "<group>";
@@ -1165,6 +1173,8 @@
A352E9E812EDC30A0049C691 /* KWHaveValueMatcherTest.m in Sources */,
A352E9EB12EDC33C0049C691 /* KWHaveValueMatcher.m in Sources */,
A352EA0E12EDC6F20049C691 /* NSObject+KiwiAdditions.m in Sources */,
+ A352EA1912EDC8160049C691 /* KWHamcrestMatcher.m in Sources */,
+ A352EA1B12EDC8380049C691 /* KWHamcrestMatcherTest.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
@@ -7,6 +7,6 @@
#import <Foundation/Foundation.h>
-@protocol HCMatcher
+@protocol HCMatcher <NSObject>
- (BOOL)matches:(id)item;
@end
View
@@ -0,0 +1,22 @@
+//
+// KWHamcrestMatcher.h
+// Kiwi
+//
+// Created by Luke Redpath on 24/01/2011.
+// Copyright 2011 Allen Ding. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import "KWMatcher.h"
+#import "KWHCMatcher.h"
+
+@interface KWHamcrestMatcher : KWMatcher {
+ id<HCMatcher> hamcrestMatcher;
+}
+
+#pragma mark -
+#pragma mark Configuring Matchers
+
+- (void)match:(id<HCMatcher>)aMatcher;
+
+@end
View
@@ -0,0 +1,52 @@
+//
+// KWHamcrestMatcher.m
+// Kiwi
+//
+// Created by Luke Redpath on 24/01/2011.
+// Copyright 2011 Allen Ding. All rights reserved.
+//
+
+#import "KWHamcrestMatcher.h"
+
+@interface KWHamcrestMatcher ()
+
+#pragma mark -
+#pragma mark Properties
+
+@property (nonatomic, retain) id<HCMatcher> matcher;
+
+@end
+
+@implementation KWHamcrestMatcher
+
+@synthesize matcher;
+
+- (void)dealloc
+{
+ [matcher release];
+ [super dealloc];
+}
+
+#pragma mark -
+#pragma mark Matching
+
+- (BOOL)evaluate {
+ return [self.matcher matches:self.subject];
+}
+
+#pragma mark -
+#pragma mark Getting Matcher Strings
+
++ (NSArray *)matcherStrings {
+ return [NSArray arrayWithObjects:@"match:", nil];
+}
+
+#pragma mark -
+#pragma mark Configuring Matchers
+
+- (void)match:(id<HCMatcher>)aMatcher;
+{
+ self.matcher = aMatcher;
+}
+
+@end
View
@@ -41,6 +41,7 @@
#import "KWFailure.h"
#import "KWFormatter.h"
#import "KWFutureObject.h"
+#import "KWHamcrestMatcher.h"
#import "KWHaveMatcher.h"
#import "KWHaveValueMatcher.h"
#import "KWInequalityMatcher.h"
@@ -0,0 +1,37 @@
+//
+// KWHamcrestMatcherTest.m
+// Kiwi
+//
+// Created by Luke Redpath on 24/01/2011.
+// Copyright 2011 Allen Ding. All rights reserved.
+//
+
+#import "Kiwi.h"
+#import "KiwiTestConfiguration.h"
+#import "TestClasses.h"
+
+#if KW_TESTS_ENABLED
+
+@interface KWHamcrestMatcherTest : SenTestCase
+
+@end
+
+@implementation KWHamcrestMatcherTest
+
+- (void)testItShouldMatchObjectsThatMatchHamcrestMatchers
+{
+ id matcher = [KWHamcrestMatcher matcherWithSubject:@"Alpha Bravo"];
+ [matcher match:hasPrefix(@"Alpha")];
+ STAssertTrue([matcher evaluate], @"expected positive match");
+}
+
+- (void)testItShouldNotMatchObjectsThatMatchHamcrestMatchers
+{
+ id matcher = [KWHamcrestMatcher matcherWithSubject:@"Charlie Bravo"];
+ [matcher match:hasPrefix(@"Alpha")];
+ STAssertFalse([matcher evaluate], @"expected negative match");
+}
+
+@end
+
+#endif

0 comments on commit 43b8407

Please sign in to comment.