Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit a24a1fd3f4710ff9e66beef19d5b528100031fcc @petejkim petejkim committed Jan 7, 2012
Showing with 2,323 additions and 0 deletions.
  1. +8 −0 .gitignore
  2. +20 −0 LICENSE
  3. +10 −0 README.md
  4. +573 −0 Specta.xcodeproj/project.pbxproj
  5. +15 −0 src/SPTExample.h
  6. +26 −0 src/SPTExample.m
  7. +40 −0 src/SPTExampleGroup.h
  8. +214 −0 src/SPTExampleGroup.m
  9. +2 −0 src/SPTSupport.h
  10. +13 −0 src/SPTTestCase.h
  11. +47 −0 src/SPTTestCase.m
  12. +3 −0 src/Specta-Prefix.pch
  13. +42 −0 src/Specta.h
  14. +5 −0 src/Specta.m
  15. +28 −0 test/CompilationTest1.m
  16. +48 −0 test/CompilationTest2.m
  17. +52 −0 test/CompilationTest3.m
  18. +53 −0 test/CompilationTest4.m
  19. +67 −0 test/CompilationTest5.m
  20. +67 −0 test/CompilationTest6.m
  21. +67 −0 test/CompilationTest7.m
  22. +30 −0 test/DSLTest1.m
  23. +56 −0 test/DSLTest2.m
  24. +51 −0 test/DSLTest3.m
  25. +50 −0 test/DSLTest4.m
  26. +58 −0 test/DSLTest5.m
  27. +71 −0 test/ReRunTest.m
  28. +160 −0 test/SequenceTest.m
  29. +7 −0 test/helpers/TestHelper.h
  30. +22 −0 test/support/Test-Info.plist
  31. +45 −0 test/vendor/expecta/EXPExpect.h
  32. +4 −0 test/vendor/expecta/EXPMatcherHelpers.h
  33. +3 −0 test/vendor/expecta/EXPMatchers+toBeFalsy.h
  34. +6 −0 test/vendor/expecta/EXPMatchers+toBeGreaterThan.h
  35. +6 −0 test/vendor/expecta/EXPMatchers+toBeGreaterThanOrEqualTo.h
  36. +3 −0 test/vendor/expecta/EXPMatchers+toBeIdenticalTo.h
  37. +6 −0 test/vendor/expecta/EXPMatchers+toBeInTheRangeOf.h
  38. +7 −0 test/vendor/expecta/EXPMatchers+toBeInstanceOf.h
  39. +5 −0 test/vendor/expecta/EXPMatchers+toBeKindOf.h
  40. +6 −0 test/vendor/expecta/EXPMatchers+toBeLessThan.h
  41. +6 −0 test/vendor/expecta/EXPMatchers+toBeLessThanOrEqualTo.h
  42. +5 −0 test/vendor/expecta/EXPMatchers+toBeNil.h
  43. +5 −0 test/vendor/expecta/EXPMatchers+toBeSubclassOf.h
  44. +3 −0 test/vendor/expecta/EXPMatchers+toBeTruthy.h
  45. +5 −0 test/vendor/expecta/EXPMatchers+toContain.h
  46. +5 −0 test/vendor/expecta/EXPMatchers+toEqual.h
  47. +14 −0 test/vendor/expecta/EXPMatchers.h
  48. +11 −0 test/vendor/expecta/EXPUnsupportedObject.h
  49. +23 −0 test/vendor/expecta/Expecta.h
  50. +46 −0 test/vendor/expecta/ExpectaSupport.h
  51. +19 −0 test/vendor/expecta/LICENSE
  52. +5 −0 test/vendor/expecta/NSObject+Expecta.h
  53. +8 −0 test/vendor/expecta/NSValue+Expecta.h
  54. +172 −0 test/vendor/expecta/README.md
  55. BIN test/vendor/expecta/libExpecta-ios-universal.a
  56. BIN test/vendor/expecta/libExpecta-macosx.a
