diff --git a/Source/OCMock.xcodeproj/project.pbxproj b/Source/OCMock.xcodeproj/project.pbxproj index b72a587b..8bb3b7a6 100644 --- a/Source/OCMock.xcodeproj/project.pbxproj +++ b/Source/OCMock.xcodeproj/project.pbxproj @@ -138,7 +138,6 @@ 03C7BF11195DAB5300A545DD /* OCMExpectationRecorder.h in Headers */ = {isa = PBXBuildFile; fileRef = 03C7BF0E195DAB5300A545DD /* OCMExpectationRecorder.h */; }; 03C7BF12195DAB5300A545DD /* OCMExpectationRecorder.m in Sources */ = {isa = PBXBuildFile; fileRef = 03C7BF0F195DAB5300A545DD /* OCMExpectationRecorder.m */; }; 03C7BF13195DAB5300A545DD /* OCMExpectationRecorder.m in Sources */ = {isa = PBXBuildFile; fileRef = 03C7BF0F195DAB5300A545DD /* OCMExpectationRecorder.m */; }; - 03C7BF1619606E7A00A545DD /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 03565A1D18F05626003AE91E /* XCTest.framework */; }; 03C7BF1719606EFD00A545DD /* OCMock.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 030EF0A814632FD000B04273 /* OCMock.framework */; }; 03C9CA1D18F05A75006DF94D /* OCMockObjectProtocolMocksTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2FA286BFBD8B9D068B41E7EF /* OCMockObjectProtocolMocksTests.m */; }; 03C9CA1E18F05A84006DF94D /* OCMArgTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2FA28EDBF243639C57F88A1B /* OCMArgTests.m */; }; @@ -281,6 +280,12 @@ 817EB1661BD7674D0047E85A /* OCMFunctionsPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 03F370CA1BAA1DE800CAD3E8 /* OCMFunctionsPrivate.h */; }; 8BF73E53246CA75E00B9A52C /* OCMNoEscapeBlockTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BF73E52246CA75E00B9A52C /* OCMNoEscapeBlockTests.m */; settings = {COMPILER_FLAGS = "-Xclang -fexperimental-optimized-noescape"; }; }; 8BF73E54246CA75E00B9A52C /* OCMNoEscapeBlockTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BF73E52246CA75E00B9A52C /* OCMNoEscapeBlockTests.m */; settings = {COMPILER_FLAGS = "-Xclang -fexperimental-optimized-noescape"; }; }; + 8BF7401E24772AEA00B9A52C /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 03565A1D18F05626003AE91E /* XCTest.framework */; }; + 8BF7402024772B0500B9A52C /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 03565A1D18F05626003AE91E /* XCTest.framework */; }; + 8BF7402124772B0600B9A52C /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 03565A1D18F05626003AE91E /* XCTest.framework */; }; + 8BF7402224772B0800B9A52C /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 03565A1D18F05626003AE91E /* XCTest.framework */; }; + 8BF7402324772B0800B9A52C /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 03565A1D18F05626003AE91E /* XCTest.framework */; }; + 8BF7402424772B0900B9A52C /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 03565A1D18F05626003AE91E /* XCTest.framework */; }; 8DE97C5522B43EE60098C63F /* OCMockObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 03B3159E146333BF0052CD09 /* OCMockObject.m */; }; 8DE97C5622B43EE60098C63F /* OCClassMockObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 03B3158C146333BF0052CD09 /* OCClassMockObject.m */; }; 8DE97C5722B43EE60098C63F /* OCPartialMockObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 03B315AA146333BF0052CD09 /* OCPartialMockObject.m */; }; @@ -589,6 +594,7 @@ buildActionMask = 2147483647; files = ( 033E1FF414FEF5E0004456B0 /* Foundation.framework in Frameworks */, + 8BF7402124772B0600B9A52C /* XCTest.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -596,6 +602,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 8BF7401E24772AEA00B9A52C /* XCTest.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -603,8 +610,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 03C7BF1619606E7A00A545DD /* XCTest.framework in Frameworks */, 03C7BF1719606EFD00A545DD /* OCMock.framework in Frameworks */, + 8BF7402024772B0500B9A52C /* XCTest.framework in Frameworks */, 03CED2E32390770C001845CC /* OCHamcrest.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -614,6 +621,7 @@ buildActionMask = 2147483647; files = ( 817EB1391BD765130047E85A /* Foundation.framework in Frameworks */, + 8BF7402324772B0800B9A52C /* XCTest.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -622,6 +630,7 @@ buildActionMask = 2147483647; files = ( 8DE97C7722B43EE60098C63F /* Foundation.framework in Frameworks */, + 8BF7402424772B0900B9A52C /* XCTest.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -638,6 +647,7 @@ buildActionMask = 2147483647; files = ( F0B9510B1B0080D500942C38 /* Foundation.framework in Frameworks */, + 8BF7402224772B0800B9A52C /* XCTest.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Source/OCMock/OCMStubRecorder.h b/Source/OCMock/OCMStubRecorder.h index 16557fe3..bec12a7b 100644 --- a/Source/OCMock/OCMStubRecorder.h +++ b/Source/OCMock/OCMStubRecorder.h @@ -18,6 +18,8 @@ #import #import +@class XCTestExpectation; + @interface OCMStubRecorder : OCMRecorder - (id)andReturn:(id)anObject; @@ -27,6 +29,7 @@ - (id)andCall:(SEL)selector onObject:(id)anObject; - (id)andDo:(void (^)(NSInvocation *invocation))block; - (id)andForwardToRealObject; +- (id)andFulfill:(XCTestExpectation *)expectation; @end @@ -58,6 +61,9 @@ #define andForwardToRealObject() _andForwardToRealObject() @property (nonatomic, readonly) OCMStubRecorder *(^ _andForwardToRealObject)(void); +#define andFulfill(anExpectation) _andFulfill(anExpectation) +@property(nonatomic, readonly) OCMStubRecorder * (^_andFulfill)(XCTestExpectation *); + @property (nonatomic, readonly) OCMStubRecorder *(^ _ignoringNonObjectArgs)(void); @end diff --git a/Source/OCMock/OCMStubRecorder.m b/Source/OCMock/OCMStubRecorder.m index 9756129f..ca33b82d 100644 --- a/Source/OCMock/OCMStubRecorder.m +++ b/Source/OCMock/OCMStubRecorder.m @@ -25,6 +25,7 @@ #import "OCMRealObjectForwarder.h" #import "OCMInvocationStub.h" +#import @implementation OCMStubRecorder @@ -99,6 +100,12 @@ - (id)andForwardToRealObject return self; } +- (id)andFulfill:(XCTestExpectation *)expectation { + return [self andDo:^(NSInvocation *invocation) { + [expectation fulfill]; + }]; +} + #pragma mark Finishing recording @@ -194,5 +201,15 @@ @implementation OCMStubRecorder (Properties) return [[theBlock copy] autorelease]; } +@dynamic _andFulfill; + +- (OCMStubRecorder * (^)(XCTestExpectation *))_andFulfill { + id (^theBlock)(XCTestExpectation *) = ^ (XCTestExpectation *expectation) + { + return [self andFulfill:expectation]; + }; + return [[theBlock copy] autorelease]; +} + @end diff --git a/Source/OCMockTests/OCMockObjectMacroTests.m b/Source/OCMockTests/OCMockObjectMacroTests.m index c4ba9f87..d57a0783 100644 --- a/Source/OCMockTests/OCMockObjectMacroTests.m +++ b/Source/OCMockTests/OCMockObjectMacroTests.m @@ -231,6 +231,15 @@ - (void)testSetsUpSubstituteCall XCTAssertEqualObjects([mock stringValue], @"TEST_STRING_FROM_TESTCASE", @"Should have called method from test case"); } +- (void)testFulfillsExpectation +{ + id mock = OCMStrictClassMock([NSString class]); + + OCMStub([mock boolValue]).andFulfill([self expectationWithDescription:@"Expectation Called"]); + [mock boolValue]; + [self waitForExpectationsWithTimeout:0 handler:nil]; +} + - (NSString *)stringValueForTesting { return @"TEST_STRING_FROM_TESTCASE"; @@ -493,6 +502,7 @@ - (void)testReturnsCorrectObjectFromInitMethodCalledOnRecorderInsideMacro OCMStub([[mock andThrow:nil] initWithString:OCMOCK_ANY]); OCMStub([[mock andPost:nil] initWithString:OCMOCK_ANY]); OCMStub([[mock andCall:nil onObject:nil] initWithString:OCMOCK_ANY]); + OCMStub([[mock andFulfill:nil] initWithString:OCMOCK_ANY]); OCMStub([[mock andDo:nil] initWithString:OCMOCK_ANY]); OCMStub([[mock andForwardToRealObject] initWithString:OCMOCK_ANY]); OCMExpect([[mock never] initWithString:OCMOCK_ANY]);