Skip to content
Browse files

Extract the hard-coded probe timeout so it can be set as a parameter.

  • Loading branch information...
1 parent c089783 commit 9c63e2da6bdc044283e97ee9544e29755f07d4eb Luke Redpath committed
Showing with 29 additions and 6 deletions.
  1. +8 −1 Kiwi/KWAsyncVerifier.h
  2. +17 −1 Kiwi/KWAsyncVerifier.m
  3. +1 −1 Kiwi/KWSpec.m
  4. +3 −3 Kiwi/KWTestCase.m
View
9 Kiwi/KWAsyncVerifier.h
@@ -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
View
18 Kiwi/KWAsyncVerifier.m
@@ -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) {
View
2 Kiwi/KWSpec.m
@@ -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;
}
View
6 Kiwi/KWTestCase.m
@@ -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 -

0 comments on commit 9c63e2d

Please sign in to comment.
Something went wrong with that request. Please try again.