Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit ffa5bddb42cfa4b5980b7e411219fd99ff6fa806 @cppforlife committed Oct 23, 2012
Showing with 3,516 additions and 0 deletions.
  1. +7 −0 .gitignore
  2. +684 −0 CedarAsync.xcodeproj/project.pbxproj
  3. +28 −0 CedarAsync/CedarAsync-Info.plist
  4. +32 −0 CedarAsyncSpecs/CedarAsyncSpecs-Info.plist
  5. +9 −0 CedarAsyncSpecs/CedarAsyncSpecs-Prefix.pch
  6. +86 −0 CedarAsyncSpecs/InTimeShouldSyntaxSpec.mm
  7. +25 −0 CedarAsyncSpecs/NSURLRequestSpec.mm
  8. +96 −0 CedarAsyncSpecs/PollingSpec.mm
  9. +10 −0 CedarAsyncSpecs/Support/AsyncAction.h
  10. +53 −0 CedarAsyncSpecs/Support/AsyncAction.mm
  11. +7 −0 CedarAsyncSpecs/Support/ExpectCallLength.h
  12. +17 −0 CedarAsyncSpecs/Support/ExpectCallLength.mm
  13. +5 −0 CedarAsyncSpecs/Support/ExpectFailureWithMessage.h
  14. +14 −0 CedarAsyncSpecs/Support/ExpectFailureWithMessage.m
  15. +7 −0 CedarAsyncSpecs/Support/HTTPClient.h
  16. +34 −0 CedarAsyncSpecs/Support/HTTPClient.m
  17. +75 −0 CedarAsyncSpecs/TimeoutSpec.mm
  18. +18 −0 CedarAsyncSpecs/main.m
  19. +1 −0 External/Cedar-iOS.framework/Cedar-iOS
  20. +1 −0 External/Cedar-iOS.framework/Headers
  21. +1 −0 External/Cedar-iOS.framework/Resources
  22. BIN External/Cedar-iOS.framework/Versions/A/Cedar-iOS
  23. +118 −0 External/Cedar-iOS.framework/Versions/A/Headers/ActualValue.h
  24. +27 −0 External/Cedar-iOS.framework/Versions/A/Headers/AnyArgument.h
  25. +29 −0 External/Cedar-iOS.framework/Versions/A/Headers/AnyInstanceArgument.h
  26. +26 −0 External/Cedar-iOS.framework/Versions/A/Headers/Argument.h
  27. +55 −0 External/Cedar-iOS.framework/Versions/A/Headers/Base.h
  28. +81 −0 External/Cedar-iOS.framework/Versions/A/Headers/BeCloseTo.h
  29. +29 −0 External/Cedar-iOS.framework/Versions/A/Headers/BeEmpty.h
  30. +67 −0 External/Cedar-iOS.framework/Versions/A/Headers/BeGTE.h
  31. +62 −0 External/Cedar-iOS.framework/Versions/A/Headers/BeGreaterThan.h
  32. +65 −0 External/Cedar-iOS.framework/Versions/A/Headers/BeInstanceOf.h
  33. +67 −0 External/Cedar-iOS.framework/Versions/A/Headers/BeLTE.h
  34. +62 −0 External/Cedar-iOS.framework/Versions/A/Headers/BeLessThan.h
  35. +55 −0 External/Cedar-iOS.framework/Versions/A/Headers/BeNil.h
  36. +59 −0 External/Cedar-iOS.framework/Versions/A/Headers/BeSameInstanceAs.h
  37. +31 −0 External/Cedar-iOS.framework/Versions/A/Headers/BeTruthy.h
  38. +9 −0 External/Cedar-iOS.framework/Versions/A/Headers/CDRClassFake.h
  39. +6 −0 External/Cedar-iOS.framework/Versions/A/Headers/CDRColorizedReporter.h
  40. +47 −0 External/Cedar-iOS.framework/Versions/A/Headers/CDRExampleBase.h
  41. +12 −0 External/Cedar-iOS.framework/Versions/A/Headers/CDRExampleDetailsViewController.h
  42. +16 −0 External/Cedar-iOS.framework/Versions/A/Headers/CDRExampleParent.h
  43. +9 −0 External/Cedar-iOS.framework/Versions/A/Headers/CDRExampleReporter.h
  44. +7 −0 External/Cedar-iOS.framework/Versions/A/Headers/CDRExampleReporterViewController.h
  45. +15 −0 External/Cedar-iOS.framework/Versions/A/Headers/CDRFake.h
  46. +8 −0 External/Cedar-iOS.framework/Versions/A/Headers/CDRFunctions.h
  47. +14 −0 External/Cedar-iOS.framework/Versions/A/Headers/CDRProtocolFake.h
  48. +32 −0 External/Cedar-iOS.framework/Versions/A/Headers/CDRSharedExampleGroupPool.h
  49. +7 −0 External/Cedar-iOS.framework/Versions/A/Headers/CDRSlowTestStatistics.h
  50. +70 −0 External/Cedar-iOS.framework/Versions/A/Headers/CDRSpec.h
  51. +19 −0 External/Cedar-iOS.framework/Versions/A/Headers/CDRSpecFailure.h
  52. +20 −0 External/Cedar-iOS.framework/Versions/A/Headers/CDRSpy.h
  53. +3 −0 External/Cedar-iOS.framework/Versions/A/Headers/Cedar-iOS.h
  54. +1 −0 External/Cedar-iOS.framework/Versions/A/Headers/Cedar.h
  55. +22 −0 External/Cedar-iOS.framework/Versions/A/Headers/CedarApplicationDelegate.h
  56. +6 −0 External/Cedar-iOS.framework/Versions/A/Headers/CedarComparators.h
  57. +29 −0 External/Cedar-iOS.framework/Versions/A/Headers/CedarDouble.h
  58. +19 −0 External/Cedar-iOS.framework/Versions/A/Headers/CedarDoubleImpl.h
  59. +11 −0 External/Cedar-iOS.framework/Versions/A/Headers/CedarDoubles.h
  60. +20 −0 External/Cedar-iOS.framework/Versions/A/Headers/CedarMatchers.h
  61. +6 −0 External/Cedar-iOS.framework/Versions/A/Headers/CedarStringifiers.h
  62. +2 −0 External/Cedar-iOS.framework/Versions/A/Headers/ComparatorsBase.h
  63. +94 −0 External/Cedar-iOS.framework/Versions/A/Headers/ComparatorsContainer.h
  64. +50 −0 External/Cedar-iOS.framework/Versions/A/Headers/CompareEqual.h
  65. +54 −0 External/Cedar-iOS.framework/Versions/A/Headers/CompareGreaterThan.h
  66. +49 −0 External/Cedar-iOS.framework/Versions/A/Headers/Contain.h
  67. +73 −0 External/Cedar-iOS.framework/Versions/A/Headers/Equal.h
  68. +48 −0 External/Cedar-iOS.framework/Versions/A/Headers/HaveReceived.h
  69. +43 −0 External/Cedar-iOS.framework/Versions/A/Headers/InvocationMatcher.h
  70. +54 −0 External/Cedar-iOS.framework/Versions/A/Headers/RaiseException.h
  71. +28 −0 External/Cedar-iOS.framework/Versions/A/Headers/ReturnValue.h
  72. +30 −0 External/Cedar-iOS.framework/Versions/A/Headers/ShouldSyntax.h
  73. +18 −0 External/Cedar-iOS.framework/Versions/A/Headers/SpecHelper.h
  74. +32 −0 External/Cedar-iOS.framework/Versions/A/Headers/StringifiersBase.h
  75. +47 −0 External/Cedar-iOS.framework/Versions/A/Headers/StringifiersContainer.h
  76. +86 −0 External/Cedar-iOS.framework/Versions/A/Headers/StubbedMethod.h
  77. +83 −0 External/Cedar-iOS.framework/Versions/A/Headers/StubbedMethod.mm
  78. +82 −0 External/Cedar-iOS.framework/Versions/A/Headers/ValueArgument.h
  79. +1 −0 External/Cedar-iOS.framework/Versions/Current
  80. +91 −0 Source/Headers/AsyncActualValue.h
  81. +7 −0 Source/Headers/CedarAsync.h
  82. +29 −0 Source/Headers/InTimeShouldSyntax.h
  83. +21 −0 Source/Headers/Timing.h
  84. +43 −0 Source/Timing.mm
