This repository was archived by the owner on Dec 2, 2019. It is now read-only.
forked from specta/specta
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathSPTSharedExampleGroups.m
More file actions
64 lines (52 loc) · 2.03 KB
/
SPTSharedExampleGroups.m
File metadata and controls
64 lines (52 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#import "SPTSharedExampleGroups.h"
#import "SPTExampleGroup.h"
#import "SPTSenTestCase.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 {}
+ (void)failWithException:(NSException *)exception {
SPTSenTestCase *currentTestCase = [[[NSThread currentThread] threadDictionary] objectForKey:@"SPT_currentTestCase"];
[currentTestCase failWithException: exception];
}
@end