Skip to content

Commit

Permalink
XCode now reports full example description, show warnings for pending…
Browse files Browse the repository at this point in the history
… examples as not finished
  • Loading branch information
paulz committed Mar 6, 2012
1 parent d5035a3 commit 2945214
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Kiwi/KWExample.h
Expand Up @@ -49,6 +49,11 @@

- (BOOL)isLastInContext:(KWContextNode *)context;

#pragma mark -
#pragma mark Full description with context

- (NSString *)descriptionWithContext;

@end

#pragma mark -
Expand Down
21 changes: 21 additions & 0 deletions Kiwi/KWExample.m
Expand Up @@ -31,6 +31,7 @@ @interface KWExample ()
@property (nonatomic, readonly) NSMutableArray *verifiers;
@property (nonatomic, readonly) KWMatcherFactory *matcherFactory;
@property (nonatomic, assign) id<KWExampleDelegate> delegate;
@property (nonatomic, assign) BOOL didNotFinish;

- (void)reportResultForExampleNodeWithLabel:(NSString *)label;

Expand All @@ -43,6 +44,7 @@ @implementation KWExample
@synthesize delegate = _delegate;
@synthesize suite;
@synthesize lastInContext;
@synthesize didNotFinish;

- (id)initWithExampleNode:(id<KWExampleNode>)node
{
Expand Down Expand Up @@ -152,6 +154,25 @@ - (void)reportResultForExampleNodeWithLabel:(NSString *)label
NSLog(@"+ '%@ %@' [%@]", [self descriptionForExampleContext], [exampleNode description], label);
}

#pragma mark - Full description with context

/** Pending cases will be marked yellow by XCode as not finished, because their description differs for -[SenTestCaseRun start] and -[SenTestCaseRun stop] methods
*/

- (NSString *)pendingNotFinished {
BOOL reportPending = self.didNotFinish;
self.didNotFinish = YES;
return reportPending ? @"(PENDING)" : @"";
}

- (NSString *)descriptionWithContext {
NSString *descriptionWithContext = [NSString stringWithFormat:@"%@ %@",
[self descriptionForExampleContext],
[exampleNode description] ? [exampleNode description] : @""];
BOOL isPending = [exampleNode isKindOfClass:[KWPendingNode class]];
return isPending ? [descriptionWithContext stringByAppendingString:[self pendingNotFinished]] : descriptionWithContext;
}

#pragma mark - Visiting Nodes

- (void)visitRegisterMatchersNode:(KWRegisterMatchersNode *)aNode {
Expand Down
9 changes: 8 additions & 1 deletion Kiwi/KWSpec.m
Expand Up @@ -39,9 +39,16 @@ - (void)dealloc

+ (void)buildExampleGroups {}

/* Reported by XCode SenTestingKit Runner before and after invocation of the test
Use underscore _ to make method friendly names from example description
*/

- (NSString *)description
{
return [NSString stringWithFormat:@"-[%@ example]", NSStringFromClass([self class])];
KWExample *currentExample = self.example ? self.example : [[self invocation] kw_example];
NSString *name = [currentExample descriptionWithContext];
name = [name stringByReplacingOccurrencesOfString:@" " withString:@"_"];
return [NSString stringWithFormat:@"-[%@ %@]", NSStringFromClass([self class]), name];
}

#pragma mark -
Expand Down

0 comments on commit 2945214

Please sign in to comment.