Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added 'action' block which is run after all beforeEach and just befor…

…e example (it()). This one allows cleaner testing with less code duplication.
  • Loading branch information...
commit d5f0a2fa647bd0eb3491735061865427aa184bb4 1 parent 423c7c6
@lukasz-warchol lukasz-warchol authored
View
1  Source/CDRExample.m
@@ -57,6 +57,7 @@ - (void)run {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@try {
[parent_ setUp];
+ [parent_ runAction];
block_();
self.state = CDRExampleStatePassed;
} @catch (CDRSpecFailure *x) {
View
11 Source/CDRExampleGroup.m
@@ -8,6 +8,8 @@ - (void)stopObservingExamples;
@implementation CDRExampleGroup
@synthesize examples = examples_;
+@synthesize action = action_;
+
+ (id)groupWithText:(NSString *)text {
return [[[[self class] alloc] initWithText: text] autorelease];
@@ -29,6 +31,7 @@ - (id)initWithText:(NSString *)text isRoot:(BOOL)isRoot {
- (void)dealloc {
[afterBlocks_ release];
+ [action_ release];
[examples_ release];
[beforeBlocks_ release];
[super dealloc];
@@ -111,6 +114,14 @@ - (void)setUp {
}
}
+- (void)runAction
+{
+ [parent_ runAction];
+ if (self.action) {
+ self.action();
+ }
+}
+
- (void)tearDown {
for (CDRSpecBlock afterBlock in afterBlocks_) {
afterBlock();
View
4 Source/CDRSpec.m
@@ -10,6 +10,10 @@ void beforeEach(CDRSpecBlock block) {
[currentSpec.currentGroup addBefore:block];
}
+void action(CDRSpecBlock block) {
+ [currentSpec.currentGroup setAction:block];
+}
+
void afterEach(CDRSpecBlock block) {
[currentSpec.currentGroup addAfter:block];
}
View
2  Source/Headers/CDRExampleGroup.h
@@ -4,7 +4,7 @@
NSMutableArray *beforeBlocks_, *examples_, *afterBlocks_;
BOOL isRoot_;
}
-
+@property(nonatomic, copy) CDRSpecBlock action;
@property (nonatomic, readonly) NSArray *examples;
+ (id)groupWithText:(NSString *)text;
View
1  Source/Headers/CDRExampleParent.h
@@ -5,6 +5,7 @@
- (BOOL)shouldRun;
- (void)setUp;
+- (void)runAction;
- (void)tearDown;
@optional
View
1  Source/Headers/CDRSpec.h
@@ -13,6 +13,7 @@ extern const CDRSpecBlock PENDING;
extern "C" {
#endif
void beforeEach(CDRSpecBlock);
+void action(CDRSpecBlock block);
void afterEach(CDRSpecBlock);
CDRExampleGroup * describe(NSString *, CDRSpecBlock);
View
3  Source/SpecHelper.m
@@ -45,6 +45,9 @@ - (BOOL)shouldRun {
return NO;
}
+- (void)runAction
+{}
+
- (void)setUp {
if ([self respondsToSelector:@selector(beforeEach)]) {
NSLog(@"********************************************************************************");

1 comment on commit d5f0a2f

@robertwijas

This is super useful. We should create a pull request for that!

Please sign in to comment.
Something went wrong with that request. Please try again.