diff --git a/Classes/Core/KWSpec.m b/Classes/Core/KWSpec.m index 3e845170..9e92cfcf 100644 --- a/Classes/Core/KWSpec.m +++ b/Classes/Core/KWSpec.m @@ -19,6 +19,8 @@ @interface KWSpec() @end +NSMutableDictionary *kw_examples; + @implementation KWSpec /* Methods are only implemented by sub-classes */ @@ -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 { @@ -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]; } @@ -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) {