forked from kiwi-bdd/Kiwi
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow multiple
registerMatchers
in one context.
The old implementation appeared to mimic that of `beforeEach` and `afterEach`--it only allowed one per context. However, there is no need for such a restriction when registering custom matchers. This commit allows any number of matchers to be registered in a single context. Other changes: - Remove obsolete forward class declarations from KWExample header. - Delete commented out code from KWMatcherFactory. - Consolidate duplicated code in KWExample, KWContext in internal methods. - Add missing variable name from block typedef (only used in `defineMatcher` macro).
- Loading branch information
Showing
10 changed files
with
143 additions
and
55 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// Licensed under the terms in License.txt | ||
// | ||
// Copyright 2014 Allen Ding. All rights reserved. | ||
// | ||
|
||
#import "Kiwi.h" | ||
#import "Cruiser.h" | ||
|
||
#pragma mark - Custom Matcher Implementations | ||
|
||
@interface HALTHyperdriveLevelMatcher : KWMatcher | ||
@property (nonatomic, assign) NSInteger hyperdriveFuelLevel; | ||
@end | ||
|
||
@implementation HALTHyperdriveLevelMatcher | ||
|
||
+ (NSArray *)matcherStrings { | ||
return @[@"haveHyperdriveFuelLevelGreaterThan:"]; | ||
} | ||
|
||
- (BOOL)evaluate { | ||
return ((Cruiser *)self.subject).hyperdriveFuelLevel > self.hyperdriveFuelLevel; | ||
} | ||
|
||
- (void)haveHyperdriveFuelLevelGreaterThan:(NSInteger)hyperdriveFuelLevel { | ||
self.hyperdriveFuelLevel = hyperdriveFuelLevel; | ||
} | ||
|
||
@end | ||
|
||
@interface FLOWCrewComplementMatcher : KWMatcher | ||
@property (nonatomic, assign) NSInteger crewComplement; | ||
@end | ||
|
||
@implementation FLOWCrewComplementMatcher | ||
|
||
+ (NSArray *)matcherStrings { | ||
return @[@"haveCrewComplementLessThan:"]; | ||
} | ||
|
||
- (BOOL)evaluate { | ||
return ((Cruiser *)self.subject).crewComplement < self.crewComplement; | ||
} | ||
|
||
- (void)haveCrewComplementLessThan:(NSInteger)crewComplement { | ||
self.crewComplement = crewComplement; | ||
} | ||
|
||
@end | ||
|
||
#pragma mark - Tests | ||
|
||
SPEC_BEGIN(KWUserDefinedMatcherFunctionalTest) | ||
|
||
registerMatchers(@"HALT"); | ||
registerMatchers(@"FLOW"); | ||
|
||
describe(@"Cruiser", ^{ | ||
let(cruiser, ^id{ return [Cruiser new]; }); | ||
|
||
it(@"has a hyperdrive fuel level above 50", ^{ | ||
[[cruiser should] haveHyperdriveFuelLevelGreaterThan:50]; | ||
}); | ||
|
||
it(@"has a crew complement below 5000", ^{ | ||
[[cruiser should] haveCrewComplementLessThan:5000]; | ||
}); | ||
}); | ||
|
||
SPEC_END |