Skip to content

Instantly share code, notes, and snippets.

@gonzalezreal
Last active August 29, 2015 13:58
Show Gist options
  • Save gonzalezreal/9997531 to your computer and use it in GitHub Desktop.
Save gonzalezreal/9997531 to your computer and use it in GitHub Desktop.
TGRAsyncTestHelper
#import <Foundation/Foundation.h>
#define TGR_RUNLOOP_INTERVAL 0.05
#define TGR_TIMEOUT_INTERVAL 1.0
#define TGR_RUNLOOP_COUNT TGR_TIMEOUT_INTERVAL / TGR_RUNLOOP_INTERVAL
#define TGR_CAT(x, y) x ## y
#define TGR_TOKCAT(x, y) TGR_CAT(x, y)
#define __runLoopCount TGR_TOKCAT(__runLoopCount,__LINE__)
#define TGRAssertEventually(a1, format...) \
NSUInteger __runLoopCount = 0; \
while (!(a1) && __runLoopCount < TGR_RUNLOOP_COUNT) { \
NSDate* date = [NSDate dateWithTimeIntervalSinceNow:TGR_RUNLOOP_INTERVAL]; \
[NSRunLoop.currentRunLoop runUntilDate:date]; \
__runLoopCount++; \
} \
if (__runLoopCount >= TGR_RUNLOOP_COUNT) { \
XCTFail(format); \
}
HCRVolume * __block volume = nil;
[[self.client fetchVolumeWithID:@"L9fpff1b4kwC"] subscribeNext:^(id x) {
volume = x;
}];
TGRAssertEventually(volume != nil, @"should complete with a response");
XCTAssertTrue([volume isKindOfClass:HCRVolume.class], @"should return a single volume");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment