Latest 1.0.2
Homepage https://github.com/tokorom/TKRGuard
License MIT
Frameworks XCTest, SenTestingKit
Authors

TKRGuard build Coverage Status

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!");
}

When you would like to use Kiwi

#import "Kiwi.h"
#define TKRGUARD_USE_KIWI
#import "TKRGuard.h"

SPEC_BEGIN(KiwiTests)

describe(@"Sample", ^{
    it(@"can test asynchronous functions", ^{
        __block id result = nil;
        [Sample asyncronousProsess:^(id res) {
            result = res;
            RESUME;
        }];

        WAIT;
        [[result should] equal:@"OK"];
    });
});

SPEC_END

Setup

Using CocoaPods

// Podfile
target :YourTestsTarget do
  pod 'TKRGuard'
end

and

pod install

and

#import "TKRGuard.h"

Install manually

Add TKRGuard subdirectory to your project.

and

#import "TKRGuard.h"

Latest podspec

{
    "name": "TKRGuard",
    "version": "1.0.2",
    "summary": "The simple test helper for asynchronous processes.",
    "homepage": "https://github.com/tokorom/TKRGuard",
    "license": "MIT",
    "authors": {
        "tokorom": "[email protected]"
    },
    "source": {
        "git": "https://github.com/tokorom/TKRGuard.git",
        "tag": "1.0.2"
    },
    "source_files": "TKRGuard/*",
    "frameworks": [
        "XCTest",
        "SenTestingKit"
    ],
    "requires_arc": true
}

Pin It on Pinterest

Share This