File tree Expand file tree Collapse file tree 5 files changed +45
-0
lines changed Expand file tree Collapse file tree 5 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ OCMock 3.3 (unreleased)
5
5
6
6
* Made the use of mock objects thread safe. You still have to setup the mocks
7
7
and verify them from a main thread (Ian Anderson)
8
+ * Added modern syntax for reject (Piotr Tobolski)
8
9
9
10
10
11
OCMock 3.2.2 (2016-01-20)
Original file line number Diff line number Diff line change 33
33
+ (void )beginExpectMacro ;
34
34
+ (OCMStubRecorder *)endExpectMacro ;
35
35
36
+ + (void )beginRejectMacro ;
37
+ + (OCMStubRecorder *)endRejectMacro ;
38
+
36
39
+ (void )beginVerifyMacroAtLocation : (OCMLocation *)aLocation ;
37
40
+ (void )endVerifyMacro ;
38
41
Original file line number Diff line number Diff line change @@ -60,6 +60,21 @@ + (OCMStubRecorder *)endExpectMacro
60
60
}
61
61
62
62
63
+ + (void )beginRejectMacro
64
+ {
65
+ OCMExpectationRecorder *recorder = [[[OCMExpectationRecorder alloc ] init ] autorelease ];
66
+ [recorder never ];
67
+ OCMMacroState *macroState = [[OCMMacroState alloc ] initWithRecorder: recorder];
68
+ [NSThread currentThread ].threadDictionary [OCMGlobalStateKey] = macroState;
69
+ [macroState release ];
70
+ }
71
+
72
+ + (OCMStubRecorder *)endRejectMacro
73
+ {
74
+ return [self endStubMacro ];
75
+ }
76
+
77
+
63
78
+ (void )beginVerifyMacroAtLocation : (OCMLocation *)aLocation
64
79
{
65
80
OCMVerifier *recorder = [[[OCMVerifier alloc ] init ] autorelease ];
Original file line number Diff line number Diff line change 66
66
); \
67
67
})
68
68
69
+ #define OCMReject (invocation ) \
70
+ ({ \
71
+ _OCMSilenceWarnings ( \
72
+ [OCMMacroState beginRejectMacro ]; \
73
+ OCMStubRecorder *recorder = nil ; \
74
+ @try { \
75
+ invocation; \
76
+ }@finally { \
77
+ recorder = [OCMMacroState endRejectMacro ]; \
78
+ } \
79
+ recorder; \
80
+ ); \
81
+ })
82
+
69
83
#define ClassMethod (invocation ) \
70
84
_OCMSilenceWarnings ( \
71
85
[[OCMMacroState globalState ] switchToClassMethod ]; \
Original file line number Diff line number Diff line change @@ -268,6 +268,18 @@ - (void)testSetsUpExpectations
268
268
}
269
269
270
270
271
+ - (void )testSetsUpReject
272
+ {
273
+ id mock = OCMClassMock ([TestClassForMacroTesting class ]);
274
+
275
+ OCMReject ([mock stringValue ]);
276
+
277
+ XCTAssertNoThrow ([mock verify ], @" Should have accepted invocation rejected method not being invoked" );
278
+ XCTAssertThrows ([mock stringValue ], @" Should have complained during rejected method being invoked" );
279
+ XCTAssertThrows ([mock verify ], @" Should have complained about rejected method being invoked" );
280
+ }
281
+
282
+
271
283
- (void )testShouldNotReportErrorWhenMethodWasInvoked
272
284
{
273
285
id mock = OCMClassMock ([NSString class ]);
You can’t perform that action at this time.
0 commit comments