@@ -0,0 +1,8 @@
+.DS_Store
+*.xcworkspace
+xcuserdata
+.idea
+build/
+*.pbxuser
+*.mode1v3
+
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2011 Peter Jihoon Kim
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
@@ -0,0 +1,10 @@
+# Specta
+
+A light-weight TDD / BDD framework for Objective-C & Cocoa.
+
+## WIP
+
+## LICENSE
+
+Copyright (c) 2011 Peter Jihoon Kim. This software is licensed under the [MIT License](http://github.com/petejkim/specta/raw/master/LICENSE).
+

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,15 @@
+#import <Foundation/Foundation.h>
+#import "SPTSupport.h"
+
+@interface SPTExample : NSObject {
+ NSString *_name;
+ SPTVoidBlock _block;
+}
+
+@property (nonatomic, copy) NSString *name;
+@property (nonatomic, copy) SPTVoidBlock block;
+
+- (id)initWithName:(NSString *)name block:(SPTVoidBlock)block;
+
+@end
+
@@ -0,0 +1,26 @@
+#import "SPTExample.h"
+
+@implementation SPTExample
+
+@synthesize
+ name=_name
+, block=_block
+;
+
+- (void)dealloc {
+ self.name = nil;
+ self.block = nil;
+ [super dealloc];
+}
+
+- (id)initWithName:(NSString *)name block:(SPTVoidBlock)block {
+ self = [super init];
+ if(self) {
+ self.name = name;
+ self.block = block;
+ }
+ return self;
+}
+
+@end
+
@@ -0,0 +1,40 @@
+#import <Foundation/Foundation.h>
+#import "SPTSupport.h"
+
+@class SPTExample;
+
+@interface SPTExampleGroup : NSObject {
+ NSString *_name;
+ SPTExampleGroup *_root;
+ SPTExampleGroup *_parent;
+ NSMutableArray *_children;
+ NSMutableArray *_beforeAllBlock;
+ NSMutableArray *_afterAllBlock;
+ NSMutableArray *_beforeEachBlock;
+ NSMutableArray *_afterEachBlock;
+ unsigned int _exampleCount;
+ unsigned int _ranExampleCount;
+}
+
+@property (nonatomic, copy) NSString *name;
+@property (nonatomic, assign) SPTExampleGroup *root;
+@property (nonatomic, assign) SPTExampleGroup *parent;
+@property (nonatomic, retain) NSMutableArray *children;
+@property (nonatomic, retain) NSMutableArray *beforeAllArray;
+@property (nonatomic, retain) NSMutableArray *afterAllArray;
+@property (nonatomic, retain) NSMutableArray *beforeEachArray;
+@property (nonatomic, retain) NSMutableArray *afterEachArray;
+@property (nonatomic) unsigned int exampleCount;
+@property (nonatomic) unsigned int ranExampleCount;
+
+- (id)initWithName:(NSString *)name parent:(SPTExampleGroup *)parent root:(SPTExampleGroup *)root;
+- (SPTExampleGroup *)addExampleGroupWithName:(NSString *)name;
+- (SPTExample *)addExampleWithName:(NSString *)name block:(SPTVoidBlock)block;
+- (void)addBeforeAllBlock:(SPTVoidBlock)block;
+- (void)addAfterAllBlock:(SPTVoidBlock)block;
+- (void)addBeforeEachBlock:(SPTVoidBlock)block;
+- (void)addAfterEachBlock:(SPTVoidBlock)block;
+- (unsigned int)compileExamples:(Class)testClass index:(unsigned int)index;
+
+@end
+
@@ -0,0 +1,214 @@
+#import "SPTExampleGroup.h"
+#import "SPTExample.h"
+#import "SPTTestCase.h"
+#import <objc/runtime.h>
+
+@interface SPTExampleGroup ()
+
+- (void)incrementExampleCount;
+- (void)resetRanExampleCountIfNeeded;
+- (void)incrementRanExampleCount;
+- (void)runBeforeHooks;
+- (void)runAfterHooks;
+
+@end
+
+unsigned int SPT_digits(unsigned int number);
+
+@implementation SPTExampleGroup
+
+@synthesize
+ name=_name
+, root=_root
+, parent=_parent
+, children=_children
+, beforeAllArray=_beforeAllArray
+, afterAllArray=_afterAllArray
+, beforeEachArray=_beforeEachArray
+, afterEachArray=_afterEachArray
+, exampleCount=_exampleCount
+, ranExampleCount=_ranExampleCount
+;
+
+- (void)dealloc {
+ self.name = nil;
+ self.root = nil;
+ self.parent = nil;
+ self.children = nil;
+ self.beforeAllArray = nil;
+ self.afterAllArray = nil;
+ self.beforeEachArray = nil;
+ self.afterEachArray = nil;
+ [super dealloc];
+}
+
+- (id)init {
+ self = [super init];
+ if(self) {
+ self.name = nil;
+ self.root = nil;
+ self.parent = nil;
+ self.children = [NSMutableArray array];
+ self.beforeAllArray = [NSMutableArray array];
+ self.afterAllArray = [NSMutableArray array];
+ self.beforeEachArray = [NSMutableArray array];
+ self.afterEachArray = [NSMutableArray array];
+ self.exampleCount = 0;
+ self.ranExampleCount = 0;
+ }
+ return self;
+}
+
+- (id)initWithName:(NSString *)name parent:(SPTExampleGroup *)parent root:(SPTExampleGroup *)root {
+ self = [self init];
+ if(self) {
+ self.name = name;
+ self.parent = parent;
+ self.root = root;
+ }
+ return self;
+}
+
+- (SPTExampleGroup *)addExampleGroupWithName:(NSString *)name {
+ SPTExampleGroup *group = [[SPTExampleGroup alloc] initWithName:name parent:self root:self.root];
+ [self.children addObject:group];
+ return [group autorelease];
+}
+
+- (SPTExample *)addExampleWithName:(NSString *)name block:(SPTVoidBlock)block {
+ SPTExample *example;
+ @synchronized(self) {
+ example = [[SPTExample alloc] initWithName:name block:block];
+ [self.children addObject:example];
+ [self incrementExampleCount];
+ }
+ return [example autorelease];
+}
+
+- (void)incrementExampleCount {
+ SPTExampleGroup *group = self;
+ while(group != nil) {
+ group.exampleCount ++;
+ group = group.parent;
+ }
+}
+
+- (void)resetRanExampleCountIfNeeded {
+ SPTExampleGroup *group = self;
+ while(group != nil) {
+ if(group.ranExampleCount >= group.exampleCount) {
+ group.ranExampleCount = 0;
+ }
+ group = group.parent;
+ }
+}
+
+- (void)incrementRanExampleCount {
+ SPTExampleGroup *group = self;
+ while(group != nil) {
+ group.ranExampleCount ++;
+ group = group.parent;
+ }
+}
+
+- (void)addBeforeAllBlock:(SPTVoidBlock)block {
+ [self.beforeAllArray addObject:[[block copy] autorelease]];
+}
+
+- (void)addAfterAllBlock:(SPTVoidBlock)block {
+ [self.afterAllArray addObject:[[block copy] autorelease]];
+}
+
+- (void)addBeforeEachBlock:(SPTVoidBlock)block {
+ [self.beforeEachArray addObject:[[block copy] autorelease]];
+}
+
+- (void)addAfterEachBlock:(SPTVoidBlock)block {
+ [self.afterEachArray addObject:[[block copy] autorelease]];
+}
+
+- (void)runBeforeHooks {
+ NSMutableArray *groups = [NSMutableArray array];
+ SPTExampleGroup *group = self;
+ while(group != nil) {
+ [groups insertObject:group atIndex:0];
+ group = group.parent;
+ }
+ // run beforeAll hooks
+ for(group in groups) {
+ if(group.ranExampleCount == 0) {
+ for(SPTVoidBlock beforeAllBlock in group.beforeAllArray) {
+ beforeAllBlock();
+ }
+ }
+ }
+ // run beforeEach hooks
+ for(group in groups) {
+ for(SPTVoidBlock beforeEachBlock in group.beforeEachArray) {
+ beforeEachBlock();
+ }
+ }
+}
+
+- (void)runAfterHooks {
+ NSMutableArray *groups = [NSMutableArray array];
+ SPTExampleGroup *group = self;
+ while(group != nil) {
+ [groups addObject:group];
+ group = group.parent;
+ }
+ // run afterEach hooks
+ for(group in groups) {
+ for(SPTVoidBlock afterEachBlock in group.afterEachArray) {
+ afterEachBlock();
+ }
+ }
+ // run afterAll hooks
+ for(group in groups) {
+ if(group.ranExampleCount == group.exampleCount) {
+ for(SPTVoidBlock afterAllBlock in group.afterAllArray) {
+ afterAllBlock();
+ }
+ }
+ }
+}
+
+- (unsigned int)compileExamples:(Class)testClass index:(unsigned int)index {
+ for(id child in self.children) {
+ if([child isKindOfClass:[SPTExampleGroup class]]) {
+ SPTExampleGroup *group = child;
+ index = [group compileExamples:testClass index:index];
+ } else if([child isKindOfClass:[SPTExample class]]) {
+ index ++;
+ SPTExample *example = child;
+ IMP imp = imp_implementationWithBlock(^{
+ @synchronized(self.root) {
+ [self resetRanExampleCountIfNeeded];
+ [self runBeforeHooks];
+ }
+ example.block();
+ @synchronized(self.root) {
+ [self incrementRanExampleCount];
+ [self runAfterHooks];
+ }
+ });
+ NSString *format = [NSString stringWithFormat:@"%@%d%@", @"test%0", SPT_digits([self.root exampleCount]), @"u"];
+ SEL sel = NSSelectorFromString([NSString stringWithFormat:format, index]);
+ class_addMethod(testClass, sel, imp, "v@:");
+ }
+ }
+ return index;
+}
+
+@end
+
+unsigned int SPT_digits(unsigned int number) {
+ unsigned int digits = 0;
+ int i = 1;
+ do {
+ digits ++;
+ i *= 10;
+ } while(i <= number);
+ return digits;
+}
+
@@ -0,0 +1,2 @@
+typedef void (^SPTVoidBlock)();
+
@@ -0,0 +1,13 @@
+#import <SenTestingKit/SenTestingKit.h>
+
+@class SPTExampleGroup;
+
+@interface SPTTestCase : SenTestCase
+
+- (void)defineSpec;
++ (SPTExampleGroup *)rootGroup;
++ (NSMutableArray *)groupStack;
++ (SPTExampleGroup *)currentGroup;
+
+@end
+
Oops, something went wrong.

0 comments on commit a24a1fd

Please sign in to comment.