Permalink
Browse files

Add descriptions to matchers so we can generate nice names for anonym…

…ous specs. Closes #43.
  • Loading branch information...
1 parent 5472d94 commit 24de39e32d74d5e42f1704173717d8b99de589bc @lukeredpath lukeredpath committed Aug 31, 2011
Showing with 335 additions and 11 deletions.
  1. +1 −1 Classes/StringPrefixMatcher.m
  2. +7 −7 Kiwi.xcodeproj/project.pbxproj
  3. +5 −0 Kiwi/KWBeBetweenMatcher.m
  4. +5 −0 Kiwi/KWBeEmptyMatcher.m
  5. +5 −0 Kiwi/KWBeIdenticalToMatcher.m
  6. +5 −0 Kiwi/KWBeKindOfClassMatcher.m
  7. +5 −0 Kiwi/KWBeMemberOfClassMatcher.m
  8. +5 −0 Kiwi/KWBeNilMatcher.m
  9. +5 −0 Kiwi/KWBeNonNilMatcher.m
  10. +8 −0 Kiwi/KWBeTrueMatcher.m
  11. +5 −0 Kiwi/KWBeWithinMatcher.m
  12. +5 −0 Kiwi/KWBlockRaiseMatcher.m
  13. +6 −1 Kiwi/KWConformToProtocolMatcher.m
  14. +6 −1 Kiwi/KWContainMatcher.m
  15. +5 −0 Kiwi/KWEqualMatcher.m
  16. +5 −0 Kiwi/KWHamcrestMatcher.m
  17. +24 −0 Kiwi/KWHaveValueMatcher.m
  18. +5 −0 Kiwi/KWInequalityMatcher.m
  19. +5 −0 Kiwi/KWRaiseMatcher.m
  20. +6 −1 Kiwi/KWRespondToSelectorMatcher.m
  21. +3 −0 Kiwi/KWUserDefinedMatcher.h
  22. +12 −0 Kiwi/KWUserDefinedMatcher.m
  23. +7 −0 Tests/KWBeBetweenMatcherTest.m
  24. +7 −0 Tests/KWBeEmptyMatcherTest.m
  25. +7 −0 Tests/KWBeIndenticalToMatcherTest.m
  26. +7 −0 Tests/KWBeKindOfClassMatcherTest.m
  27. +7 −0 Tests/KWBeMemberOfClassMatcherTest.m
  28. +9 −0 Tests/KWBeTrueMatcherTest.m
  29. +7 −0 Tests/KWBeWithinMatcherTest.m
  30. +18 −0 Tests/KWBlockRaiseMatcherTest.m
  31. +7 −0 Tests/KWConformToProtocolMatcherTest.m
  32. +14 −0 Tests/KWContainMatcherTest.m
  33. +7 −0 Tests/KWEqualMatcherTest.m
  34. +7 −0 Tests/KWHamcrestMatcherTest.m
  35. +33 −0 Tests/KWHaveMatcherTest.m
  36. +19 −0 Tests/KWHaveValueMatcherTest.m
  37. +17 −0 Tests/KWInequalityMatcherTest.m
  38. +17 −0 Tests/KWRaiseMatcherTest.m
  39. +7 −0 Tests/KWRespondToSelectorMatcherTest.m
