Permalink
Browse files

Pending specs

  • Loading branch information...
petejkim committed Feb 6, 2012
1 parent 742fe92 commit d4c0b6a2f1f5c98c496b6a5fec8016cd95b66976
Showing with 127 additions and 10 deletions.
  1. +7 −1 README.md
  2. +16 −3 Specta.xcodeproj/project.pbxproj
  3. +2 −0 src/SPTExample.h
  4. +2 −0 src/SPTExample.m
  5. +9 −1 src/SPTExampleGroup.m
  6. +4 −2 src/SPTSenTestCase.m
  7. +8 −0 src/Specta.h
  8. +11 −3 src/Specta.m
  9. +31 −0 test/PendingSpecTest1.m
  10. +37 −0 test/PendingSpecTest2.m
View
@@ -71,6 +71,12 @@ describe(@"Thing", ^{
});
});
+ pending(@"pending example");
+
+ pending(@"another pending example", ^{
+ // ...
+ });
+
afterEach(^{
// This is run after each example.
});
@@ -87,11 +93,11 @@ SpecEnd
* `beforeEach` and `afterEach` are also aliased as `before` and `after` respectively.
* `describe` is also aliased as `context`.
* `it` is also aliased as `example` and `specify`.
+* Use `pending` or prepend `x` to `describe`, `context`, `example, `it`, and `specify` to mark examples or groups as pending.
* Do `#define SPT_CEDAR_SYNTAX` if you prefer to write `SPEC_BEGIN` and `SPEC_END` instead of `SpecBegin` and `SpecEnd`.
### FEATURES COMING SOON
-* Pending Specs
* Shared Examples
### CONTRIBUTION GUIDELINES
@@ -9,8 +9,8 @@
/* Begin PBXBuildFile section */
E910177314B911340087CD46 /* PassingSpecTest.m in Sources */ = {isa = PBXBuildFile; fileRef = E910177214B911340087CD46 /* PassingSpecTest.m */; };
E910177514B9114A0087CD46 /* FailingSpecTest.m in Sources */ = {isa = PBXBuildFile; fileRef = E910177414B9114A0087CD46 /* FailingSpecTest.m */; };
- E944CA2914C4B5E300821DED /* SPTSenTestInvocation.h in Headers */ = {isa = PBXBuildFile; fileRef = E944CA2814C4B5E300821DED /* SPTSenTestInvocation.h */; };
- E944CA2A14C4B5E300821DED /* SPTSenTestInvocation.h in Headers */ = {isa = PBXBuildFile; fileRef = E944CA2814C4B5E300821DED /* SPTSenTestInvocation.h */; };
+ E944CA2914C4B5E300821DED /* SPTSenTestInvocation.h in Headers */ = {isa = PBXBuildFile; fileRef = E944CA2814C4B5E300821DED /* SPTSenTestInvocation.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ E944CA2A14C4B5E300821DED /* SPTSenTestInvocation.h in Headers */ = {isa = PBXBuildFile; fileRef = E944CA2814C4B5E300821DED /* SPTSenTestInvocation.h */; settings = {ATTRIBUTES = (Public, ); }; };
E944CA2C14C4B5F600821DED /* SPTSenTestInvocation.m in Sources */ = {isa = PBXBuildFile; fileRef = E944CA2B14C4B5F600821DED /* SPTSenTestInvocation.m */; };
E944CA2D14C4B5F600821DED /* SPTSenTestInvocation.m in Sources */ = {isa = PBXBuildFile; fileRef = E944CA2B14C4B5F600821DED /* SPTSenTestInvocation.m */; };
E944CA2F14C4B70000821DED /* SpectaTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = E944CA2E14C4B70000821DED /* SpectaTypes.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -38,6 +38,10 @@
E96187C714C4AFA70021D7CE /* MiscTest.m in Sources */ = {isa = PBXBuildFile; fileRef = E9BDBAB814BE2F3A00102FB5 /* MiscTest.m */; };
E96187C814C4AFBD0021D7CE /* libExpecta-ios-universal.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E9D9424214B8B43200CD833A /* libExpecta-ios-universal.a */; };
E96598D914C345F3003BC25B /* CompilationTest8.m in Sources */ = {isa = PBXBuildFile; fileRef = E96598D814C345F3003BC25B /* CompilationTest8.m */; };
+ E9A204C914C79F81006E4A66 /* PendingSpecTest1.m in Sources */ = {isa = PBXBuildFile; fileRef = E9A204C814C79F81006E4A66 /* PendingSpecTest1.m */; };
+ E9A204CA14C79F81006E4A66 /* PendingSpecTest1.m in Sources */ = {isa = PBXBuildFile; fileRef = E9A204C814C79F81006E4A66 /* PendingSpecTest1.m */; };
+ E9A204CD14C7A487006E4A66 /* PendingSpecTest2.m in Sources */ = {isa = PBXBuildFile; fileRef = E9A204CC14C7A487006E4A66 /* PendingSpecTest2.m */; };
+ E9A204CE14C7A487006E4A66 /* PendingSpecTest2.m in Sources */ = {isa = PBXBuildFile; fileRef = E9A204CC14C7A487006E4A66 /* PendingSpecTest2.m */; };
E9B7778014B9E15300D8DC76 /* SPTSenTestCase.h in Headers */ = {isa = PBXBuildFile; fileRef = E9B7777F14B9E15300D8DC76 /* SPTSenTestCase.h */; settings = {ATTRIBUTES = (Public, ); }; };
E9B7778214B9E15A00D8DC76 /* SPTSenTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = E9B7778114B9E15A00D8DC76 /* SPTSenTestCase.m */; };
E9B7778814BA24EC00D8DC76 /* TestHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = E9B7778714BA24EC00D8DC76 /* TestHelper.m */; };
@@ -121,6 +125,8 @@
E9624B4614B8AF2B00E50DE5 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = text; path = README.md; sourceTree = "<group>"; };
E96598D814C345F3003BC25B /* CompilationTest8.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CompilationTest8.m; sourceTree = "<group>"; };
E96598DF14C34CE9003BC25B /* Specta.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = Specta.podspec; sourceTree = "<group>"; };
+ E9A204C814C79F81006E4A66 /* PendingSpecTest1.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PendingSpecTest1.m; sourceTree = "<group>"; };
+ E9A204CC14C7A487006E4A66 /* PendingSpecTest2.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PendingSpecTest2.m; sourceTree = "<group>"; };
E9B7777F14B9E15300D8DC76 /* SPTSenTestCase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPTSenTestCase.h; sourceTree = "<group>"; };
E9B7778114B9E15A00D8DC76 /* SPTSenTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPTSenTestCase.m; sourceTree = "<group>"; };
E9B7778714BA24EC00D8DC76 /* TestHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestHelper.m; sourceTree = "<group>"; };
@@ -291,8 +297,11 @@
E9D9422814B8B43200CD833A /* SequenceTest.m */,
E910177214B911340087CD46 /* PassingSpecTest.m */,
E910177414B9114A0087CD46 /* FailingSpecTest.m */,
+ E9A204C814C79F81006E4A66 /* PendingSpecTest1.m */,
+ E9A204CC14C7A487006E4A66 /* PendingSpecTest2.m */,
E96187B114C4AC690021D7CE /* UnexpectedExceptionTest.m */,
E9BDBAB814BE2F3A00102FB5 /* MiscTest.m */,
+ E9D96A2814B6B8AB007D9521 /* frameworks */,
);
path = test;
sourceTree = "<group>";
@@ -363,7 +372,6 @@
E96598DF14C34CE9003BC25B /* Specta.podspec */,
E9D9420314B8B42A00CD833A /* src */,
E9D9421814B8B43200CD833A /* test */,
- E9D96A2814B6B8AB007D9521 /* frameworks */,
E9D96A2714B6B8AB007D9521 /* products */,
);
sourceTree = "<group>";
@@ -387,6 +395,7 @@
E9D96A3B14B6B8AB007D9521 /* SenTestingKit.framework */,
);
name = frameworks;
+ path = ..;
sourceTree = "<group>";
};
/* End PBXGroup section */
@@ -614,6 +623,8 @@
E96187C514C4AFA70021D7CE /* FailingSpecTest.m in Sources */,
E96187C614C4AFA70021D7CE /* UnexpectedExceptionTest.m in Sources */,
E96187C714C4AFA70021D7CE /* MiscTest.m in Sources */,
+ E9A204CA14C79F81006E4A66 /* PendingSpecTest1.m in Sources */,
+ E9A204CE14C7A487006E4A66 /* PendingSpecTest2.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -654,6 +665,8 @@
E9BDBAB914BE2F3A00102FB5 /* MiscTest.m in Sources */,
E96598D914C345F3003BC25B /* CompilationTest8.m in Sources */,
E96187B214C4AC690021D7CE /* UnexpectedExceptionTest.m in Sources */,
+ E9A204C914C79F81006E4A66 /* PendingSpecTest1.m in Sources */,
+ E9A204CD14C7A487006E4A66 /* PendingSpecTest2.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
@@ -4,10 +4,12 @@
@interface SPTExample : NSObject {
NSString *_name;
SPTVoidBlock _block;
+ BOOL _pending;
}
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) SPTVoidBlock block;
+@property (nonatomic) BOOL pending;
- (id)initWithName:(NSString *)name block:(SPTVoidBlock)block;
View
@@ -5,6 +5,7 @@ @implementation SPTExample
@synthesize
name=_name
, block=_block
+, pending=_pending
;
- (void)dealloc {
@@ -18,6 +19,7 @@ - (id)initWithName:(NSString *)name block:(SPTVoidBlock)block {
if(self) {
self.name = name;
self.block = block;
+ self.pending = NO;
}
return self;
}
View
@@ -75,6 +75,9 @@ - (SPTExample *)addExampleWithName:(NSString *)name block:(SPTVoidBlock)block {
SPTExample *example;
@synchronized(self) {
example = [[SPTExample alloc] initWithName:name block:block];
+ if(!block) {
+ example.pending = YES;
+ }
[self.children addObject:example];
[self incrementExampleCount];
}
@@ -108,18 +111,22 @@ - (void)incrementRanExampleCount {
}
- (void)addBeforeAllBlock:(SPTVoidBlock)block {
+ if(!block) return;
[self.beforeAllArray addObject:[[block copy] autorelease]];
}
- (void)addAfterAllBlock:(SPTVoidBlock)block {
+ if(!block) return;
[self.afterAllArray addObject:[[block copy] autorelease]];
}
- (void)addBeforeEachBlock:(SPTVoidBlock)block {
+ if(!block) return;
[self.beforeEachArray addObject:[[block copy] autorelease]];
}
- (void)addAfterEachBlock:(SPTVoidBlock)block {
+ if(!block) return;
[self.afterEachArray addObject:[[block copy] autorelease]];
}
@@ -180,7 +187,7 @@ - (NSArray *)compileExamplesWithNameStack:(NSArray *)nameStack {
SPTExample *example = child;
NSArray *newNameStack = [nameStack arrayByAddingObject:example.name];
NSString *compiledName = [newNameStack componentsJoinedByString:@" "];
- SPTVoidBlock compiledBlock = ^{
+ SPTVoidBlock compiledBlock = example.pending ? nil : ^{
@synchronized(self.root) {
[self resetRanExampleCountIfNeeded];
[self runBeforeHooks];
@@ -192,6 +199,7 @@ - (NSArray *)compileExamplesWithNameStack:(NSArray *)nameStack {
}
};
SPTExample *compiledExample = [[SPTExample alloc] initWithName:compiledName block:compiledBlock];
+ compiledExample.pending = example.pending;
compiled = [compiled arrayByAddingObject:compiledExample];
[compiledExample release];
}
View
@@ -54,8 +54,10 @@ - (void)SPT_unsetCurrentSpec {
- (void)SPT_runExampleAtIndex:(NSUInteger)index {
[[[NSThread currentThread] threadDictionary] setObject:self forKey:@"SPT_currentTestCase"];
SPTExample *compiledExample = [[[self class] SPT_spec].compiledExamples objectAtIndex:index];
- fprintf(stderr, " %s\n", [compiledExample.name UTF8String]);
- compiledExample.block();
+ fprintf(stderr, " %s%s\n", [compiledExample.name UTF8String], compiledExample.pending ? " (pending)" : "");
+ if(!compiledExample.pending) {
+ compiledExample.block();
+ }
[[[NSThread currentThread] threadDictionary] removeObjectForKey:@"SPT_currentTestCase"];
}
View
@@ -22,6 +22,14 @@ void example(NSString *name, void (^block)());
void it(NSString *name, void (^block)());
void specify(NSString *name, void (^block)());
+void _pending(NSString *name, ...);
+#define xdescribe(...) _pending(__VA_ARGS__, nil)
+#define xcontext(...) _pending(__VA_ARGS__, nil)
+#define xexample(...) _pending(__VA_ARGS__, nil)
+#define xit(...) _pending(__VA_ARGS__, nil)
+#define xspecify(...) _pending(__VA_ARGS__, nil)
+#define pending(...) _pending(__VA_ARGS__, nil)
+
void beforeAll(void (^block)());
void afterAll(void (^block)());
void beforeEach(void (^block)());
View
@@ -8,9 +8,13 @@ @implementation Specta
#define SPT_currentGroup [SPT_currentSpec currentGroup]
void describe(NSString *name, void (^block)()) {
- [SPT_groupStack addObject:[SPT_currentGroup addExampleGroupWithName:name]];
- block();
- [SPT_groupStack removeLastObject];
+ if(block) {
+ [SPT_groupStack addObject:[SPT_currentGroup addExampleGroupWithName:name]];
+ block();
+ [SPT_groupStack removeLastObject];
+ } else {
+ example(name, nil);
+ }
}
void context(NSString *name, void (^block)()) {
@@ -29,6 +33,10 @@ void specify(NSString *name, void (^block)()) {
example(name, block);
}
+void _pending(NSString *name, ...) {
+ example(name, nil);
+}
+
void beforeAll(void (^block)()) {
[SPT_currentGroup addBeforeAllBlock:block];
}
View
@@ -0,0 +1,31 @@
+#import "TestHelper.h"
+#import <objc/runtime.h>
+
+SpecBegin(_PendingSpecTest1)
+
+describe(@"group", ^{
+ beforeAll(nil);
+ afterAll(nil);
+ beforeEach(nil);
+ afterEach(nil);
+
+ describe(@"describe with nil", nil);
+ context(@"context with nil", nil);
+
+ it(@"it with nil", nil);
+ specify(@"specify with nil", nil);
+ example(@"example with nil", nil);
+});
+SpecEnd
+
+@interface PendingSpecTest1 : SenTestCase; @end
+@implementation PendingSpecTest1
+
+- (void)testPendingSpec {
+ SenTestSuiteRun *result = RunSpec(_PendingSpecTest1Spec);
+ expect([result testCaseCount]).toEqual(5);
+ expect([result failureCount]).toEqual(0);
+ expect([result hasSucceeded]).toEqual(YES);
+}
+
+@end
View
@@ -0,0 +1,37 @@
+#import "TestHelper.h"
+#import <objc/runtime.h>
+
+SpecBegin(_PendingSpecTest2)
+
+describe(@"group", ^{
+ xdescribe(@"xdescribe without block");
+ xdescribe(@"xdescribe with block", ^{ NSAssert(NO, @"fail"); });
+
+ xcontext(@"xcontext without block");
+ xcontext(@"xcontext with block", ^{ NSAssert(NO, @"fail"); });
+
+ xit(@"xit without block");
+ xit(@"xit with block", ^{ NSAssert(NO, @"fail"); });
+
+ xspecify(@"xspecify without block");
+ xspecify(@"xspecify with block", ^{ NSAssert(NO, @"fail"); });
+
+ xexample(@"xexample without block");
+ xexample(@"xexample with block", ^{ NSAssert(NO, @"fail"); });
+
+ pending(@"pending without block");
+ pending(@"pending with block", ^{ NSAssert(NO, @"fail"); });
+});
+SpecEnd
+
+@interface PendingSpecTest2 : SenTestCase; @end
+@implementation PendingSpecTest2
+
+- (void)testPendingSpec {
+ SenTestSuiteRun *result = RunSpec(_PendingSpecTest2Spec);
+ expect([result testCaseCount]).toEqual(12);
+ expect([result failureCount]).toEqual(0);
+ expect([result hasSucceeded]).toEqual(YES);
+}
+
+@end

0 comments on commit d4c0b6a

Please sign in to comment.