main
1//
2// Licensed under the terms in License.txt
3//
4// Copyright 2010 Allen Ding. All rights reserved.
5//
6
7#import "KWItNode.h"
8#import "KWExampleNodeVisitor.h"
9#import "KWExample.h"
10#import "KWVerifying.h"
11#import "KWContextNode.h"
12
13@interface KWItNode ()
14
15@property (nonatomic, retain, readwrite) KWContextNode *context;
16
17@end
18
19@implementation KWItNode
20
21@synthesize context = _context;
22@synthesize example;
23
24#pragma mark -
25#pragma mark Initializing
26
27+ (id)itNodeWithCallSite:(KWCallSite *)aCallSite
28 description:(NSString *)aDescription
29 context:(KWContextNode *)context
30 block:(KWVoidBlock)aBlock;
31{
32 KWItNode *itNode = [[self alloc] initWithCallSite:aCallSite description:aDescription block:aBlock];
33 itNode.context = context;
34 return [itNode autorelease];
35}
36
37#pragma mark -
38#pragma mark Accepting Visitors
39
40- (void)acceptExampleNodeVisitor:(id<KWExampleNodeVisitor>)aVisitor {
41 [aVisitor visitItNode:self];
42}
43
44#pragma mark -
45#pragma mark Runtime Description support
46
47- (NSString *)description
48{
49 NSString *description = [super description];
50 if (description == nil) {
51 description = [self.example generateDescriptionForAnonymousItNode];
52 }
53 return description;
54}
55
56#pragma mark -
57#pragma mark - Accessing the context stack
58
59- (NSArray *)contextStack
60{
61 NSMutableArray *contextStack = [NSMutableArray array];
62
63 KWContextNode *currentContext = _context;
64
65 while (currentContext) {
66 [contextStack addObject:currentContext];
67 currentContext = currentContext.parentContext;
68 }
69 return contextStack;
70}
71
72@end