Permalink
Please sign in to comment.
Browse files
WIP: fix for issue #64, ensuring beforeAll and afterAll work as expec…
…ted.
- Loading branch information...
Showing
with
167 additions
and 52 deletions.
- +17 −0 Examples/SimpleSpec.m
- +8 −0 Kiwi.xcodeproj/project.pbxproj
- +3 −0 Kiwi/KWExampleGroup.h
- +4 −16 Kiwi/KWExampleGroup.m
- +4 −2 Kiwi/KWExampleGroupBuilder.h
- +14 −15 Kiwi/KWExampleGroupBuilder.m
- +2 −0 Kiwi/KWExampleNodeVisitor.h
- +26 −0 Kiwi/KWExampleSuite.h
- +83 −0 Kiwi/KWExampleSuite.m
- +6 −19 Kiwi/KWSpec.m
@@ -0,0 +1,26 @@ | ||
+// | ||
+// KWExampleSuite.h | ||
+// Kiwi | ||
+// | ||
+// Created by Luke Redpath on 17/10/2011. | ||
+// Copyright (c) 2011 Allen Ding. All rights reserved. | ||
+// | ||
+ | ||
+#import <Foundation/Foundation.h> | ||
+#import "KWExampleNodeVisitor.h" | ||
+ | ||
+@class KWContextNode; | ||
+@class KWExampleGroup; | ||
+@class SenTestCase; | ||
+ | ||
+#define kKWINVOCATION_EXAMPLE_GROUP_KEY @"__KWExampleGroupKey" | ||
+ | ||
+@interface KWExampleSuite : NSObject <KWExampleNodeVisitor> { | ||
+ KWContextNode *rootNode; | ||
+ NSMutableSet *exampleGroups; | ||
+ NSMutableSet *visitedNodes; | ||
+} | ||
+- (id)initWithRootNode:(KWContextNode *)contextNode; | ||
+- (void)addExampleGroup:(KWExampleGroup *)exampleGroup; | ||
+- (NSArray *)invocationsForTestCase; | ||
+@end |
@@ -0,0 +1,83 @@ | ||
+// | ||
+// KWExampleSuite.m | ||
+// Kiwi | ||
+// | ||
+// Created by Luke Redpath on 17/10/2011. | ||
+// Copyright (c) 2011 Allen Ding. All rights reserved. | ||
+// | ||
+ | ||
+#import "KWExampleSuite.h" | ||
+#import "KWExampleGroup.h" | ||
+#import "KWStringUtilities.h" | ||
+#import "KWBeforeAllNode.h" | ||
+#import "KWAfterAllNode.h" | ||
+#import "NSMethodSignature+KiwiAdditions.h" | ||
+#import <objc/runtime.h> | ||
+ | ||
+ | ||
+@implementation KWExampleSuite | ||
+ | ||
+- (id)initWithRootNode:(KWContextNode *)contextNode | ||
+{ | ||
+ if ((self = [super init])) { | ||
+ rootNode = [contextNode retain]; | ||
+ exampleGroups = [[NSMutableSet alloc] init]; | ||
+ visitedNodes = [[NSMutableSet alloc] init]; | ||
+ } | ||
+ return self; | ||
+} | ||
+ | ||
+- (void)dealloc | ||
+{ | ||
+ [visitedNodes release]; | ||
+ [exampleGroups release]; | ||
+ [rootNode release]; | ||
+ [super dealloc]; | ||
+} | ||
+ | ||
+- (void)addExampleGroup:(KWExampleGroup *)exampleGroup | ||
+{ | ||
+ [exampleGroups addObject:exampleGroup]; | ||
+ [exampleGroup setSuite:self]; | ||
+} | ||
+ | ||
+- (NSArray *)invocationsForTestCase; | ||
+{ | ||
+ NSMutableArray *invocations = [NSMutableArray array]; | ||
+ | ||
+ for (KWExampleGroup *exampleGroup in exampleGroups) { | ||
+ // Add a single dummy invocation for each example group | ||
+ NSMethodSignature *methodSignature = [NSMethodSignature signatureWithObjCTypes:[KWEncodingForVoidMethod() UTF8String]]; | ||
+ NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature]; | ||
+ | ||
+ [invocations addObject:invocation]; | ||
+ | ||
+ // because SenTest will modify the invocation target, we'll have to store | ||
+ // another reference to the example group so we can retrieve it later | ||
+ objc_setAssociatedObject(invocation, kKWINVOCATION_EXAMPLE_GROUP_KEY, exampleGroup, OBJC_ASSOCIATION_RETAIN); | ||
+ } | ||
+ | ||
+ return invocations; | ||
+} | ||
+ | ||
+#pragma mark - Node visiting | ||
+ | ||
+- (void)visitBeforeAllNode:(KWBeforeAllNode *)aNode { | ||
+ if (aNode.block == nil || [visitedNodes containsObject:aNode]) | ||
+ return; | ||
+ | ||
+ [visitedNodes addObject:aNode]; | ||
+ | ||
+ aNode.block(); | ||
+} | ||
+ | ||
+- (void)visitAfterAllNode:(KWAfterAllNode *)aNode { | ||
+ if (aNode.block == nil || [visitedNodes containsObject:aNode]) | ||
+ return; | ||
+ | ||
+ [visitedNodes addObject:aNode]; | ||
+ | ||
+ aNode.block(); | ||
+} | ||
+ | ||
+@end |

Oops, something went wrong.
0 comments on commit
9c878f0