@@ -25,9 +25,10 @@ @implementation OCMMacroState
2525
2626#pragma mark Methods to begin/end macros
2727
28- + (void )beginStubMacro
28+ + (void )beginStubMacroAtLocation : (OCMLocation *) aLocation
2929{
3030 OCMStubRecorder *recorder = [[[OCMStubRecorder alloc ] init ] autorelease ];
31+ recorder.ocm_location = aLocation;
3132 OCMMacroState *macroState = [[OCMMacroState alloc ] initWithRecorder: recorder];
3233 [NSThread currentThread ].threadDictionary [OCMGlobalStateKey] = macroState;
3334 [macroState release ];
@@ -40,21 +41,31 @@ + (OCMStubRecorder *)endStubMacro
4041 OCMStubRecorder *recorder = [[(OCMStubRecorder *)[globalState recorder ] retain ] autorelease ];
4142 BOOL didThrow = [globalState invocationDidThrow ];
4243 [threadDictionary removeObjectForKey: OCMGlobalStateKey];
43- if (didThrow == NO && [recorder wasUsed ] == NO )
44- {
45- [NSException raise: NSInternalInconsistencyException
46- format: @" Did not record an invocation in OCMStub/OCMExpect/OCMReject.\n "
47- @" Possible causes are:\n "
48- @" - The receiver is not a mock object.\n "
49- @" - The selector conflicts with a selector implemented by OCMStubRecorder/OCMExpectationRecorder." ];
50- }
44+ if (didThrow == NO && [recorder wasUsed ] == NO )
45+ {
46+ OCMLocation *location = recorder.ocm_location ;
47+ NSString *explanation = @" Did not record an invocation in OCMStub/OCMExpect/OCMReject.\n "
48+ @" Possible causes are:\n "
49+ @" - The receiver is not a mock object.\n "
50+ @" - The selector conflicts with a selector implemented by OCMStubRecorder/OCMExpectationRecorder." ;
51+ if (location != nil )
52+ {
53+ [NSException raise: NSInternalInconsistencyException
54+ format: @" %@ :%d :%@ " , [location file ], (int )[location line ], explanation];
55+ }
56+ else
57+ {
58+ [NSException raise: NSInternalInconsistencyException format: @" %@ " , explanation];
59+ }
60+ }
5161 return recorder;
5262}
5363
5464
55- + (void )beginExpectMacro
65+ + (void )beginExpectMacroAtLocation : (OCMLocation *) aLocation
5666{
5767 OCMExpectationRecorder *recorder = [[[OCMExpectationRecorder alloc ] init ] autorelease ];
68+ recorder.ocm_location = aLocation;
5869 OCMMacroState *macroState = [[OCMMacroState alloc ] initWithRecorder: recorder];
5970 [NSThread currentThread ].threadDictionary [OCMGlobalStateKey] = macroState;
6071 [macroState release ];
@@ -66,9 +77,10 @@ + (OCMStubRecorder *)endExpectMacro
6677}
6778
6879
69- + (void )beginRejectMacro
80+ + (void )beginRejectMacroAtLocation : (OCMLocation *) aLocation
7081{
7182 OCMExpectationRecorder *recorder = [[[OCMExpectationRecorder alloc ] init ] autorelease ];
83+ recorder.ocm_location = aLocation;
7284 OCMMacroState *macroState = [[OCMMacroState alloc ] initWithRecorder: recorder];
7385 [NSThread currentThread ].threadDictionary [OCMGlobalStateKey] = macroState;
7486 [macroState release ];
@@ -92,7 +104,7 @@ + (void)beginVerifyMacroAtLocation:(OCMLocation *)aLocation
92104+ (void )beginVerifyMacroAtLocation : (OCMLocation *)aLocation withQuantifier : (OCMQuantifier *)quantifier
93105{
94106 OCMVerifier *recorder = [[[OCMVerifier alloc ] init ] autorelease ];
95- [ recorder setLocation: aLocation] ;
107+ recorder. ocm_location = aLocation;
96108 [recorder setQuantifier: quantifier];
97109 OCMMacroState *macroState = [[OCMMacroState alloc ] initWithRecorder: recorder];
98110 [NSThread currentThread ].threadDictionary [OCMGlobalStateKey] = macroState;
0 commit comments