Permalink
Browse files

Modified the example builder tests to use the new block based transac…

…tional system and proceeded to make them pass. Also did the same with determining if one is on the simulator or an actual iOS device.
  • Loading branch information...
1 parent b39fe45 commit bde8fd542067efc3507b0cab55c2af28f10c00cd @dented42 dented42 committed Nov 29, 2011
Showing with 26 additions and 28 deletions.
  1. +1 −2 Kiwi/KWDeviceInfo.m
  2. +13 −0 Kiwi/KWExampleGroupBuilder.m
  3. +12 −26 Tests/KWExampleGroupBuilderTest.m
View
@@ -19,8 +19,7 @@ @implementation KWDeviceInfo
+ (BOOL)isSimulator {
#if TARGET_IPHONE_SIMULATOR
- NSString *model = [[UIDevice currentDevice] model];
- return [model hasSuffix:@" Simulator"];
+ return YES;
#else
return NO;
#endif // #if TARGET_IPHONE_SIMULATOR
@@ -91,12 +91,25 @@ - (BOOL)isBuildingExampleGroup {
- (NSArray *)buildExampleGroups:(void (^)(void))buildingBlock
{
+ if (self.isBuildingExampleGroup)
+ [NSException raise:@"KWExampleGroupBuilderException" format:@"an example group has already been started"];
+
self.exampleGroups = [NSMutableArray array];
KWContextNode *rootNode = [KWContextNode contextNodeWithCallSite:nil description:nil];
[self.contextNodeStack addObject:rootNode];
buildingBlock();
+ if ([self.contextNodeStack count] > 1) {
+ NSDictionary * context = [[NSDictionary alloc] initWithObjectsAndKeys:[self.contextNodeStack copy], @"contextNodeStack",
+ [self.exampleGroups copy], @"exampleGroups", nil];
+ [self.contextNodeStack removeAllObjects];
+ self.exampleGroups = nil;
+ NSException *exception = [[NSException alloc] initWithName:@"KWExampleGroupBuilderException"
+ reason:@"cannot end example group with open contexts"
+ userInfo:context];
+ [exception raise];
+ }
[self.contextNodeStack removeAllObjects];
NSArray *_exampleGroups = [self.exampleGroups copy];
@@ -16,44 +16,30 @@ @interface KWExampleGroupBuilderTest : SenTestCase
@implementation KWExampleGroupBuilderTest
-- (void)testItShouldStartExampleGroups {
- STAssertNoThrow([[KWExampleGroupBuilder sharedExampleGroupBuilder] startExampleGroups], @"expected example group to be started");
- [[KWExampleGroupBuilder sharedExampleGroupBuilder] endExampleGroups];
- STAssertFalse([[KWExampleGroupBuilder sharedExampleGroupBuilder] isBuildingExampleGroup], @"example group builder must be clean for other tests to run cleanly");
-}
-
-- (void)testItShouldEndAndCreateExampleGroups {
- [[KWExampleGroupBuilder sharedExampleGroupBuilder] startExampleGroups];
- id exampleGroup = [[KWExampleGroupBuilder sharedExampleGroupBuilder] endExampleGroups];
+- (void)testItShouldBuildExampleGroups {
+ id exampleGroup = [[KWExampleGroupBuilder sharedExampleGroupBuilder] buildExampleGroups:^{}];
STAssertNotNil(exampleGroup, @"expected example group to be created");
STAssertFalse([[KWExampleGroupBuilder sharedExampleGroupBuilder] isBuildingExampleGroup], @"example group builder must be clean for other tests to run cleanly");
}
-- (void)testItShouldRaiseIfStartExampleGroupIsUnmatched {
- [[KWExampleGroupBuilder sharedExampleGroupBuilder] startExampleGroups];
- STAssertThrows([[KWExampleGroupBuilder sharedExampleGroupBuilder] startExampleGroups], @"expected raised exception");
- [[KWExampleGroupBuilder sharedExampleGroupBuilder] endExampleGroups];
- STAssertFalse([[KWExampleGroupBuilder sharedExampleGroupBuilder] isBuildingExampleGroup], @"example group builder must be clean for other tests to run cleanly");
-}
-
-- (void)testItShouldRaiseIfEndExampleGroupIsUnmatched {
- STAssertThrows([[KWExampleGroupBuilder sharedExampleGroupBuilder] endExampleGroups], @"expected raised exception");
+- (void)testItShouldRaiseIfBuildingIsNested {
+ [[KWExampleGroupBuilder sharedExampleGroupBuilder] buildExampleGroups:^{
+ STAssertThrows([[KWExampleGroupBuilder sharedExampleGroupBuilder] buildExampleGroups:^{}], @"expected raised exception");
+ }];
STAssertFalse([[KWExampleGroupBuilder sharedExampleGroupBuilder] isBuildingExampleGroup], @"example group builder must be clean for other tests to run cleanly");
}
- (void)testItShouldRaiseWhenEndingWithPushContextUnmatched {
- [[KWExampleGroupBuilder sharedExampleGroupBuilder] startExampleGroups];
- [[KWExampleGroupBuilder sharedExampleGroupBuilder] pushContextNodeWithCallSite:nil description:@"Cruiser"];
- STAssertThrows([[KWExampleGroupBuilder sharedExampleGroupBuilder] endExampleGroups], @"expected raised exception");
- [[KWExampleGroupBuilder sharedExampleGroupBuilder] popContextNode];
- [[KWExampleGroupBuilder sharedExampleGroupBuilder] endExampleGroups];
+ STAssertThrows([[KWExampleGroupBuilder sharedExampleGroupBuilder] buildExampleGroups:^{
+ [[KWExampleGroupBuilder sharedExampleGroupBuilder] pushContextNodeWithCallSite:nil description:@"Cruiser"];
+ }], @"expected raised exception");
STAssertFalse([[KWExampleGroupBuilder sharedExampleGroupBuilder] isBuildingExampleGroup], @"example group builder must be clean for other tests to run cleanly");
}
- (void)testItShouldRaiseWhenPopContextUnmatched {
- [[KWExampleGroupBuilder sharedExampleGroupBuilder] startExampleGroups];
- STAssertThrows([[KWExampleGroupBuilder sharedExampleGroupBuilder] popContextNode], @"expected raised exception");
- [[KWExampleGroupBuilder sharedExampleGroupBuilder] endExampleGroups];
+ [[KWExampleGroupBuilder sharedExampleGroupBuilder] buildExampleGroups:^{
+ STAssertThrows([[KWExampleGroupBuilder sharedExampleGroupBuilder] popContextNode], @"expected raised exception");
+ }];
STAssertFalse([[KWExampleGroupBuilder sharedExampleGroupBuilder] isBuildingExampleGroup], @"example group builder must be clean for other tests to run cleanly");
}

0 comments on commit bde8fd5

Please sign in to comment.