@@ -0,0 +1,7 @@
+*.mode1v3
+*.pbxuser
+*.xcworkspace
+xcuserdata
+build
+.DS_Store
+.idea
Oops, something went wrong.
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIconFile</key>
+ <string></string>
+ <key>CFBundleIdentifier</key>
+ <string>com.tomato.${PRODUCT_NAME:rfc1034identifier}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>FMWK</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+ <key>NSPrincipalClass</key>
+ <string></string>
+</dict>
+</plist>
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleDisplayName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.tomato.${PRODUCT_NAME:rfc1034identifier}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+ <key>LSRequiresIPhoneOS</key>
+ <true/>
+ <key>UIRequiredDeviceCapabilities</key>
+ <array>
+ <string>armv7</string>
+ </array>
+</dict>
+</plist>
@@ -0,0 +1,9 @@
+//
+// Prefix header for all source files of the 'CedarAsyncSpecs' target in the 'CedarAsyncSpecs' project
+//
+
+#ifdef __OBJC__
+ #import <UIKit/UIKit.h>
+ #import <Foundation/Foundation.h>
+ #import <Cedar-iOS/SpecHelper.h>
+#endif
@@ -0,0 +1,86 @@
+#import "CedarAsync.h"
+#import "AsyncAction.h"
+#import "ExpectCallLength.h"
+#import "ExpectFailureWithMessage.h"
+
+SPEC_BEGIN(InTimeSyntaxSpec)
+
+using namespace Cedar::Matchers;
+
+describe(@"in_time syntax", ^{
+ __block AsyncAction *action;
+
+ beforeEach(^{
+ action = [[[AsyncAction alloc] init] autorelease];
+ });
+
+ describe(@"positive matching", ^{
+ context(@"when actual initially matches expected value", ^{
+ it(@"reports a pass", ^{
+ [action start];
+ expectShortCallLength(^{
+ in_time(action.value) should equal(@"FROM");
+ });
+ });
+ });
+
+ context(@"when actual does not initially match expected value", ^{
+ context(@"when actual eventually matches expected value", ^{
+ it(@"reports a pass", ^{
+ [action start];
+ expectLongCallLength(^{
+ in_time(action.value) should equal(@"TO");
+ });
+ });
+ });
+
+ context(@"when actual does not eventually match expected value", ^{
+ it(@"reports a failure", ^{
+ [action start];
+ expectLongCallLength(^{
+ expectFailureWithMessage(@"Expected <TO> to equal <OTHER>", ^{
+ in_time(action.value) should equal(@"OTHER");
+ });
+ });
+ });
+ });
+ });
+ });
+
+ describe(@"negative matching", ^{
+ context(@"when actual does not initially match expected value", ^{
+ it(@"reports a pass", ^{
+ [action start];
+ expectShortCallLength(^{
+ in_time(action.value) should_not equal(@"OTHER");
+ });
+ });
+ });
+
+ context(@"when actual initially matches expected value", ^{
+ context(@"when actual eventually does not match expected value", ^{
+ it(@"reports a pass", ^{
+ [action start];
+ expectLongCallLength(^{
+ in_time(action.value) should_not equal(@"FROM");
+ });
+ });
+ });
+
+ context(@"when actual eventually matches expected value", ^{
+ it(@"reports a failure", ^{
+ action.to = @"FROM";
+ [action start];
+
+ expectLongCallLength(^{
+ expectFailureWithMessage(@"Expected <FROM> to not equal <FROM>", ^{
+ in_time(action.value) should_not equal(@"FROM");
+ });
+ });
+ });
+ });
+ });
+ });
+});
+
+SPEC_END
@@ -0,0 +1,25 @@
+#import "CedarAsync.h"
+#import "HTTPClient.h"
+
+SPEC_BEGIN(NSURLRequestSpec)
+
+using namespace Cedar::Matchers;
+
+describe(@"Works with NSURLRequest", ^{
+ __block HTTPClient *client;
+
+ beforeEach(^{
+ client = [[[HTTPClient alloc] init] autorelease];
+ });
+
+ it(@"fetches google's homepage", ^{
+ [client fetchURLString:@"http://google.com"];
+ client.lastResponse should be_nil;
+
+ with_timeout(4, ^{
+ in_time(client.lastResponse) should contain(@"Google");
+ });
+ });
+});
+
+SPEC_END
@@ -0,0 +1,96 @@
+#import "CedarAsync.h"
+#import "AsyncAction.h"
+#import "ExpectFailureWithMessage.h"
+
+SPEC_BEGIN(PollingSpec)
+
+using namespace Cedar::Matchers;
+
+describe(@"Polling", ^{
+ NSTimeInterval diff = CedarAsync::Timing::default_poll / 2;
+
+ __block AsyncAction *action;
+
+ beforeEach(^{
+ action = [[[AsyncAction alloc] init] autorelease];
+ });
+
+ it(@"uses default poll", ^{
+ Timing::current_poll should equal(Timing::default_poll);
+ Timing::current_poll should be_less_than(Timing::current_timeout);
+ Timing::current_poll should be_greater_than(0);
+ });
+
+ describe(@"with custom poll", ^{
+ beforeEach(^{
+ Timing::current_poll += diff;
+ });
+
+ context(@"when matching succeeds", ^{
+ void (^match)(void) = ^{
+ [action start];
+ in_time(action.value) should equal(@"TO");
+ };
+
+ context(@"when poll is greater than delay", ^{
+ it(@"makes a match in the beginning and right after delay", ^{
+ Timing::current_poll = action.delay + diff;
+ match();
+ action.valueCallCount should equal(2);
+ action.valueCallCountAfterChange should equal(1);
+ });
+ });
+
+ context(@"when poll is same as delay", ^{
+ it(@"makes a match in the beginning and exactly at the delay", ^{
+ Timing::current_poll = action.delay;
+ match();
+ action.valueCallCount should equal(2);
+ action.valueCallCountAfterChange should equal(1);
+ });
+ });
+
+ context(@"when poll is less than delay", ^{
+ it(@"makes a match in the beginning, before delay and right after delay", ^{
+ Timing::current_poll = action.delay - diff;
+ match();
+ action.valueCallCount should equal(3);
+ action.valueCallCountAfterChange should equal(1);
+ });
+ });
+ });
+
+ context(@"when matching does not succeed", ^{
+ void (^match)(void) = ^{
+ [action start];
+ @try { in_time(action.value) should equal(@"OTHER"); } @catch(id x) {}
+ };
+
+ context(@"when poll is greater than timeout", ^{
+ it(@"makes a match in the beginning and one at the end", ^{
+ Timing::current_poll = Timing::current_timeout + diff;
+ match();
+ action.valueCallCount should equal(2);
+ });
+ });
+
+ context(@"when poll is same as timeout", ^{
+ it(@"makes a match in the beginning and one at the end", ^{
+ Timing::current_poll = Timing::current_timeout;
+ match();
+ action.valueCallCount should equal(2);
+ });
+ });
+
+ context(@"when poll is less than timeout", ^{
+ it(@"makes a match in the beginning, in the middle and one at the end", ^{
+ Timing::current_poll = Timing::current_timeout - diff;
+ match();
+ action.valueCallCount should equal(3);
+ });
+ });
+ });
+ });
+});
+
+SPEC_END
@@ -0,0 +1,10 @@
+#import <Foundation/Foundation.h>
+
+@interface AsyncAction : NSObject
+@property (nonatomic, assign) NSTimeInterval delay;
+@property (nonatomic, retain) NSString *value, *from, *to;
+@property (nonatomic, assign) int valueCallCount;
+
+- (void)start;
+- (int)valueCallCountAfterChange;
+@end
@@ -0,0 +1,53 @@
+#import "AsyncAction.h"
+#import "Timing.h"
+
+@interface AsyncAction ()
+@property (nonatomic, assign) int valueCallCountAtChange;
+@end
+
+@implementation AsyncAction
+@synthesize
+ delay = delay_,
+ value = value_,
+ from = from_,
+ to = to_,
+ valueCallCount = valueCallCount_,
+ valueCallCountAtChange = valueCallCountAtChange_;
+
+- (id)init {
+ if (self = [super init]) {
+ self.delay = CedarAsync::Timing::default_timeout / 2;
+ self.from = @"FROM";
+ self.to = @"TO";
+ }
+ return self;
+}
+
+- (void)dealloc {
+ self.from = nil;
+ self.to = nil;
+ [super dealloc];
+}
+
+- (void)start {
+ self.value = self.from;
+ [self performSelector:@selector(end) withObject:nil afterDelay:self.delay];
+}
+
+- (void)end {
+ self.valueCallCountAtChange = self.valueCallCount;
+ self.value = self.to;
+}
+
+- (NSString *)value {
+ self.valueCallCount += 1;
+ return value_;
+}
+
+- (int)valueCallCountAfterChange {
+ if (self.valueCallCountAtChange > 0) {
+ return self.valueCallCount - self.valueCallCountAtChange;
+ }
+ return 0;
+}
+@end
@@ -0,0 +1,7 @@
+#import <Foundation/Foundation.h>
+
+__BEGIN_DECLS
+NSTimeInterval callLength(void(^call)(void));
+void expectShortCallLength(void(^call)(void));
+void expectLongCallLength(void(^call)(void));
+__END_DECLS
@@ -0,0 +1,17 @@
+#import "ExpectCallLength.h"
+
+using namespace Cedar::Matchers;
+
+NSTimeInterval callLength(void(^block)(void)) {
+ NSTimeInterval start = [[NSDate date] timeIntervalSince1970];
+ block();
+ return [[NSDate date] timeIntervalSince1970] - start;
+}
+
+void expectShortCallLength(void(^block)(void)) {
+ callLength(block) should be_less_than(0.001);
+}
+
+void expectLongCallLength(void(^block)(void)) {
+ callLength(block) should be_greater_than(0.001);
+}
@@ -0,0 +1,5 @@
+#import <Foundation/Foundation.h>
+
+__BEGIN_DECLS
+void expectFailureWithMessage(NSString *message, CDRSpecBlock block);
+__END_DECLS
Oops, something went wrong.

0 comments on commit ffa5bdd

Please sign in to comment.