Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cheyueyong committed Feb 8, 2017
1 parent 9429e0a commit 62217c7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Classes/Core/KWSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ @interface KWSpec()

@end

NSMutableDictionary *kw_examples;

@implementation KWSpec

/* Methods are only implemented by sub-classes */
Expand All @@ -31,6 +33,12 @@ - (NSString *)name {
return [self description];
}

+ (void)initialize {
kw_examples = [NSMutableDictionary new];
[self testInvocations];
}


/* Use camel case to make method friendly names from example description. */

- (NSString *)description {
Expand Down Expand Up @@ -58,6 +66,7 @@ + (NSArray *)testInvocations {
for (KWExample *example in exampleSuite) {
SEL selector = [self addInstanceMethodForExample:example];
NSInvocation *invocation = [self invocationForExample:example selector:selector];
[kw_examples setObject:example forKey:NSStringFromSelector(invocation.selector)];
[invocations addObject:invocation];
}

Expand Down Expand Up @@ -114,7 +123,9 @@ + (BOOL)respondsToSelector:(SEL)aSelector {

- (void)runExample {
self.currentExample = self.invocation.kw_example;

if (self.currentExample == nil) {
self.currentExample = [kw_examples objectForKey:NSStringFromSelector(self.invocation.selector)];
}
@try {
[self.currentExample runWithDelegate:self];
} @catch (NSException *exception) {
Expand Down

0 comments on commit 62217c7

Please sign in to comment.