-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only call +before/afterEach on CDRHooks conformers (#387)
* Only call +before/afterEach on CDRHooks conformers Rebased from and added more tests from #365
- Loading branch information
Showing
9 changed files
with
139 additions
and
63 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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#import "Cedar.h" | ||
#import "CDRSpec.h" | ||
#import "CDRSpecRun.h" | ||
|
||
static BOOL conformantClassBeforeEachWasTriggered__ = NO; | ||
static BOOL conformantClassBeforeEachWasTriggeredBeforeSpecBeforeEach__ = NO; | ||
static BOOL nonConformantClassBeforeEachWasTriggered__ = NO; | ||
static BOOL conformantClassAfterEachWasTriggered__ = NO; | ||
static BOOL conformantClassAfterEachWasTriggeredBeforeSpecAfterEach__ = NO; | ||
static BOOL nonConformantClassAfterEachWasTriggered__ = NO; | ||
|
||
using namespace Cedar::Matchers; | ||
|
||
|
||
@interface ClassThatDoesntConformToCDRHooks : NSObject | ||
@end | ||
|
||
@interface ClassThatConformsToCDRHooks : NSObject | ||
@end | ||
|
||
@interface ClassThatConformsToCDRHooks ()<CDRHooks> | ||
@end | ||
|
||
@implementation ClassThatConformsToCDRHooks | ||
+ (void)beforeEach { | ||
conformantClassBeforeEachWasTriggered__ = YES; | ||
} | ||
|
||
+ (void)afterEach { | ||
conformantClassAfterEachWasTriggered__ = YES; | ||
} | ||
@end | ||
|
||
@implementation ClassThatDoesntConformToCDRHooks | ||
+ (void)beforeEach { | ||
nonConformantClassBeforeEachWasTriggered__ = YES; | ||
} | ||
|
||
+ (void)afterEach { | ||
nonConformantClassAfterEachWasTriggered__ = YES; | ||
} | ||
@end | ||
|
||
@interface DummySpecForTestingHooks : CDRSpec | ||
@end | ||
@implementation DummySpecForTestingHooks | ||
- (void)declareBehaviors { | ||
self.fileName = [NSString stringWithUTF8String:__FILE__]; | ||
beforeEach(^{ | ||
conformantClassBeforeEachWasTriggeredBeforeSpecBeforeEach__ = conformantClassBeforeEachWasTriggered__; | ||
}); | ||
it(@"just needs to have a spec", ^{ | ||
}); | ||
afterEach(^{ | ||
conformantClassAfterEachWasTriggeredBeforeSpecAfterEach__ = conformantClassAfterEachWasTriggered__; | ||
}); | ||
} | ||
@end | ||
|
||
SPEC_BEGIN(CDRHooksSpec) | ||
|
||
//NB: If you focus any test here, you must also focus "just needs to run this spec" in DummySpecForTestingHooks | ||
describe(@"CDRHooks", ^{ | ||
beforeEach(^{ | ||
nonConformantClassBeforeEachWasTriggered__ = | ||
nonConformantClassAfterEachWasTriggered__ = | ||
conformantClassBeforeEachWasTriggered__ = | ||
conformantClassBeforeEachWasTriggeredBeforeSpecBeforeEach__ = | ||
conformantClassAfterEachWasTriggered__ = | ||
conformantClassAfterEachWasTriggeredBeforeSpecAfterEach__ = NO; | ||
|
||
CDRSpec *dummySpec = [[[DummySpecForTestingHooks class] alloc] init]; | ||
[dummySpec defineBehaviors]; | ||
|
||
CDRSpecRun *specRun = [[CDRSpecRun alloc] initWithExampleReporters:@[]]; | ||
[specRun performSpecRun:^{ | ||
[dummySpec.rootGroup runWithDispatcher:specRun.dispatcher]; | ||
}]; | ||
}); | ||
|
||
describe(@"+beforeEach", ^{ | ||
it(@"should not call +beforeEach on non-conformant classes", ^{ | ||
expect(nonConformantClassBeforeEachWasTriggered__).to(be_falsy); | ||
}); | ||
|
||
it(@"should run the +beforeEach BEFORE spec beforeEaches for CDRHooks conformers", ^{ | ||
expect(conformantClassBeforeEachWasTriggered__).to(be_truthy); | ||
expect(conformantClassBeforeEachWasTriggeredBeforeSpecBeforeEach__).to(be_truthy); | ||
}); | ||
}); | ||
|
||
describe(@"+afterEach", ^{ | ||
it(@"should not call +afterEach on non-conformant classes", ^{ | ||
expect(nonConformantClassAfterEachWasTriggered__).to(be_falsy); | ||
}); | ||
|
||
it(@"should run the +afterEach AFTER spec afterEaches for CDRHooks conformers", ^{ | ||
expect(conformantClassAfterEachWasTriggered__).to(be_truthy); | ||
expect(conformantClassAfterEachWasTriggeredBeforeSpecAfterEach__).to(be_falsy); | ||
}); | ||
}); | ||
}); | ||
|
||
SPEC_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 was deleted.
Oops, something went wrong.
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