Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
358 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,15 @@ | |||
#import <Foundation/Foundation.h> | |||
#import "SpectaTypes.h" | |||
|
|||
@class | |||
SPTExampleGroup | |||
; | |||
|
|||
@interface SPTSharedExampleGroups : NSObject | |||
|
|||
+ (void)addSharedExampleGroupWithName:(NSString *)name block:(SPTDictionaryBlock)block exampleGroup:(SPTExampleGroup *)exampleGroup; | |||
+ (SPTDictionaryBlock)sharedExampleGroupWithName:(NSString *)name exampleGroup:(SPTExampleGroup *)exampleGroup; | |||
+ (void)defineSharedExampleGroups; | |||
|
|||
@end | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,58 @@ | |||
#import "SPTSharedExampleGroups.h" | |||
#import "SPTExampleGroup.h" | |||
#import <objc/runtime.h> | |||
|
|||
NSMutableDictionary *globalSharedExampleGroups = nil; | |||
BOOL initialized = NO; | |||
|
|||
@implementation SPTSharedExampleGroups | |||
|
|||
+ (void)initialize { | |||
@synchronized(self) { | |||
Class SPTSharedExampleGroupsClass = [SPTSharedExampleGroups class]; | |||
if([self class] == SPTSharedExampleGroupsClass) { | |||
if(!initialized) { | |||
initialized = YES; | |||
globalSharedExampleGroups = [[NSMutableDictionary alloc] init]; | |||
|
|||
Class *classes = NULL; | |||
int numClasses = objc_getClassList(NULL, 0); | |||
|
|||
if(numClasses > 0) { | |||
classes = malloc(sizeof(Class) * numClasses); | |||
numClasses = objc_getClassList(classes, numClasses); | |||
|
|||
Class klass, superClass; | |||
for(uint i = 0; i < numClasses; i++) { | |||
klass = classes[i]; | |||
superClass = class_getSuperclass(klass); | |||
if(superClass == SPTSharedExampleGroupsClass) { | |||
[klass defineSharedExampleGroups]; | |||
} | |||
} | |||
|
|||
free(classes); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
|
|||
+ (void)addSharedExampleGroupWithName:(NSString *)name block:(SPTDictionaryBlock)block exampleGroup:(SPTExampleGroup *)exampleGroup { | |||
[(exampleGroup == nil ? globalSharedExampleGroups : exampleGroup.sharedExamples) setObject:[[block copy] autorelease] forKey:name]; | |||
} | |||
|
|||
+ (SPTDictionaryBlock)sharedExampleGroupWithName:(NSString *)name exampleGroup:(SPTExampleGroup *)exampleGroup { | |||
SPTDictionaryBlock sharedExampleGroup = nil; | |||
while(exampleGroup != nil) { | |||
if((sharedExampleGroup = [exampleGroup.sharedExamples objectForKey:name])) { | |||
return sharedExampleGroup; | |||
} | |||
exampleGroup = exampleGroup.parent; | |||
} | |||
return [globalSharedExampleGroups objectForKey:name]; | |||
} | |||
|
|||
+ (void)defineSharedExampleGroups {} | |||
|
|||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1 +1,2 @@ | |||
typedef void (^SPTVoidBlock)(); | typedef void (^SPTVoidBlock)(); | ||
typedef void (^SPTDictionaryBlock)(); |
Oops, something went wrong.