Permalink
Browse files

Specifying itShouldBehaveLike with a shared example group name that d…

…oesn't exist will now throw an exception, rather than giving an EXC_BAD_ACCESS.
  • Loading branch information...
Adam Milligan
Adam Milligan committed Aug 12, 2011
1 parent 9a6a1f0 commit 4645d891f57e48f2869359d5ce20628ae555afdd
Showing with 13 additions and 0 deletions.
  1. +4 −0 Source/CDRSharedExampleGroupPool.m
  2. +9 −0 Spec/SpecSpec.mm
@@ -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]];
View
@@ -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

0 comments on commit 4645d89

Please sign in to comment.