tkr

TKRGuard

The simple test helper for asynchronous processes

Showing:

Popularity

Downloads/wk

0

GitHub Stars

47

Maintenance

Last Commit

7yrs ago

Contributors

1

Package

Dependencies

0

License

MIT

Categories

Readme

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"

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100