@@ -40,7 +40,7 @@ - (BOOL)matches:(id)item
- (NSString *)description
{
- return [NSString stringWithFormat:@"<a string with prefix '%@'>", prefix];
+ return [NSString stringWithFormat:@"a string with prefix '%@'", prefix];
}
@end
@@ -252,7 +252,7 @@
A352EA0D12EDC6F20049C691 /* KWHamrestMatchingAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWHamrestMatchingAdditions.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>"; };
+ A352EA1A12EDC8380049C691 /* KWHamcrestMatcherTest.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = KWHamcrestMatcherTest.m; sourceTree = "<group>"; tabWidth = 4; };
A35B033113CB30FF0045500C /* OneTestPerSpecExample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OneTestPerSpecExample.m; sourceTree = "<group>"; };
A385CAE713AA7EA200DCA951 /* KWUserDefinedMatcherTest.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = KWUserDefinedMatcherTest.m; sourceTree = "<group>"; tabWidth = 4; };
A385CAE913AA7ED800DCA951 /* KWUserDefinedMatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = KWUserDefinedMatcher.h; sourceTree = "<group>"; tabWidth = 4; };
@@ -324,16 +324,16 @@
F51A59BE1191D45500598B04 /* KWRealObjectStubTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWRealObjectStubTest.m; sourceTree = "<group>"; };
F52CD2A7115E1E760038A6A2 /* NSInvocation+KiwiAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSInvocation+KiwiAdditions.h"; sourceTree = "<group>"; };
F52CD2A8115E1E760038A6A2 /* NSInvocation+KiwiAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSInvocation+KiwiAdditions.m"; sourceTree = "<group>"; };
- F53B5E42115B33FC0022BC0B /* KWContainMatcherTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWContainMatcherTest.m; sourceTree = "<group>"; };
+ F53B5E42115B33FC0022BC0B /* KWContainMatcherTest.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = KWContainMatcherTest.m; sourceTree = "<group>"; tabWidth = 4; };
F53B5E65115B36EB0022BC0B /* KWEqualMatcherTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWEqualMatcherTest.m; sourceTree = "<group>"; };
- F53B5EC5115B3D180022BC0B /* KWRaiseMatcherTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWRaiseMatcherTest.m; sourceTree = "<group>"; };
+ F53B5EC5115B3D180022BC0B /* KWRaiseMatcherTest.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = KWRaiseMatcherTest.m; sourceTree = "<group>"; tabWidth = 4; };
F54A4B1D11733D98002442C5 /* KWBeKindOfClassMatcherTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWBeKindOfClassMatcherTest.m; sourceTree = "<group>"; };
F54A4B3611733E8A002442C5 /* KWBeKindOfClassMatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWBeKindOfClassMatcher.h; sourceTree = "<group>"; };
F54A4B3711733E8A002442C5 /* KWBeKindOfClassMatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWBeKindOfClassMatcher.m; sourceTree = "<group>"; };
F54A4BD411734750002442C5 /* KWBeMemberOfClassMatcherTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWBeMemberOfClassMatcherTest.m; sourceTree = "<group>"; };
F54A4BDE117347EF002442C5 /* KWBeMemberOfClassMatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWBeMemberOfClassMatcher.h; sourceTree = "<group>"; };
F54A4BDF117347EF002442C5 /* KWBeMemberOfClassMatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWBeMemberOfClassMatcher.m; sourceTree = "<group>"; };
- F54A4C0011734975002442C5 /* KWConformToProtocolMatcherTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWConformToProtocolMatcherTest.m; sourceTree = "<group>"; };
+ F54A4C0011734975002442C5 /* KWConformToProtocolMatcherTest.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = KWConformToProtocolMatcherTest.m; sourceTree = "<group>"; tabWidth = 4; };
F54A4C0B11734ABB002442C5 /* JumpCapable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JumpCapable.h; sourceTree = "<group>"; };
F54A4C1411734B82002442C5 /* KWConformToProtocolMatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWConformToProtocolMatcher.h; sourceTree = "<group>"; };
F54A4C1511734B82002442C5 /* KWConformToProtocolMatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWConformToProtocolMatcher.m; sourceTree = "<group>"; };
@@ -350,7 +350,7 @@
F553B4411175A190004FCA2E /* KWBeEmptyMatcherTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWBeEmptyMatcherTest.m; sourceTree = "<group>"; };
F553B4531175A292004FCA2E /* KWBeEmptyMatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWBeEmptyMatcher.h; sourceTree = "<group>"; };
F553B4541175A292004FCA2E /* KWBeEmptyMatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWBeEmptyMatcher.m; sourceTree = "<group>"; };
- F553B48A1175B238004FCA2E /* KWHaveMatcherTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWHaveMatcherTest.m; sourceTree = "<group>"; };
+ F553B48A1175B238004FCA2E /* KWHaveMatcherTest.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = KWHaveMatcherTest.m; sourceTree = "<group>"; tabWidth = 4; };
F553B4971175B3C3004FCA2E /* KWHaveMatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWHaveMatcher.h; sourceTree = "<group>"; };
F553B4981175B3C3004FCA2E /* KWHaveMatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWHaveMatcher.m; sourceTree = "<group>"; };
F553B6641175D48C004FCA2E /* KWRespondToSelectorMatcherTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWRespondToSelectorMatcherTest.m; sourceTree = "<group>"; };
@@ -411,7 +411,7 @@
F5BDB86A11C0CA9A00DD3474 /* KWBeforeAllNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWBeforeAllNode.m; sourceTree = "<group>"; };
F5BDB86D11C0CAA000DD3474 /* KWAfterAllNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWAfterAllNode.h; sourceTree = "<group>"; };
F5BDB86E11C0CAA000DD3474 /* KWAfterAllNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWAfterAllNode.m; sourceTree = "<group>"; };
- F5C36E91115C9F0700425FDA /* KWReceiveMatcherTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWReceiveMatcherTest.m; sourceTree = "<group>"; };
+ F5C36E91115C9F0700425FDA /* KWReceiveMatcherTest.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.objc; path = KWReceiveMatcherTest.m; sourceTree = "<group>"; tabWidth = 2; };
F5C4393D11BAB1A200615054 /* ExampleSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleSpec.m; sourceTree = "<group>"; tabWidth = 4; };
F5C5CB1911BCC45B0076529B /* KWExampleGroupBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWExampleGroupBuilder.h; sourceTree = "<group>"; };
F5C5CB1A11BCC45B0076529B /* KWExampleGroupBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWExampleGroupBuilder.m; sourceTree = "<group>"; };
@@ -440,7 +440,7 @@
F5E5032B119EA3CA00F5D05F /* KWBeIdenticalToMatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWBeIdenticalToMatcher.m; sourceTree = "<group>"; };
F5E9FC2F11AE6A0F0089BACE /* KWBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWBlock.h; sourceTree = "<group>"; };
F5E9FC3011AE6A0F0089BACE /* KWBlock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWBlock.m; sourceTree = "<group>"; };
- F5E9FC8411AE6E740089BACE /* KWBlockRaiseMatcherTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWBlockRaiseMatcherTest.m; sourceTree = "<group>"; };
+ F5E9FC8411AE6E740089BACE /* KWBlockRaiseMatcherTest.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = KWBlockRaiseMatcherTest.m; sourceTree = "<group>"; tabWidth = 4; };
F5E9FC8A11AE6F050089BACE /* KWBlockRaiseMatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWBlockRaiseMatcher.h; sourceTree = "<group>"; };
F5E9FC8B11AE6F050089BACE /* KWBlockRaiseMatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWBlockRaiseMatcher.m; sourceTree = "<group>"; };
F5ECAEE3116711D200B0BEEF /* ExampleTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ExampleTestCase.m; sourceTree = "<group>"; };
@@ -64,6 +64,11 @@ - (NSString *)failureMessageForShould {
[KWFormatter formatObject:self.subject]];
}
+- (NSString *)description
+{
+ return [NSString stringWithFormat:@"be between %@ and %@", self.lowerEndpoint, self.upperEndpoint];
+}
+
#pragma mark -
#pragma mark Configuring Matchers
View
@@ -65,6 +65,11 @@ - (NSString *)failureMessageForShouldNot {
return @"expected subject not to be empty";
}
+- (NSString *)description
+{
+ return @"be empty";
+}
+
#pragma mark -
#pragma mark Configuring Matchers
@@ -62,6 +62,11 @@ - (NSString *)failureMessageForShouldNot {
self.otherSubject];
}
+- (NSString *)description
+{
+ return [NSString stringWithFormat:@"be identical to %@", self.otherSubject];
+}
+
#pragma mark -
#pragma mark Configuring Matchers
@@ -45,6 +45,11 @@ - (NSString *)failureMessageForShould {
NSStringFromClass(self.targetClass)];
}
+- (NSString *)description
+{
+ return [NSString stringWithFormat:@"be kind of %@", NSStringFromClass(self.targetClass)];
+}
+
#pragma mark -
#pragma mark Configuring Matchers
@@ -45,6 +45,11 @@ - (NSString *)failureMessageForShould {
NSStringFromClass(self.targetClass)];
}
+- (NSString *)description
+{
+ return [NSString stringWithFormat:@"be member of %@", self.targetClass];
+}
+
#pragma mark -
#pragma mark Configuring Matchers
View
@@ -40,4 +40,9 @@ - (NSString *)failureMessageForShouldNot {
- (void)beNil {}
+- (NSString *)description
+{
+ return @"be nil";
+}
+
@end
View
@@ -38,6 +38,11 @@ - (NSString *)failureMessageForShouldNot {
[KWFormatter formatObject:self.subject]];
}
+- (NSString *)description
+{
+ return @"be non-nil";
+}
+
- (void)beNonNil {}
@end
View
@@ -47,6 +47,14 @@ - (NSString *)failureMessageForShould {
expectedValue ? @"true" : @"false"];
}
+- (NSString *)description
+{
+ if (self.expectedValue == YES) {
+ return @"be true";
+ }
+ return @"be false";
+}
+
#pragma mark -
#pragma mark Configuring Matchers
View
@@ -94,6 +94,11 @@ - (NSString *)failureMessageForShould {
[KWFormatter formatObject:self.subject]];
}
+- (NSString *)description
+{
+ return [NSString stringWithFormat:@"be within %@ of %@", self.distance, self.otherValue];
+}
+
#pragma mark -
#pragma mark Configuring Matchers
@@ -118,4 +118,9 @@ - (void)raiseWithName:(NSString *)aName reason:(NSString *)aReason {
self.exception = [NSException exceptionWithName:aName reason:aReason userInfo:nil];
}
+- (NSString *)description
+{
+ return [NSString stringWithFormat:@"raise %@", [[self class] exceptionPhraseWithException:self.exception]];
+}
+
@end
@@ -41,10 +41,15 @@ - (BOOL)evaluate {
#pragma mark Getting Failure Messages
- (NSString *)failureMessageForShould {
- return [NSString stringWithFormat:@"expected subject to conform to %@",
+ return [NSString stringWithFormat:@"expected subject to conform to %@ protocol",
NSStringFromProtocol(self.protocol)];
}
+- (NSString *)description
+{
+ return [NSString stringWithFormat:@"conform to %@ protocol", NSStringFromProtocol(self.protocol)];
+}
+
#pragma mark -
#pragma mark Configuring Matchers
View
@@ -61,13 +61,18 @@ - (NSString *)objectsPhrase {
if ([self.objects count] == 1)
return [KWFormatter formatObject:[self.objects objectAtIndex:0]];
- return [KWFormatter formatObject:self.objects];
+ return [NSString stringWithFormat:@"all of %@", [KWFormatter formatObject:self.objects]];
}
- (NSString *)failureMessageForShould {
return [NSString stringWithFormat:@"expected subject to contain %@", [self objectsPhrase]];
}
+- (NSString *)description
+{
+ return [NSString stringWithFormat:@"contain %@", [self objectsPhrase]];
+}
+
#pragma mark -
#pragma mark Configuring Matchers
View
@@ -64,6 +64,11 @@ - (NSString *)failureMessageForShouldNot {
[KWFormatter formatObject:self.otherSubject]];
}
+- (NSString *)description
+{
+ return [NSString stringWithFormat:@"equal %@", [KWFormatter formatObject:self.otherSubject]];
+}
+
#pragma mark -
#pragma mark Configuring Matchers
View
@@ -39,6 +39,11 @@ - (NSString *)failureMessageForShould {
return [NSString stringWithFormat:@"expected subject to match %@", self.matcher];
}
+- (NSString *)description
+{
+ return [NSString stringWithFormat:@"match %@", [self.matcher description]];
+}
+
#pragma mark -
#pragma mark Getting Matcher Strings
View
@@ -9,6 +9,7 @@
#import "KWHaveValueMatcher.h"
#import "KWHamrestMatchingAdditions.h"
#import "KWHCMatcher.h"
+#import "KWFormatter.h"
@interface KWHaveValueMatcher()
@@ -87,6 +88,29 @@ - (id)subjectValue;
return value;
}
+- (NSString *)description
+{
+ NSString *keyDescription = nil;
+
+ if (self.expectedKey) {
+ keyDescription = [NSString stringWithFormat:@"key %@", [KWFormatter formatObject:self.expectedKey]];
+ }
+ else {
+ keyDescription = [NSString stringWithFormat:@"keypath %@", [KWFormatter formatObject:self.expectedKeyPath]];
+ }
+
+ NSString *valueDescription = nil;
+
+ if (self.expectedValue) {
+ valueDescription = [NSString stringWithFormat:@"value %@", [KWFormatter formatObject:self.expectedValue]];
+ }
+ else {
+ valueDescription = @"value";
+ }
+
+ return [NSString stringWithFormat:@"have %@ for %@", valueDescription, keyDescription];
+}
+
#pragma mark -
#pragma mark Configuring Matchers
@@ -91,6 +91,11 @@ - (NSString *)failureMessageForShould {
[KWFormatter formatObject:self.subject]];
}
+- (NSString *)description
+{
+ return [NSString stringWithFormat:@"be %@ %@", [self comparisonPhrase], [KWFormatter formatObject:self.otherValue]];
+}
+
#pragma mark -
#pragma mark Configuring Matchers
View
@@ -98,6 +98,11 @@ - (NSString *)failureMessageForShouldNot {
[[self class] exceptionPhraseWithException:self.actualException]];
}
+- (NSString *)description
+{
+ return [NSString stringWithFormat:@"raise %@ when sent %@", [[self class] exceptionPhraseWithException:self.exception], NSStringFromSelector(self.selector)];
+}
+
#pragma mark -
#pragma mark Configuring Matchers
@@ -41,10 +41,15 @@ - (BOOL)evaluate {
#pragma mark Getting Failure Messages
- (NSString *)failureMessageForShould {
- return [NSString stringWithFormat:@"expected subject to respond -%@",
+ return [NSString stringWithFormat:@"expected subject to respond to -%@",
NSStringFromSelector(self.selector)];
}
+- (NSString *)description
+{
+ return [NSString stringWithFormat:@"respond to -%@", NSStringFromSelector(self.selector)];
+}
+
#pragma mark -
#pragma mark Configuring Matchers
@@ -23,6 +23,7 @@ typedef BOOL (^KWUserDefinedMatcherBlock)();
@property (nonatomic, copy) NSString *failureMessageForShould;
@property (nonatomic, copy) NSString *failureMessageForShouldNot;
@property (nonatomic, assign) KWUserDefinedMatcherBlock matcherBlock;
+@property (nonatomic, copy) NSString *description;
+ (id)matcherWithSubject:(id)aSubject block:(KWUserDefinedMatcherBlock)aBlock;
- (id)initWithSubject:(id)aSubject block:(KWUserDefinedMatcherBlock)aBlock;
@@ -38,6 +39,7 @@ typedef NSString * (^KWUserDefinedMatcherMessageBlock)(id);
KWUserDefinedMatcher *matcher;
KWUserDefinedMatcherMessageBlock failureMessageForShouldBlock;
KWUserDefinedMatcherMessageBlock failureMessageForShouldNotBlock;
+ NSString *description;
}
@property (nonatomic, readonly) NSString *key;
@@ -51,6 +53,7 @@ typedef NSString * (^KWUserDefinedMatcherMessageBlock)(id);
- (void)match:(KWUserDefinedMatcherBlock)block;
- (void)failureMessageForShould:(KWUserDefinedMatcherMessageBlock)block;
- (void)failureMessageForShouldNot:(KWUserDefinedMatcherMessageBlock)block;
+- (void)description:(NSString *)description;
#pragma mark -
#pragma mark Buiding The Matcher
@@ -14,6 +14,7 @@ @implementation KWUserDefinedMatcher
@synthesize failureMessageForShould;
@synthesize failureMessageForShouldNot;
@synthesize matcherBlock;
+@synthesize description;
+ (id)matcherWithSubject:(id)aSubject block:(KWUserDefinedMatcherBlock)aBlock
{
@@ -24,6 +25,7 @@ - (id)initWithSubject:(id)aSubject block:(KWUserDefinedMatcherBlock)aBlock
{
if ((self = [super initWithSubject:aSubject])) {
matcherBlock = [aBlock copy];
+ self.description = @"match user defined matcher";
}
return self;
}
@@ -146,6 +148,12 @@ - (void)failureMessageForShouldNot:(KWUserDefinedMatcherMessageBlock)block {
failureMessageForShouldNotBlock = [block copy];
}
+- (void)description:(NSString *)aDescription
+{
+ [description release];
+ description = [aDescription copy];
+}
+
#pragma mark -
#pragma mark Buiding The Matcher
@@ -160,6 +168,10 @@ - (KWUserDefinedMatcher *)buildMatcherWithSubject:(id)subject {
[matcher setFailureMessageForShouldNot:failureMessageForShouldNotBlock(subject)];
}
+ if (description) {
+ [matcher setDescription:description];
+ }
+
return matcher;
}
Oops, something went wrong.

0 comments on commit 24de39e

Please sign in to comment.