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.
Add DSL for setup/teardown of entire test suite
Example usage: #import <Kiwi/Kiwi.h> CONFIG_START beforeAllSpecs(^{ NSLog(@"BEFORE ALL SPECS"); }); afterAllSpecs(^{ NSLog(@"AFTER ALL SPECS"); }); CONFIG_END (Add this code to a file `<tests-dir>/Support/Config.m` and ensure it is part of your unit test bundle's Compile Sources build phase.) - - - Defines a `KWSuiteConfigurationBase` class that provides a `+defaultConfiguration` singleton instance. The first time this method is called, we look for a class named `KWSuiteConfiguration` that is a subclass of `KWSuiteConfigurationBase`, and instantiate it. This class is declared by using the `CONFIG_START` and `CONFIG_END` macros. When the default configuration receives the `-setUp` message, it sends `-configureSuite` to `self`, which executes the code between `CONFIG_START` and `CONFIG_END`. The blocks passed to `beforeAllSpecs` and `afterAllSpecs` are then executed in `-setUp` and `-tearDown`, respectively.
- Loading branch information
Adam Sharp
committed
Dec 16, 2013
1 parent
e86cc03
commit 253322a
Showing
6 changed files
with
114 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// KWSuiteConfigurationBase.h | ||
// Kiwi | ||
// | ||
// Created by Adam Sharp on 14/12/2013. | ||
// Copyright (c) 2013 Allen Ding. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface KWSuiteConfigurationBase : NSObject | ||
|
||
+ (instancetype)defaultConfiguration; | ||
|
||
- (void)configureSuite; | ||
|
||
- (void)setUp; | ||
- (void)tearDown; | ||
|
||
@property (nonatomic, copy) void (^beforeAllSpecsBlock)(void); | ||
@property (nonatomic, copy) void (^afterAllSpecsBlock)(void); | ||
|
||
@end | ||
|
||
void beforeAllSpecs(void (^block)(void)); | ||
void afterAllSpecs(void (^block)(void)); |
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,53 @@ | ||
// | ||
// KWSuiteConfigurationBase.m | ||
// Kiwi | ||
// | ||
// Created by Adam Sharp on 14/12/2013. | ||
// Copyright (c) 2013 Allen Ding. All rights reserved. | ||
// | ||
|
||
#import "KWSuiteConfigurationBase.h" | ||
|
||
@implementation KWSuiteConfigurationBase | ||
|
||
+ (instancetype)defaultConfiguration | ||
{ | ||
static Class configClass; | ||
static KWSuiteConfigurationBase *defaultConfiguration; | ||
|
||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
configClass = NSClassFromString(@"KWSuiteConfiguration"); | ||
if (configClass && [configClass isSubclassOfClass:[self class]]) { | ||
defaultConfiguration = [configClass new]; | ||
} | ||
}); | ||
|
||
return defaultConfiguration; | ||
} | ||
|
||
- (void)configureSuite {} | ||
|
||
- (void)setUp { | ||
[self configureSuite]; | ||
|
||
if (self.beforeAllSpecsBlock) { | ||
self.beforeAllSpecsBlock(); | ||
} | ||
} | ||
|
||
- (void)tearDown { | ||
if (self.afterAllSpecsBlock) { | ||
self.afterAllSpecsBlock(); | ||
} | ||
} | ||
|
||
@end | ||
|
||
void beforeAllSpecs(void (^block)(void)) { | ||
[[KWSuiteConfigurationBase defaultConfiguration] setBeforeAllSpecsBlock:block]; | ||
} | ||
|
||
void afterAllSpecs(void (^block)(void)) { | ||
[[KWSuiteConfigurationBase defaultConfiguration] setAfterAllSpecsBlock:block]; | ||
} |
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