Permalink
Browse files

fixed specs and added more to test new features for skipped CDRExamples

  • Loading branch information...
1 parent e491a85 commit c11dd752ab1204805222f3eb02f99e7e22cabd62 @robertwijas robertwijas committed Oct 3, 2012
Showing with 149 additions and 81 deletions.
  1. +8 −5 Source/CDRJUnitXMLReporter.m
  2. +141 −76 Spec/CDRJUnitXMLReporterSpec.mm
@@ -57,7 +57,7 @@ - (void)reportOnExample:(CDRExample *)example {
break;
case CDRExampleStateSkipped:
if (self.skippedAsFailed) {
- [failureMessages_ addObject:[NSString stringWithFormat:@"%@\n%@\n",[example fullText], @"Skipped"]];
+ [failureMessages_ addObject:[NSString stringWithFormat:@"%@\n%@\n",[example fullText], @"Test skipped and we hate it. Fail!"]];
} else {
[skippedMessages_ addObject:example.fullText];
}
@@ -74,19 +74,22 @@ - (void)reportOnExample:(CDRExample *)example {
- (void)appendXMLForTestcaseWithName:(NSString *)name body:(NSString *)body toString:(NSMutableString *)xml {
NSUInteger firstWordEndIndex = [name rangeOfCharacterFromSet:[NSCharacterSet whitespaceCharacterSet]].location;
if (firstWordEndIndex != NSNotFound) {
- [xml appendFormat:@"\t<testcase classname=\"%@\" name=\"%@\">\n", [name substringToIndex:firstWordEndIndex], [self escape:name]];
+ [xml appendFormat:@"\t<testcase classname=\"%@\" name=\"%@\"", [name substringToIndex:firstWordEndIndex], [self escape:name]];
} else {
- [xml appendFormat:@"\t<testcase name=\"%@\">\n", [self escape:name]];
+ [xml appendFormat:@"\t<testcase name=\"%@\"", [self escape:name]];
}
if (body) {
+ [xml appendString:@">\n"];
[xml appendFormat:@"\t\t%@\n", body];
+ [xml appendString:@"\t</testcase>\n"];
+ } else {
+ [xml appendString:@"/>\n"];
}
- [xml appendString:@"\t</testcase>\n"];
}
- (void)runDidComplete {
- NSTimeInterval time = [startTime_ timeIntervalSinceNow] * (-1);
+ NSTimeInterval time = fabs([startTime_ timeIntervalSinceNow]);
NSMutableString *xml = [NSMutableString string];
[xml appendString:@"<?xml version=\"1.0\"?>\n"];
@@ -55,96 +55,161 @@ + (id) exampleWithText:(NSString *)text andState:(CDRExampleState)state {
SPEC_BEGIN(CDRJUnitXMLReporterSpec)
-describe(@"runDidComplete", ^{
- __block TestCDRJUnitXMLReporter *reporter;
+describe(@"CDRJUnitXMLReporter", ^{
+ __block TestCDRJUnitXMLReporter *reporter;
+
beforeEach(^{
reporter = [[TestCDRJUnitXMLReporter alloc] init];
});
-
+
afterEach(^{
[reporter release];
});
-
- context(@"When no specs are run", ^{
- it(@"should output a blank test suite report", ^{
- [reporter runDidComplete];
-
- expect(reporter.xml).to(equal(@"<?xml version=\"1.0\"?>\n<testsuite>\n</testsuite>\n"));
+
+ describe(@"runDidComplete", ^{
+ context(@"When no specs are run", ^{
+ it(@"should output a blank test suite report", ^{
+ [reporter runDidComplete];
+
+ expect(reporter.xml).to(equal(@"<?xml version=\"1.0\"?>\n<testsuite time=\"0.0000\">\n</testsuite>\n"));
+ });
});
- });
-
- describe(@"Each passing spec", ^{
- it(@"should be written to the XML file", ^{
- CDRExample *example1 = [CDRExample exampleWithText:@"Passing spec 1" andState:CDRExampleStatePassed];
- CDRExample *example2 = [CDRExample exampleWithText:@"Passing spec 2" andState:CDRExampleStatePassed];
-
- [reporter reportOnExample:example1];
- [reporter reportOnExample:example2];
-
- [reporter runDidComplete];
-
- expect([reporter.xml rangeOfString:@"<testcase classname=\"Cedar\" name=\"Passing spec 1\" />"].location).to_not(equal((NSUInteger)NSNotFound));
- expect([reporter.xml rangeOfString:@"<testcase classname=\"Cedar\" name=\"Passing spec 2\" />"].location).to_not(equal((NSUInteger)NSNotFound));
+
+ describe(@"Each passing spec", ^{
+ it(@"should be written to the XML file", ^{
+ CDRExample *example1 = [CDRExample exampleWithText:@"Passing spec 1" andState:CDRExampleStatePassed];
+ CDRExample *example2 = [CDRExample exampleWithText:@"Passing spec 2" andState:CDRExampleStatePassed];
+
+ [reporter reportOnExample:example1];
+ [reporter reportOnExample:example2];
+
+ [reporter runDidComplete];
+
+ expect([reporter.xml rangeOfString:@"<testcase classname=\"Passing\" name=\"Passing spec 1\"/>"].location).to_not(equal((NSUInteger)NSNotFound));
+ expect([reporter.xml rangeOfString:@"<testcase classname=\"Passing\" name=\"Passing spec 2\"/>"].location).to_not(equal((NSUInteger)NSNotFound));
+ });
+
+ it(@"should have its name escaped", ^{
+ CDRExample *example = [CDRExample exampleWithText:@"Special ' characters \" should < be & escaped > " andState:CDRExampleStatePassed];
+
+ [reporter reportOnExample:example];
+
+ [reporter runDidComplete];
+
+ expect([reporter.xml rangeOfString:@"name=\"Special &apos; characters &quot; should &lt; be &amp; escaped &gt; \""].location).to_not(equal((NSUInteger)NSNotFound));
+ });
});
-
- it(@"should have its name escaped", ^{
- CDRExample *example = [CDRExample exampleWithText:@"Special ' characters \" should < be & escaped > " andState:CDRExampleStatePassed];
-
- [reporter reportOnExample:example];
-
- [reporter runDidComplete];
-
- expect([reporter.xml rangeOfString:@"name=\"Special &apos; characters &quot; should &lt; be &amp; escaped &gt; \""].location).to_not(equal((NSUInteger)NSNotFound));
+
+ describe(@"Each failing spec", ^{
+ it(@"should be written to the XML file", ^{
+ CDRExample *example1 = [CDRExample exampleWithText:@"Failing spec 1" andState:CDRExampleStateFailed];
+ example1.failure = [CDRSpecFailure specFailureWithReason:@"Failure reason 1"];
+ CDRExample *example2 = [CDRExample exampleWithText:@"Failing spec 2" andState:CDRExampleStateFailed];
+ example2.failure = [CDRSpecFailure specFailureWithReason:@"Failure reason 2"];
+
+ [reporter reportOnExample:example1];
+ [reporter reportOnExample:example2];
+
+ [reporter runDidComplete];
+
+ expect([reporter.xml rangeOfString:@"<testcase classname=\"Failing\" name=\"Failing spec 1\">\n\t\t<failure>Failure reason 1</failure>\n\t</testcase>"].location).to_not(equal((NSUInteger)NSNotFound));
+ expect([reporter.xml rangeOfString:@"<testcase classname=\"Failing\" name=\"Failing spec 2\">\n\t\t<failure>Failure reason 2</failure>\n\t</testcase>"].location).to_not(equal((NSUInteger)NSNotFound));
+ });
+
+ it(@"should have its name escaped", ^{
+ CDRExample *example = [CDRExample exampleWithText:@"Special ' characters \" should < be & escaped > " andState:CDRExampleStateFailed];
+
+ [reporter reportOnExample:example];
+
+ [reporter runDidComplete];
+
+ expect([reporter.xml rangeOfString:@"name=\"Special &apos; characters &quot; should &lt; be &amp; escaped &gt; \""].location).to_not(equal((NSUInteger)NSNotFound));
+ });
+
+ it(@"should escape the failure reason", ^{
+ CDRExample *example1 = [CDRExample exampleWithText:@"Failing spec 1\n Special ' characters \" should < be & escaped > " andState:CDRExampleStateFailed];
+
+ [reporter reportOnExample:example1];
+
+ [reporter runDidComplete];
+
+ expect([reporter.xml rangeOfString:@"<failure> Special &apos; characters &quot; should &lt; be &amp; escaped &gt; </failure>"].location).to_not(equal((NSUInteger)NSNotFound));
+ });
});
- });
-
- describe(@"Each failing spec", ^{
- it(@"should be written to the XML file", ^{
- CDRExample *example1 = [CDRExample exampleWithText:@"Failing spec 1" andState:CDRExampleStateFailed];
- example1.failure = [CDRSpecFailure specFailureWithReason:@"Failure reason 1"];
- CDRExample *example2 = [CDRExample exampleWithText:@"Failing spec 2" andState:CDRExampleStateFailed];
- example2.failure = [CDRSpecFailure specFailureWithReason:@"Failure reason 2"];
-
- [reporter reportOnExample:example1];
- [reporter reportOnExample:example2];
-
- [reporter runDidComplete];
-
- expect([reporter.xml rangeOfString:@"<testcase classname=\"Cedar\" name=\"Failing spec 1\">\n\t\t<failure type=\"Failure\">Failure reason 1</failure>\n\t</testcase>"].location).to_not(equal((NSUInteger)NSNotFound));
- expect([reporter.xml rangeOfString:@"<testcase classname=\"Cedar\" name=\"Failing spec 2\">\n\t\t<failure type=\"Failure\">Failure reason 2</failure>\n\t</testcase>"].location).to_not(equal((NSUInteger)NSNotFound));
+
+ describe(@"Each spec that causes an error", ^{
+ it(@"should be handled the same as a failing spec", ^{
+ CDRExample *example = [CDRExample exampleWithText:@"Failing spec\nFailure reason" andState:CDRExampleStateError];
+
+ [reporter reportOnExample:example];
+
+ [reporter runDidComplete];
+
+ expect([reporter.xml rangeOfString:@"<testcase classname=\"Failing\" name=\"Failing spec\">\n\t\t<failure>Failure reason</failure>\n\t</testcase>"].location).to_not(equal((NSUInteger)NSNotFound));
+ });
});
-
- it(@"should have its name escaped", ^{
- CDRExample *example = [CDRExample exampleWithText:@"Special ' characters \" should < be & escaped > " andState:CDRExampleStateFailed];
-
- [reporter reportOnExample:example];
-
- [reporter runDidComplete];
-
- expect([reporter.xml rangeOfString:@"name=\"Special &apos; characters &quot; should &lt; be &amp; escaped &gt; \""].location).to_not(equal((NSUInteger)NSNotFound));
+
+ describe(@"skipped test", ^{
+ beforeEach(^{
+ [reporter reportOnExample:[CDRExample exampleWithText:@"Skipped test" andState:CDRExampleStateSkipped]];
+ });
+
+ it(@"should be reported as skipped", ^{
+ [reporter runDidComplete];
+
+ expect([reporter.xml rangeOfString:@"<skipped"].location).to_not(equal((NSUInteger)NSNotFound));
+ });
});
-
- it(@"should escape the failure reason", ^{
- CDRExample *example1 = [CDRExample exampleWithText:@"Failing spec 1\n Special ' characters \" should < be & escaped > " andState:CDRExampleStateFailed];
-
- [reporter reportOnExample:example1];
-
- [reporter runDidComplete];
-
- expect([reporter.xml rangeOfString:@"<failure type=\"Failure\"> Special &apos; characters &quot; should &lt; be &amp; escaped &gt; </failure>"].location).to_not(equal((NSUInteger)NSNotFound));
+
+ context(@"when skippedAsFailed property is set to YES", ^{
+ beforeEach(^{
+ reporter.skippedAsFailed = YES;
+ });
+
+ describe(@"skipped test", ^{
+ beforeEach(^{
+ [reporter reportOnExample:[CDRExample exampleWithText:@"Skipped test" andState:CDRExampleStateSkipped]];
+ });
+
+ it(@"should be reported as failure", ^{
+ [reporter runDidComplete];
+
+ expect([reporter.xml rangeOfString:@"<failure"].location).to_not(equal((NSUInteger)NSNotFound));
+ });
+
+ it(@"should be reported with a message 'Test skipped and we hate it. Fail!'", ^{
+ [reporter runDidComplete];
+
+ expect([reporter.xml rangeOfString:@"Test skipped and we hate it. Fail!"].location).to_not(equal((NSUInteger)NSNotFound));
+ });
+ });
});
});
-
- describe(@"Each spec that causes an error", ^{
- it(@"should be handled the same as a failing spec", ^{
- CDRExample *example = [CDRExample exampleWithText:@"Failing spec\nFailure reason" andState:CDRExampleStateError];
-
- [reporter reportOnExample:example];
-
- [reporter runDidComplete];
-
- expect([reporter.xml rangeOfString:@"<testcase classname=\"Cedar\" name=\"Failing spec\">\n\t\t<failure type=\"Failure\">Failure reason</failure>\n\t</testcase>"].location).to_not(equal((NSUInteger)NSNotFound));
+
+ it(@"should have skippedAsFailed property set to NO by default", ^{
+ expect(reporter.skippedAsFailed).to(equal(NO));
+ });
+
+ context(@"when CEDAR_JUNIT_XML_SKIPPED_AS_FAILED is set to 1", ^{
+ beforeEach(^{
+ setenv("CEDAR_JUNIT_XML_SKIPPED_AS_FAILED", "1", 1);
+ });
+
+ afterEach(^{
+ unsetenv("CEDAR_JUNIT_XML_SKIPPED_AS_FAILED");
+ });
+
+ describe(@"created reporter", ^{
+ __block TestCDRJUnitXMLReporter *createdReporter;
+
+ beforeEach(^{
+ createdReporter = [[[TestCDRJUnitXMLReporter alloc] init] autorelease];
+ });
+
+ it(@"should have skippedAsFailed property set to YES", ^{
+ expect(createdReporter.skippedAsFailed).to(equal(YES));
+ });
});
});
});

0 comments on commit c11dd75

Please sign in to comment.