Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Experimental feature: concise auto mocking, with less setup needed

  • Loading branch information...
commit 5f4b8cf32b5f2829d5713e56809e51dc52951826 1 parent 4cdb09d
@lukeredpath authored
View
14 BasicExamples.m
@@ -13,6 +13,7 @@
#import <SenTestingKit/SenTestingKit.h>
#import "OCHamcrest.h"
#import "LRMocky.h"
+#import "LRMockyAutomation.h"
#import "TestHelper.h"
@interface BasicExamples : SenTestCase
@@ -231,4 +232,17 @@ - (void)testStubbedClassMethodIsRestoredAfterContextAssertSatisfied
assertThat([SimpleObject factoryMethod], is(nilValue()));
}
+- (void)testBasicMockingWithMockeryAutomation
+{
+ id myMockString = [automock mock:[NSString class] named:@"My Mock String"];
+
+ check(^(that) {
+ [[oneOf(myMockString) receives] uppercaseString];
+ });
+
+ verifyWith(^{
+ [myMockString uppercaseString];
+ });
+}
+
@end
View
29 Classes/LRMocky/LRMockyAutomation.h
@@ -0,0 +1,29 @@
+//
+// LRMockyAutomation.h
+// Timeslips
+//
+// Created by Luke Redpath on 05/03/2012.
+// Copyright (c) 2012 LJR Software Limited. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+#define LRMOCKY_SUGAR
+#define LRMOCKY_KIWI_COMPATIBILITY_MODE
+#import "LRMocky.h"
+
+void LRM_check(id testCase, void (^expectationBlock)(LRExpectationBuilder *));
+void LRM_verify(NSString *fileName, int lineNumber, void (^block)(void));
+LRMockery *LRM_automock(id testCase);
+
+@interface LRMockeryAutomation : NSObject
++ (id)sharedAutomation;
+- (void)prepareContextForTestCase:(id)testCase;
+- (void)checking:(void (^)(LRExpectationBuilder *))expectationBlock;
+- (void)verify:(void (^)(void))block fileName:(NSString *)fileName lineNumber:(int)lineNumber;
+- (LRMockery *)mockery;
+@end
+
+#define automock LRM_automock(self)
+#define check(block) LRM_check(self, block)
+#define verifyWith(block) LRM_verify([NSString stringWithUTF8String:__FILE__], __LINE__, block)
View
66 Classes/LRMocky/LRMockyAutomation.m
@@ -0,0 +1,66 @@
+//
+// LRMockyAutomation.m
+// Timeslips
+//
+// Created by Luke Redpath on 05/03/2012.
+// Copyright (c) 2012 LJR Software Limited. All rights reserved.
+//
+
+#import "LRMockyAutomation.h"
+
+@implementation LRMockeryAutomation {
+ LRMockery *mockery;
+}
+
++ (id)sharedAutomation
+{
+ static LRMockeryAutomation *__sharedAutomation = nil;
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ __sharedAutomation = [[LRMockeryAutomation alloc] init];
+ });
+ return __sharedAutomation;
+}
+
+- (void)prepareContextForTestCase:(id)testCase
+{
+ if (mockery == nil) {
+ mockery = [LRMockery mockeryForTestCase:testCase];
+ }
+}
+
+- (void)checking:(void (^)(LRExpectationBuilder *))expectationBlock
+{
+ [mockery checking:expectationBlock];
+}
+
+- (void)verify:(void (^)(void))block fileName:(NSString *)fileName lineNumber:(int)lineNumber
+{
+ block();
+ LRM_assertContextSatisfied(mockery, fileName, lineNumber);
+ mockery = nil;
+}
+
+- (LRMockery *)mockery
+{
+ return mockery;
+}
+
+@end
+
+void LRM_check(id testCase, void (^expectationBlock)(LRExpectationBuilder *))
+{
+ [[LRMockeryAutomation sharedAutomation] prepareContextForTestCase:testCase];
+ [[LRMockeryAutomation sharedAutomation] checking:expectationBlock];
+}
+
+void LRM_verify(NSString *fileName, int lineNumber, void (^block)(void))
+{
+ [[LRMockeryAutomation sharedAutomation] verify:block fileName:fileName lineNumber:lineNumber];
+}
+
+LRMockery *LRM_automock(id testCase)
+{
+ [[LRMockeryAutomation sharedAutomation] prepareContextForTestCase:testCase];
+ return [[LRMockeryAutomation sharedAutomation] mockery];
+}
View
12 Mocky.xcodeproj/project.pbxproj
@@ -86,6 +86,8 @@
A3D496E31210D0070076940C /* ExpectationsWithDifferentArgumentsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A3D496D91210CF910076940C /* ExpectationsWithDifferentArgumentsTest.m */; };
A3EE4F5211FF1B7C002DA61D /* HamcrestIntegrationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A3EE4F5111FF1B7C002DA61D /* HamcrestIntegrationTest.m */; };
A3EE4F5911FF1C10002DA61D /* FunctionalMockeryTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = A3EE4F5811FF1C0F002DA61D /* FunctionalMockeryTestCase.m */; };
+ A3F962441505869F003051DD /* LRMockyAutomation.h in Headers */ = {isa = PBXBuildFile; fileRef = A3F962421505869F003051DD /* LRMockyAutomation.h */; };
+ A3F962451505869F003051DD /* LRMockyAutomation.m in Sources */ = {isa = PBXBuildFile; fileRef = A3F962431505869F003051DD /* LRMockyAutomation.m */; };
AA747D9F0F9514B9006C5449 /* Mocky_Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = AA747D9E0F9514B9006C5449 /* Mocky_Prefix.pch */; settings = {ATTRIBUTES = (); }; };
AACBBE4A0F95108600F1A2B1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AACBBE490F95108600F1A2B1 /* Foundation.framework */; };
/* End PBXBuildFile section */
@@ -195,6 +197,8 @@
A3EE4F5111FF1B7C002DA61D /* HamcrestIntegrationTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HamcrestIntegrationTest.m; sourceTree = "<group>"; };
A3EE4F5711FF1C0F002DA61D /* FunctionalMockeryTestCase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FunctionalMockeryTestCase.h; sourceTree = "<group>"; };
A3EE4F5811FF1C0F002DA61D /* FunctionalMockeryTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FunctionalMockeryTestCase.m; sourceTree = "<group>"; };
+ A3F962421505869F003051DD /* LRMockyAutomation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LRMockyAutomation.h; sourceTree = "<group>"; };
+ A3F962431505869F003051DD /* LRMockyAutomation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LRMockyAutomation.m; sourceTree = "<group>"; };
AA747D9E0F9514B9006C5449 /* Mocky_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Mocky_Prefix.pch; sourceTree = "<group>"; };
AACBBE490F95108600F1A2B1 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
D2AAC07E0554694100DB518D /* libMocky.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libMocky.a; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -307,6 +311,8 @@
A391557A11FF670500FE7C49 /* LRDescribable.h */,
A3C66A42120249240004F78B /* LRMockyStates.h */,
A36F414A142962C4004EAA45 /* LRHamcrestSupport.h */,
+ A3F962421505869F003051DD /* LRMockyAutomation.h */,
+ A3F962431505869F003051DD /* LRMockyAutomation.m */,
);
path = LRMocky;
sourceTree = "<group>";
@@ -511,6 +517,7 @@
A38AFFC5122BFD020001D038 /* NSInvocation+LRAdditions.h in Headers */,
A3289A3C122C73B100D89A88 /* LRNotificationExpectation.h in Headers */,
A36F414B142962C4004EAA45 /* LRHamcrestSupport.h in Headers */,
+ A3F962441505869F003051DD /* LRMockyAutomation.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -727,6 +734,7 @@
A38AFDFC122BEC2E0001D038 /* LRPerformBlockArgumentAction.m in Sources */,
A38AFFC6122BFD020001D038 /* NSInvocation+LRAdditions.m in Sources */,
A3289A3D122C73B100D89A88 /* LRNotificationExpectation.m in Sources */,
+ A3F962451505869F003051DD /* LRMockyAutomation.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -763,6 +771,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = Mocky_Prefix.pch;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+ GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
INSTALL_PATH = /usr/local/lib;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = Mocky;
@@ -784,6 +793,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = Mocky_Prefix.pch;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+ GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
INSTALL_PATH = /usr/local/lib;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = Mocky;
@@ -798,7 +808,6 @@
GCC_C_LANGUAGE_STANDARD = c99;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
- GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
@@ -813,7 +822,6 @@
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
GCC_C_LANGUAGE_STANDARD = c99;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
- GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
View
2  Mocky.xcodeproj/xcshareddata/xcschemes/Mocky Examples.xcscheme
@@ -42,7 +42,7 @@
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
- selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.GDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
Please sign in to comment.
Something went wrong with that request. Please try again.