Skip to content

Commit

Permalink
Specifying itShouldBehaveLike with a shared example group name that d…
Browse files Browse the repository at this point in the history
…oesn't exist will now throw an exception, rather than giving an EXC_BAD_ACCESS.
  • Loading branch information
Adam Milligan committed Aug 12, 2011
1 parent 9a6a1f0 commit 4645d89
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Source/CDRSharedExampleGroupPool.m
Expand Up @@ -16,6 +16,10 @@ void sharedExamplesFor(NSString *groupName, CDRSharedExampleGroupBlock block) {

void itShouldBehaveLike(NSString *groupName) {
CDRSharedExampleGroupBlock sharedExampleGroupBlock = [[[SpecHelper specHelper] sharedExampleGroups] objectForKey:groupName];
if (!sharedExampleGroupBlock) {
NSString *message = [NSString stringWithFormat:@"Unknown shared example group with description: '%@'", groupName];
[[NSException exceptionWithName:NSInternalInconsistencyException reason:message userInfo:nil] raise];
}

CDRExampleGroup *parentGroup = currentSpec.currentGroup;
currentSpec.currentGroup = [CDRExampleGroup groupWithText:[NSString stringWithFormat:@"(as %@)", groupName]];
Expand Down
9 changes: 9 additions & 0 deletions Spec/SpecSpec.mm
Expand Up @@ -163,6 +163,15 @@ void expectFailure(CDRSpecBlock block) {
itShouldBehaveLike(@"a shared example group that contains a failing spec");
});

describe(@"a describe block that tries to include a shared example group that doesn't exist", ^{
@try {
itShouldBehaveLike(@"a unicorn");
} @catch (NSException *) {
return;
}
[NSException exceptionWithName:NSInternalInconsistencyException reason:@"Should have thrown an exception" userInfo:nil];
});

SPEC_END


Expand Down

0 comments on commit 4645d89

Please sign in to comment.