Permalink
Browse files

A proper test of the postcondition method

  • Loading branch information...
1 parent 62096ea commit 003cc7306601d7c928bef6649caee54e19849813 Eric Smith committed Mar 26, 2012
Showing with 25 additions and 0 deletions.
  1. +25 −0 Specs/OCDSpecDescriptionSpec.m
@@ -106,6 +106,31 @@
nil ]];
}),
+ it(@"runs a postcondition after each example", ^{
+ __block NSMutableArray *callsMade = [[NSMutableArray alloc] init];
+
+ OCDSpecExample *exampleOne = [[OCDSpecExample alloc] initWithBlock:^{
+ [callsMade addObject:@"Ran First Example"];
+ }];
+ OCDSpecExample *exampleTwo = [[OCDSpecExample alloc] initWithBlock:^{
+ [callsMade addObject:@"Ran Second Example"];
+ }];
+
+ NSArray *tests = [NSArray arrayWithObjects:exampleOne, exampleTwo, nil];
+
+ OCDSpecDescription *description = [[OCDSpecDescription alloc] initWithName:@"Something" examples:tests];
+ description.postcondition = ^{
+ [callsMade addObject:@"Postcondition Called"];
+ };
+ [description describe];
+
+ [expect(callsMade) toBeEqualTo:[NSArray arrayWithObjects:@"Ran First Example",
+ @"Postcondition Called",
+ @"Ran Second Example",
+ @"Postcondition Called",
+ nil]];
+ }),
+
it(@"Will still run the postcondition even if the example throws an exception", ^{
__block bool calledPost = NO;

0 comments on commit 003cc73

Please sign in to comment.