Unit Tests Specta. , .
-:
#define SPT_fail(...) \
SPTSpec *spec = [[SPTCurrentTestCase class] spt_spec]; \
NSString *message = [NSString stringWithFormat:__VA_ARGS__]; \
[SPTCurrentTestCase recordFailureWithDescription:message inFile:spec.fileName atLine:(int)spec.lineNumber expected:YES]; \
xxxLoggingAssertionHandler.m:
@implementation xxxLoggingAssertionHandler
+ (void)load {
[xxxLoggingAssertionHandler addHandler];
}
- (void)handleFailureInMethod:(SEL)selector
object:(id)object
file:(NSString *)fileName
lineNumber:(NSInteger)line
description:(NSString *)format, ... {
NSString *selectorName = NSStringFromSelector(selector);
BOOL ignore = [selectorName isEqualToString:@"initWithFieldDescription:rootClass:"] || [selectorName isEqualToString:@"allocDescriptorForClass:rootClass:fields:fieldCount:enums:enumCount:ranges:rangeCount:storageSize:wireFormat:"];
if (!ignore) {
SPT_fail(@"NSAssert Failure: Method %@ for object %@ in %@#%i", selectorName, object, fileName, line);
}
}
- (void)handleFailureInFunction:(NSString *)functionName
file:(NSString *)fileName
lineNumber:(NSInteger)line
description:(NSString *)format, ... {
SPT_fail(@"NSCAssert Failure: Function (%@) in %@#%i", functionName, fileName, line);
}
+ (void)addHandler {
NSAssertionHandler *assertionHandler = [[xxxLoggingAssertionHandler alloc] init];
[[[NSThread currentThread] threadDictionary] setValue:assertionHandler
forKey:NSAssertionHandlerKey];
}
+ (void)removeHandler {
[[[NSThread currentThread] threadDictionary] setValue:nil
forKey:NSAssertionHandlerKey];
}
@end