Skip to content

Commit

Permalink
Extract the hard-coded probe timeout so it can be set as a parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Redpath committed Jan 13, 2011
1 parent c089783 commit 9c63e2d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
9 changes: 8 additions & 1 deletion Kiwi/KWAsyncVerifier.h
Expand Up @@ -10,10 +10,17 @@
#import "KWMatchVerifier.h"
#import "KWProbe.h"

#define kKW_DEFAULT_PROBE_TIMEOUT 1.0

@class KWAsyncMatcherProbe;

@interface KWAsyncVerifier : KWMatchVerifier
{}
{
NSInteger timeout;
}
@property (nonatomic, assign) NSInteger timeout;

+ (id)asyncVerifierWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite matcherFactory:(KWMatcherFactory *)aMatcherFactory reporter:(id<KWReporting>)aReporter probeTimeout:(NSInteger)probeTimeout;
- (void)verifyWithProbe:(KWAsyncMatcherProbe *)aProbe;
@end

Expand Down
18 changes: 17 additions & 1 deletion Kiwi/KWAsyncVerifier.m
Expand Up @@ -14,9 +14,25 @@

@implementation KWAsyncVerifier

@synthesize timeout;

+ (id)asyncVerifierWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite matcherFactory:(KWMatcherFactory *)aMatcherFactory reporter:(id<KWReporting>)aReporter probeTimeout:(NSInteger)probeTimeout;
{
KWAsyncVerifier *verifier = [[self alloc] initWithExpectationType:anExpectationType callSite:aCallSite matcherFactory:aMatcherFactory reporter:aReporter];
verifier.timeout = probeTimeout;
return [verifier autorelease];
}

- (id)initWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite matcherFactory:(KWMatcherFactory *)aMatcherFactory reporter:(id<KWReporting>)aReporter {
if ((self = [super initWithExpectationType:anExpectationType callSite:aCallSite matcherFactory:aMatcherFactory reporter:aReporter])) {
self.timeout = kKW_DEFAULT_PROBE_TIMEOUT;
}
return self;
}

- (void)verifyWithProbe:(KWAsyncMatcherProbe *)aProbe {
@try {
KWProbePoller *poller = [[KWProbePoller alloc] initWithTimeout:3.0 delay:kKW_DEFAULT_PROBE_DELAY];
KWProbePoller *poller = [[KWProbePoller alloc] initWithTimeout:self.timeout delay:kKW_DEFAULT_PROBE_DELAY];

if (![poller check:aProbe]) {
if (self.expectationType == KWExpectationTypeShould) {
Expand Down
2 changes: 1 addition & 1 deletion Kiwi/KWSpec.m
Expand Up @@ -104,7 +104,7 @@ - (id)addMatchVerifierWithExpectationType:(KWExpectationType)anExpectationType c
}

- (id)addAsyncVerifierWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite {
id verifier = [KWAsyncVerifier matchVerifierWithExpectationType:anExpectationType callSite:aCallSite matcherFactory:self.matcherFactory reporter:self];
id verifier = [KWAsyncVerifier asyncVerifierWithExpectationType:anExpectationType callSite:aCallSite matcherFactory:self.matcherFactory reporter:self probeTimeout:kKW_DEFAULT_PROBE_TIMEOUT];
[self addVerifier:verifier];
return verifier;
}
Expand Down
6 changes: 3 additions & 3 deletions Kiwi/KWTestCase.m
Expand Up @@ -107,9 +107,9 @@ - (id)addMatchVerifierWithExpectationType:(KWExpectationType)anExpectationType c
}

- (id)addAsyncVerifierWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite {
id verifier = [KWAsyncVerifier matchVerifierWithExpectationType:anExpectationType callSite:aCallSite matcherFactory:self.matcherFactory reporter:self];
[self.verifiers addObject:verifier];
return verifier;
id verifier = [KWAsyncVerifier asyncVerifierWithExpectationType:anExpectationType callSite:aCallSite matcherFactory:self.matcherFactory reporter:self probeTimeout:kKW_DEFAULT_PROBE_TIMEOUT];
[self.verifiers addObject:verifier];
return verifier;
}

#pragma mark -
Expand Down

0 comments on commit 9c63e2d

Please sign in to comment.