TKRGuard 1.0.2

TKRGuard 1.0.2

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Dec 2014

Maintained by Unclaimed.


Downloads

Total1,431
Week0
Month0

Installs

Apps5
Test Targets33
powered by Segment

GitHub

Stars47
Watchers2
Forks1
Issues0
Contributors1
Pull Requests0

Code

Files5
LOCLines of Code 235


TKRGuard 1.0.2

  • By
  • tokorom

The simple test helper for asynchronous processes.

Usage

All you need to use only WAIT and RESUME.

- (void)testExample
{
    __block NSString *response = nil;
    [self requestGetAsyncronous:^(id res, NSError *error) {
        response = res;
        RESUME;
    }];

    WAIT;
    XCTAssertEqualObjects(response, @"OK!");
}

Advanced Examples

When you want to notify a status (like a GHUnit).

- (void)testExample
{
    [self requestGetAsyncronous:^(id res, NSError *error) {
        if (error) {
            RESUME_WITH(TKRGuardStatusFailure);
        } else {
            RESUME_WITH(TKRGuardStatusSuccess);
        }
    }];

    WAIT_FOR(TKRGuardStatusSuccess);
}

When you want to change the default timeout interval.

// default is 1.0
[TKRGuard setDefaultTimeoutInterval:2.0];

When you want to wait some resumes

    __block NSString *response1 = nil;
    [self requestGetAsyncronous:^(id res, NSError *error) {
        response1 = res;
        RESUME;
    }];
    __block NSString *response2 = nil;
    [self requestGetAsyncronous:^(id res, NSError *error) {
        response2 = res;
        RESUME;
    }];

    WAIT_TIMES(2);
    XCTAssertEqualObjects(response1, @"1");
    XCTAssertEqualObjects(response2, @"2");

When you do not want to use the shorthand macro.

#define UNUSE_TKRGUARD_SHORTHAND

- (void)testExample
{
    __block id result = nil;
    [self requestGetAsyncronous:^(id res, NSError *error) {
        result = res;
        [TKRGuard resumeForKey:@"xxx"];
    }];

    [TKRGuard waitWithTimeout:1.0 forKey:@"xxx"];
    XCTAssertEqualObjects(response, @"OK!");
}

Setup

Install manually

Add TKRGuard subdirectory to your project.

and

#import "TKRGuard.h"