GithubHelp home page GithubHelp logo

paultaykalo / cedarasync Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cppforlife/cedarasync

0.0 2.0 0.0 1.16 MB

asynchronous testing for Cedar (and others)

Objective-C 43.60% C++ 51.56% C 4.84%

cedarasync's Introduction

CedarAsync lets you use Cedar matchers to test asynchronous code. This becomes useful when writing intergration tests rather than plain unit tests. (CedarAsync only supports Cedar's should syntax.)

Instead of

client.lastResponse should contain(@"Google");

use

in_time(client.lastResponse) should contain(@"Google");

to force contain matcher check client.lastResponse multiple times until it succeeds or times out.

Example

#import "CedarAsync.h"
#import "HTTPClient.h"

SPEC_BEGIN(HTTPClientSpec)

using namespace Cedar::Matchers;

describe(@"HTTPClient", ^{
    __block HTTPClient *client;
    
    beforeEach(^{
        client = [[[HTTPClient alloc] init] autorelease];
    });
    
    it(@"can fetch google's homepage", ^{
        // uses NSURLRequest internally
        [client fetchURLString:@"http://google.com"];
        
        // plain Cedar matcher use - does not wait
        // (passes immediately since it takes sometime to fetch google)
        client.lastResponse should be_nil;
        
        // async matcher use - waits for lastResponse to contain 'Google'
        in_time(client.lastResponse) should contain(@"Google");
    });
});

SPEC_END

Timeout & Polling Interval

Temporarily change timeout and polling interval:

CedarAsync::Timing::current_timeout = 4; // seconds
CedarAsync::Timing::current_poll = 0.3;  // seconds

or

with_timeout(10, ^{
    in_time(valueThatTakesForever) should equal(@"so large...");
});

Change default timeout and polling interval (these values are used to populate current_timeout and current_poll before every test run):

CedarAsync::Timing::default_timeout = 4; // seconds
CedarAsync::Timing::default_poll = 2;    // seconds

Todo

  • clean up queued up actions on NSRunLoop, GCD, etc. after every test

cedarasync's People

Contributors

cppforlife avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.