Permalink
Browse files

add readme

  • Loading branch information...
1 parent ffa5bdd commit 5d6112c6401984b00755eb2eb808dd83a64962d9 @cppforlife committed Oct 23, 2012
Showing with 70 additions and 0 deletions.
  1. +2 −0 CedarAsync.xcodeproj/project.pbxproj
  2. +68 −0 README.md
@@ -94,6 +94,7 @@
96D6ECE81633347C00F26774 /* HTTPClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HTTPClient.m; sourceTree = "<group>"; };
96D6ECEA16333A1E00F26774 /* TimeoutSpec.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TimeoutSpec.mm; sourceTree = "<group>"; };
96D6ECEE1633415E00F26774 /* Timing.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Timing.mm; sourceTree = "<group>"; };
+ 96FF918F163642EB0003A779 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = text; path = README.md; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -132,6 +133,7 @@
961EB7FA1633C1EB0062EDA0 = {
isa = PBXGroup;
children = (
+ 96FF918F163642EB0003A779 /* README.md */,
961EB8361633C1EB0062EDA0 /* Source */,
96D6ECA31633236A00F26774 /* CedarAsyncSpecs */,
96BB77881633225B00D441EB /* External */,
View
@@ -0,0 +1,68 @@
+CedarAsync lets you use [Cedar](http://github.com/pivotal/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

0 comments on commit 5d6112c

Please sign in to comment.