Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Output spec names with each context description correctly.

The exampleNodeStack is no longer used by KWExample, so it can be removed.

This continues work on Issue #64
  • Loading branch information...
commit 63b911c0fe595da2378384cba5f0cc010a9ae255 1 parent e32bc53
@lukeredpath lukeredpath authored
View
2  Kiwi.xcodeproj/project.pbxproj
@@ -321,7 +321,7 @@
F50922FB1165E43D00083EB1 /* NSValue+KiwiAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSValue+KiwiAdditions.h"; sourceTree = "<group>"; };
F50922FC1165E43D00083EB1 /* NSValue+KiwiAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSValue+KiwiAdditions.m"; sourceTree = "<group>"; };
F50C749F11BE835C005BB3E2 /* KWPendingNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWPendingNode.h; sourceTree = "<group>"; };
- F50C74A011BE835C005BB3E2 /* KWPendingNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWPendingNode.m; sourceTree = "<group>"; };
+ F50C74A011BE835C005BB3E2 /* KWPendingNode.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = KWPendingNode.m; sourceTree = "<group>"; tabWidth = 4; };
F510167A1169855000DB137E /* Cruiser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Cruiser.h; sourceTree = "<group>"; };
F510167B1169855000DB137E /* Cruiser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Cruiser.m; sourceTree = "<group>"; };
F51019E5116A321300DB137E /* Carrier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Carrier.h; sourceTree = "<group>"; };
View
1  Kiwi/KWContextNode.h
@@ -56,6 +56,7 @@
@property (nonatomic, readwrite, retain) KWAfterAllNode *afterAllNode;
@property (nonatomic, readwrite, retain) KWBeforeEachNode *beforeEachNode;
@property (nonatomic, readwrite, retain) KWAfterEachNode *afterEachNode;
+@property (nonatomic, readonly) KWContextNode *parentContext;
@property (nonatomic, readonly) NSArray *nodes;
- (void)addContextNode:(KWContextNode *)aNode;
View
2  Kiwi/KWContextNode.m
@@ -11,6 +11,8 @@
@implementation KWContextNode
+@synthesize parentContext;
+
#pragma mark -
#pragma mark Initializing
View
69 Kiwi/KWExample.m
@@ -30,16 +30,16 @@ @interface KWExample ()
@property (nonatomic, readonly) NSMutableArray *verifiers;
@property (nonatomic, readonly) KWMatcherFactory *matcherFactory;
-@property (nonatomic, readonly) NSMutableArray *exampleNodeStack;
@property (nonatomic, assign) id<KWExampleDelegate> delegate;
+- (void)reportResultForExampleNodeWithLabel:(NSString *)label;
+
@end
@implementation KWExample
@synthesize matcherFactory;
@synthesize verifiers;
-@synthesize exampleNodeStack;
@synthesize delegate = _delegate;
@synthesize suite;
@synthesize lastInContext;
@@ -50,7 +50,6 @@ - (id)initWithExampleNode:(id<KWExampleNode>)node
exampleNode = [node retain];
matcherFactory = [[KWMatcherFactory alloc] init];
verifiers = [[NSMutableArray alloc] init];
- exampleNodeStack = [[NSMutableArray alloc] init];
passed = YES;
}
return self;
@@ -60,7 +59,6 @@ - (void)dealloc
{
[lastInContext release];
[exampleNode release];
- [exampleNodeStack release];
[matcherFactory release];
[verifiers release];
[super dealloc];
@@ -116,20 +114,15 @@ - (void)runWithDelegate:(id<KWExampleDelegate>)delegate;
#pragma mark - Reporting failure
- (NSString *)descriptionForExampleContext {
- NSMutableString *description = [NSMutableString string];
-
- for (id<KWExampleNode> node in self.exampleNodeStack) {
- NSString *nodeDescription = [node description];
-
- if (nodeDescription != nil)
- [description appendFormat:@"%@ ", nodeDescription];
+ NSMutableArray *parts = [NSMutableArray array];
+
+ for (KWContextNode *context in [[exampleNode contextStack] reverseObjectEnumerator]) {
+ if ([context description] != nil) {
+ [parts addObject:[context description]];
+ }
}
- // Remove trailing space
- if ([description length] > 0)
- [description deleteCharactersInRange:NSMakeRange([description length] - 1, 1)];
-
- return description;
+ return [parts componentsJoinedByString:@" "];
}
- (KWFailure *)outputReadyFailureWithFailure:(KWFailure *)aFailure {
@@ -154,6 +147,11 @@ - (void)reportFailure:(KWFailure *)failure
[self.delegate example:self didFailWithFailure:[self outputReadyFailureWithFailure:failure]];
}
+- (void)reportResultForExampleNodeWithLabel:(NSString *)label
+{
+ NSLog(@"+ '%@ %@' [%@]", [self descriptionForExampleContext], [exampleNode description], label);
+}
+
#pragma mark - Visiting Nodes
- (void)visitRegisterMatchersNode:(KWRegisterMatchersNode *)aNode {
@@ -197,32 +195,19 @@ - (void)visitItNode:(KWItNode *)aNode {
[aNode.context performExample:self withBlock:^{
@try {
- // Add it node to the stack
- [self.exampleNodeStack addObject:aNode];
- @try {
- aNode.block();
-
- #if KW_TARGET_HAS_INVOCATION_EXCEPTION_BUG
- NSException *invocationException = KWGetAndClearExceptionFromAcrossInvocationBoundary();
- [invocationException raise];
- #endif // #if KW_TARGET_HAS_INVOCATION_EXCEPTION_BUG
-
- // Finish verifying and clear
- for (id<KWVerifying> verifier in self.verifiers) {
- [verifier exampleWillEnd];
- }
-
- } @catch (NSException *exception) {
- KWFailure *failure = [KWFailure failureWithCallSite:aNode.callSite format:@"%@ \"%@\" raised",
- [exception name],
- [exception reason]];
- [self reportFailure:failure];
+ aNode.block();
+
+#if KW_TARGET_HAS_INVOCATION_EXCEPTION_BUG
+ NSException *invocationException = KWGetAndClearExceptionFromAcrossInvocationBoundary();
+ [invocationException raise];
+#endif // #if KW_TARGET_HAS_INVOCATION_EXCEPTION_BUG
+
+ // Finish verifying and clear
+ for (id<KWVerifying> verifier in self.verifiers) {
+ [verifier exampleWillEnd];
}
-
- // Remove it node from the stack
- [self.exampleNodeStack removeLastObject];
-
+
} @catch (NSException *exception) {
KWFailure *failure = [KWFailure failureWithCallSite:aNode.callSite format:@"%@ \"%@\" raised",
[exception name],
@@ -231,7 +216,7 @@ - (void)visitItNode:(KWItNode *)aNode {
}
if (passed) {
- NSLog(@"+ '%@ %@' [PASSED]", [self descriptionForExampleContext], [exampleNode description]);
+ [self reportResultForExampleNodeWithLabel:@"PASSED"];
}
// Always clear stubs and spies at the end of it blocks
@@ -244,7 +229,7 @@ - (void)visitPendingNode:(KWPendingNode *)aNode {
if (aNode != exampleNode)
return;
- NSLog(@"+ '%@' [PENDING]", [self descriptionForExampleContext]);
+ [self reportResultForExampleNodeWithLabel:@"PENDING"];
}
- (NSString *)generateDescriptionForAnonymousItNode
View
2  Kiwi/KWExampleGroupBuilder.m
@@ -189,7 +189,7 @@ - (void)addPendingNodeWithCallSite:(KWCallSite *)aCallSite description:(NSString
[NSException raise:@"KWExampleGroupBuilderException" format:@"an example group has not been started"];
KWContextNode *contextNode = [self.contextNodeStack lastObject];
- KWPendingNode *pendingNode = [KWPendingNode pendingNodeWithCallSite:aCallSite description:aDescription];
+ KWPendingNode *pendingNode = [KWPendingNode pendingNodeWithCallSite:aCallSite context:contextNode description:aDescription];
[contextNode addPendingNode:pendingNode];
KWExample *example = [[KWExample alloc] initWithExampleNode:pendingNode];
View
5 Kiwi/KWExampleNode.h
@@ -6,6 +6,7 @@
#import "KiwiConfiguration.h"
+@class KWContextNode;
@protocol KWExampleNodeVisitor;
@protocol KWExampleNode<NSObject>
@@ -15,4 +16,8 @@
- (void)acceptExampleNodeVisitor:(id<KWExampleNodeVisitor>)aVisitor;
+@optional
+
+- (NSArray *)contextStack;
+
@end
View
4 Kiwi/KWItNode.h
@@ -12,9 +12,7 @@
@class KWExample;
@class KWContextNode;
-@interface KWItNode : KWBlockNode<KWExampleNode> {
- KWContextNode *context;
-}
+@interface KWItNode : KWBlockNode<KWExampleNode>
@property (nonatomic, assign) KWExample *example;
@property (nonatomic, retain, readonly) KWContextNode *context;
View
19 Kiwi/KWItNode.m
@@ -8,6 +8,7 @@
#import "KWExampleNodeVisitor.h"
#import "KWExample.h"
#import "KWVerifying.h"
+#import "KWContextNode.h"
@interface KWItNode ()
@@ -17,7 +18,7 @@ @interface KWItNode ()
@implementation KWItNode
-@synthesize context;
+@synthesize context = _context;
@synthesize example;
#pragma mark -
@@ -52,4 +53,20 @@ - (NSString *)description
return description;
}
+#pragma mark -
+#pragma mark - Accessing the context stack
+
+- (NSArray *)contextStack
+{
+ NSMutableArray *contextStack = [NSMutableArray array];
+
+ KWContextNode *currentContext = _context;
+
+ while (currentContext) {
+ [contextStack addObject:currentContext];
+ currentContext = currentContext.parentContext;
+ }
+ return contextStack;
+}
+
@end
View
6 Kiwi/KWPendingNode.h
@@ -7,6 +7,7 @@
#import "KiwiConfiguration.h"
#import "KWExampleNode.h"
+@class KWContextNode;
@class KWCallSite;
@interface KWPendingNode : NSObject<KWExampleNode> {
@@ -14,13 +15,14 @@
KWCallSite *callSite;
NSString *description;
}
+@property (nonatomic, readonly, retain) KWContextNode *context;
#pragma mark -
#pragma mark Initializing
-- (id)initWithCallSite:(KWCallSite *)aCallSite description:(NSString *)aDescription;
+- (id)initWithCallSite:(KWCallSite *)aCallSite context:(KWContextNode *)context description:(NSString *)aDescription;
-+ (id)pendingNodeWithCallSite:(KWCallSite *)aCallSite description:(NSString *)aDescription;
++ (id)pendingNodeWithCallSite:(KWCallSite *)aCallSite context:(KWContextNode *)context description:(NSString *)aDescription;
#pragma mark -
#pragma mark Getting Call Sites
View
27 Kiwi/KWPendingNode.m
@@ -6,26 +6,31 @@
#import "KWPendingNode.h"
#import "KWExampleNodeVisitor.h"
+#import "KWContextNode.h"
@implementation KWPendingNode
+@synthesize context = _context;
+
#pragma mark -
#pragma mark Initializing
-- (id)initWithCallSite:(KWCallSite *)aCallSite description:(NSString *)aDescription {
+- (id)initWithCallSite:(KWCallSite *)aCallSite context:(KWContextNode *)context description:(NSString *)aDescription {
if ((self = [super init])) {
callSite = [aCallSite retain];
description = [aDescription copy];
+ _context = [context retain];
}
return self;
}
-+ (id)pendingNodeWithCallSite:(KWCallSite *)aCallSite description:(NSString *)aDescription {
- return [[[self alloc] initWithCallSite:aCallSite description:aDescription] autorelease];
++ (id)pendingNodeWithCallSite:(KWCallSite *)aCallSite context:(KWContextNode *)context description:(NSString *)aDescription {
+ return [[[self alloc] initWithCallSite:aCallSite context:context description:aDescription] autorelease];
}
- (void)dealloc {
+ [_context release];
[callSite release];
[description release];
[super dealloc];
@@ -48,4 +53,20 @@ - (void)acceptExampleNodeVisitor:(id<KWExampleNodeVisitor>)aVisitor {
[aVisitor visitPendingNode:self];
}
+#pragma mark -
+#pragma mark - Accessing the context stack
+
+- (NSArray *)contextStack
+{
+ NSMutableArray *contextStack = [NSMutableArray array];
+
+ KWContextNode *currentContext = _context;
+
+ while (currentContext) {
+ [contextStack addObject:currentContext];
+ currentContext = currentContext.parentContext;
+ }
+ return contextStack;
+}
+
@end
Please sign in to comment.
Something went wrong with that request. Please try again.