Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 84 lines (71 sloc) 1.964 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
#import "CDRExample.h"
#import "CDRExampleReporter.h"
#import "CDRSpecFailure.h"
#import "SpecHelper.h"

const CDRSpecBlock PENDING = nil;

@interface CDRExample (Private)
- (void)setState:(CDRExampleState)state;
@end

@implementation CDRExample

@synthesize failure = failure_;

+ (id)exampleWithText:(NSString *)text andBlock:(CDRSpecBlock)block {
    return [[[[self class] alloc] initWithText:text andBlock:block] autorelease];
}

- (id)initWithText:(NSString *)text andBlock:(CDRSpecBlock)block {
    if (self = [super initWithText:text]) {
        block_ = [block copy];
        state_ = CDRExampleStateIncomplete;
    }
    return self;
}

- (void)dealloc {
    [block_ release];
    [super dealloc];
}

#pragma mark CDRExampleBase
- (CDRExampleState)state {
    return state_;
}

- (NSString *)message {
    if (self.failure.reason) {
        return self.failure.reason;
    }
    return [super message];
}

- (float)progress {
    if (self.state == CDRExampleStateIncomplete) {
        return 0.0;
    } else {
        return 1.0;
    }
}

- (void)run {
    NSDate *startDate = [[NSDate alloc] init];
    if (!self.shouldRun) {
        self.state = CDRExampleStateSkipped;
    } else if (block_) {
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        @try {
            [parent_ setUp];
            block_();
            self.state = CDRExampleStatePassed;
        } @catch (CDRSpecFailure *x) {
            self.failure = x;
            self.state = CDRExampleStateFailed;
        } @catch (NSObject *x) {
            self.failure = [CDRSpecFailure specFailureWithRaisedObject:x];
            self.state = CDRExampleStateError;
        }
        [parent_ tearDown];
        [pool drain];
    } else {
        self.state = CDRExampleStatePending;
    }
    runTime_ = -[startDate timeIntervalSinceNow];
    [startDate release];
}

#pragma mark Private interface
- (void)setState:(CDRExampleState)state {
    state_ = state;
}

@end
Something went wrong with that request. Please try again.