Skip to content

Commit

Permalink
Exit the app after running the specs, with an exit code representing …
Browse files Browse the repository at this point in the history
…the amount of failures.

This is handy when running the specs from the terminal with, for instance, Kicker.
  • Loading branch information
alloy committed Jul 14, 2010
1 parent f21a921 commit c40f952
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Binary file modified bin/UISpec/UISpec_1_0.a
Binary file not shown.
14 changes: 12 additions & 2 deletions src/UISpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,31 @@ +(void)runSpecExample:(NSTimer *)timer {
}

+(void)runSpecClasses:(NSArray *)specClasses {
int failures = 0;
if (specClasses.count == 0) return;
int examplesCount = 0;
[logger onStart];
for (Class *class in specClasses) {
NSArray *examples = [self examplesForSpecClass:class];
if (examples.count == 0) continue;
examplesCount = examplesCount + examples.count;
[self runExamples:examples onSpec:class];
failures += [self runExamples:examples onSpec:class];
}
[logger onFinish:examplesCount];
// TODO: clean this up as a nice patch
exit(failures);
}

+(void)runExamples:(NSArray *)examples onSpec:(Class *)class {
+(int)runExamples:(NSArray *)examples onSpec:(Class *)class {
int failures = 0;
UISpec *spec = [[[class alloc] init] autorelease];
[logger onSpec:spec];
if ([spec respondsToSelector:@selector(beforeAll)]) {
@try {
[logger onBeforeAll];
[spec beforeAll];
} @catch (NSException *exception) {
failures += 1;
[logger onBeforeAllException:exception];
}
}
Expand All @@ -75,20 +80,23 @@ +(void)runExamples:(NSArray *)examples onSpec:(Class *)class {
[logger onBefore:exampleName];
[spec before];
} @catch (NSException *exception) {
failures += 1;
[logger onBeforeException:exception];
}
}
@try {
[logger onExample:exampleName];
[spec performSelector:NSSelectorFromString(exampleName)];
} @catch (NSException *exception) {
failures += 1;
[logger onExampleException:exception];
}
if ([spec respondsToSelector:@selector(after)]) {
@try {
[logger onAfter:exampleName];
[spec after];
} @catch (NSException *exception) {
failures += 1;
[logger onAfterException:exception];
}
}
Expand All @@ -98,10 +106,12 @@ +(void)runExamples:(NSArray *)examples onSpec:(Class *)class {
[logger onAfterAll];
[spec afterAll];
} @catch (NSException *exception) {
failures += 1;
[logger onAfterAllException:exception];
}
}
[logger afterSpec:spec];
return failures;
}

+(NSDictionary *)specsAndExamples {
Expand Down

0 comments on commit c40f952

Please sign in to comment.