Last active
August 29, 2015 13:56
-
-
Save modocache/8910077 to your computer and use it in GitHub Desktop.
`registerMatcher` sample usage as of Feb 10, 2014.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "Kiwi.h" | |
#import "Cruiser.h" | |
registerMatcher(haveFighters) // From what I understand, the `registerMatcher` macro | |
registerMatcher(haveNoFighters) // is simply a trick to enable code completion in Xcode. | |
// Using this twice causes a warning for duplicate category | |
// definitions. | |
SPEC_BEGIN(KWUserDefinedMatcherFunctionalTest) | |
defineMatcher(@"haveFighters", ^(KWUserDefinedMatcherBuilder *builder) { // Matchers are customized by calling methods on builder | |
[builder match:^BOOL(id subject) { // `match:` takes a block which | |
if (![subject isKindOfClass:[Cruiser class]]) { // returns NO for match failure, | |
return NO; // YES otherwise | |
} | |
Cruiser *cruiser = subject; | |
return cruiser.fighters.count > 0; | |
}]; | |
[builder failureMessageForShould:^(id subject) { // You can also specify custom failure messages. | |
return [NSString stringWithFormat:@"%@ should have fighters", subject]; | |
}]; | |
}); | |
defineMatcher(@"haveNoFighters", ^(KWUserDefinedMatcherBuilder *builder) { | |
[builder match:^BOOL(id subject) { | |
if (![subject isKindOfClass:[Cruiser class]]) { | |
return NO; | |
} | |
Cruiser *cruiser = subject; | |
return cruiser.fighters.count == 0; | |
}]; | |
[builder failureMessageForShould:^(id subject) { | |
return [NSString stringWithFormat:@"%@ should have zero fighters", subject]; | |
}]; | |
}); | |
describe(@"Cruiser", ^{ | |
it(@"has fighters", ^{ | |
Cruiser *cruiser = [Cruiser new]; // | |
[[cruiser shouldNot] haveFighters]; // LLVM warns of Memory leak here. | |
[[cruiser should] haveNoFighters]; // | |
}); | |
}); | |
SPEC_END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have several problems with this:
match:
is a strange name for a method which takes a matcher block. A property might be nicer.