-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only call +before/afterEach on CDRHooks conformers #387
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@briancroom I think this was added in error 2 years ago... What's odd is that the example further up on line 174 seems to imply this should have raised an exception in the main spec run, but it only occurred when the spec gets redefined via construction of a
CDRSpecRun
inCDRHooksSpec
.