diff --git a/Source/Doubles/CDRSpy.mm b/Source/Doubles/CDRSpy.mm index 96071126..16846df5 100644 --- a/Source/Doubles/CDRSpy.mm +++ b/Source/Doubles/CDRSpy.mm @@ -33,6 +33,38 @@ + (void)stopInterceptingMessagesForInstance:(id)instance { #pragma mark - Emulating the original object +- (id)retain { + __block id that = self; + [self as_spied_class:^{ + [that retain]; + }]; + return self; +} + +- (oneway void)release { + __block id that = self; + [self as_spied_class:^{ + [that release]; + }]; +} + +- (id)autorelease { + __block id that = self; + [self as_spied_class:^{ + [that autorelease]; + }]; + return self; +} + +- (NSUInteger)retainCount { + __block id that = self; + __block NSUInteger count; + [self as_spied_class:^{ + count = [that retainCount]; + }]; + return count; +} + - (NSString *)description { __block id that = self; __block NSString *description = nil; diff --git a/Source/ReporterHelpers/CDROTestNamer.m b/Source/ReporterHelpers/CDROTestNamer.m index 62880566..2759b5a4 100644 --- a/Source/ReporterHelpers/CDROTestNamer.m +++ b/Source/ReporterHelpers/CDROTestNamer.m @@ -2,10 +2,25 @@ #import "CDRExample.h" #import "CDRExampleBase.h" +@interface CDROTestNamer () +@property (nonatomic, retain) NSMutableCharacterSet *allowedCharacterSet; +@end + + @implementation CDROTestNamer +- (id)init { + self = [super init]; + if (self) { + self.allowedCharacterSet = [[[NSCharacterSet alphanumericCharacterSet] mutableCopy] autorelease]; + [self.allowedCharacterSet addCharactersInString:@"_"]; + } + return self; +} + - (NSString *)classNameForExample:(CDRExampleBase *)example { NSString *className = NSStringFromClass([example.spec class]); + className = className ?: @"Cedar"; return [self sanitizeNameFromString:className]; } @@ -28,18 +43,19 @@ - (NSString *)sanitizeNameFromString:(NSString *)string { NSMutableString *mutableString = [string mutableCopy]; [mutableString replaceOccurrencesOfString:@" " withString:@"_" options:0 range:NSMakeRange(0, mutableString.length)]; - NSMutableCharacterSet *allowedCharacterSet = [[NSCharacterSet alphanumericCharacterSet] mutableCopy]; - [allowedCharacterSet addCharactersInString:@"_"]; - for (NSUInteger i=0; i\n"]; for (CDRExample *example in successExamples_) { - [xml appendFormat:@"\t\n", [self escapeString:example.fullText], example.runTime]; + NSString *className = [self.namer classNameForExample:example]; + [xml appendFormat:@"\t\n", [self escapeString:className], [self escapeString:example.fullText], example.runTime]; } for (CDRExample *example in failureExamples_) { @@ -54,8 +64,9 @@ - (void)runDidComplete { NSArray *parts = [failureMessage componentsSeparatedByString:@"\n"]; NSString *testCaseName = [parts objectAtIndex:0]; NSString *failureDescription = [parts objectAtIndex:1]; + NSString *className = [self.namer classNameForExample:example]; - [xml appendFormat:@"\t\n", [self escapeString:testCaseName], example.runTime]; + [xml appendFormat:@"\t\n", [self escapeString:className], [self escapeString:testCaseName], example.runTime]; [xml appendFormat:@"\t\t%@\n", [self escapeString:failureDescription]]; [xml appendString:@"\t\n"]; } diff --git a/Spec/Reporters/CDRJUnitXMLReporterSpec.mm b/Spec/Reporters/CDRJUnitXMLReporterSpec.mm index 2411af30..ddae7e9a 100644 --- a/Spec/Reporters/CDRJUnitXMLReporterSpec.mm +++ b/Spec/Reporters/CDRJUnitXMLReporterSpec.mm @@ -9,7 +9,6 @@ #import "CDRExample.h" #import "CDRJUnitXMLReporter.h" -#import "CDRSpecFailure.h" #import "GDataXMLNode.h" #import "ExampleWithPublicRunDates.h" @@ -143,7 +142,32 @@ + (id)exampleWithText:(NSString *)text andState:(CDRExampleState)state { GDataXMLElement *exampleXML = [[reporter.xmlRootElement elementsForName:@"testcase"] objectAtIndex:0]; expect([[exampleXML attributeForName:@"time"] stringValue]).to_not(be_nil); expect([[[exampleXML attributeForName:@"time"] stringValue] floatValue]).to(be_close_to(5)); + }); + + it(@"should have it's classname", ^{ + CDRExample *example = [CDRExample exampleWithText:@"Spec" andState:CDRExampleStatePassed]; + example.spec = [[CDRSpec new] autorelease]; + [reporter reportOnExample:example]; + + CDRExample *junitExample = [CDRExample exampleWithText:@"JUnitExample" andState:CDRExampleStatePassed]; + junitExample.spec = [[CDRJUnitXMLReporterSpec new] autorelease]; + [reporter reportOnExample:junitExample]; + + [reporter runDidComplete]; + GDataXMLElement *exampleXML = [[reporter.xmlRootElement elementsForName:@"testcase"] objectAtIndex:0]; + expect([[exampleXML attributeForName:@"classname"] stringValue]).to(equal(@"CDRSpec")); + GDataXMLElement *junitExampleXML = [[reporter.xmlRootElement elementsForName:@"testcase"] objectAtIndex:1]; + expect([[junitExampleXML attributeForName:@"classname"] stringValue]).to(equal(@"CDRJUnitXMLReporterSpec")); + }); + + it(@"should have it's classname to default value if spec filename is empty", ^{ + CDRExample *example = [CDRExample exampleWithText:@"Spec" andState:CDRExampleStatePassed]; + + [reporter reportOnExample:example]; + [reporter runDidComplete]; + GDataXMLElement *exampleXML = [[reporter.xmlRootElement elementsForName:@"testcase"] objectAtIndex:0]; + expect([[exampleXML attributeForName:@"classname"] stringValue]).to(equal(@"Cedar")); }); }); @@ -187,7 +211,6 @@ + (id)exampleWithText:(NSString *)text andState:(CDRExampleState)state { }); it(@"should escape the failure reason", ^{ - NSString *exampleName = @"Failing spec 1"; NSString *failureReason = @" Special ' characters \" should < be & escaped > "; NSString *fullExampleText = [NSString stringWithFormat:@"%@\n%@", exampleName, failureReason]; @@ -212,7 +235,32 @@ + (id)exampleWithText:(NSString *)text andState:(CDRExampleState)state { GDataXMLElement *exampleXML = [[reporter.xmlRootElement elementsForName:@"testcase"] objectAtIndex:0]; expect([[exampleXML attributeForName:@"time"] stringValue]).to_not(be_nil); expect([[[exampleXML attributeForName:@"time"] stringValue] floatValue]).to(be_close_to(5)); + }); + + it(@"should have it's classname", ^{ + CDRExample *example = [CDRExample exampleWithText:@"Spec" andState:CDRExampleStateFailed]; + example.spec = [[CDRSpec new] autorelease]; + [reporter reportOnExample:example]; + + CDRExample *junitExample = [CDRExample exampleWithText:@"JUnitExample" andState:CDRExampleStateFailed]; + junitExample.spec = [[CDRJUnitXMLReporterSpec new] autorelease]; + [reporter reportOnExample:junitExample]; + [reporter runDidComplete]; + GDataXMLElement *exampleXML = [[reporter.xmlRootElement elementsForName:@"testcase"] objectAtIndex:0]; + expect([[exampleXML attributeForName:@"classname"] stringValue]).to(equal(@"CDRSpec")); + GDataXMLElement *junitExampleXML = [[reporter.xmlRootElement elementsForName:@"testcase"] objectAtIndex:1]; + expect([[junitExampleXML attributeForName:@"classname"] stringValue]).to(equal(@"CDRJUnitXMLReporterSpec")); + }); + + it(@"should have it's classname to default value if spec filename is empty", ^{ + CDRExample *example = [CDRExample exampleWithText:@"Spec" andState:CDRExampleStateFailed]; + + [reporter reportOnExample:example]; + + [reporter runDidComplete]; + GDataXMLElement *exampleXML = [[reporter.xmlRootElement elementsForName:@"testcase"] objectAtIndex:0]; + expect([[exampleXML attributeForName:@"classname"] stringValue]).to(equal(@"Cedar")); }); });