@@ -25,9 +25,10 @@ @implementation OCMMacroState
25
25
26
26
#pragma mark Methods to begin/end macros
27
27
28
- + (void )beginStubMacro
28
+ + (void )beginStubMacroAtLocation : (OCMLocation *) aLocation
29
29
{
30
30
OCMStubRecorder *recorder = [[[OCMStubRecorder alloc ] init ] autorelease ];
31
+ recorder.ocm_location = aLocation;
31
32
OCMMacroState *macroState = [[OCMMacroState alloc ] initWithRecorder: recorder];
32
33
[NSThread currentThread ].threadDictionary [OCMGlobalStateKey] = macroState;
33
34
[macroState release ];
@@ -40,21 +41,31 @@ + (OCMStubRecorder *)endStubMacro
40
41
OCMStubRecorder *recorder = [[(OCMStubRecorder *)[globalState recorder ] retain ] autorelease ];
41
42
BOOL didThrow = [globalState invocationDidThrow ];
42
43
[threadDictionary removeObjectForKey: OCMGlobalStateKey];
43
- if (didThrow == NO && [recorder didRecordInvocation ] == 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 didRecordInvocation ] == 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
+ }
51
61
return recorder;
52
62
}
53
63
54
64
55
- + (void )beginExpectMacro
65
+ + (void )beginExpectMacroAtLocation : (OCMLocation *) aLocation
56
66
{
57
67
OCMExpectationRecorder *recorder = [[[OCMExpectationRecorder alloc ] init ] autorelease ];
68
+ recorder.ocm_location = aLocation;
58
69
OCMMacroState *macroState = [[OCMMacroState alloc ] initWithRecorder: recorder];
59
70
[NSThread currentThread ].threadDictionary [OCMGlobalStateKey] = macroState;
60
71
[macroState release ];
@@ -66,9 +77,10 @@ + (OCMStubRecorder *)endExpectMacro
66
77
}
67
78
68
79
69
- + (void )beginRejectMacro
80
+ + (void )beginRejectMacroAtLocation : (OCMLocation *) aLocation
70
81
{
71
82
OCMExpectationRecorder *recorder = [[[OCMExpectationRecorder alloc ] init ] autorelease ];
83
+ recorder.ocm_location = aLocation;
72
84
OCMMacroState *macroState = [[OCMMacroState alloc ] initWithRecorder: recorder];
73
85
[NSThread currentThread ].threadDictionary [OCMGlobalStateKey] = macroState;
74
86
[macroState release ];
@@ -92,7 +104,7 @@ + (void)beginVerifyMacroAtLocation:(OCMLocation *)aLocation
92
104
+ (void )beginVerifyMacroAtLocation : (OCMLocation *)aLocation withQuantifier : (OCMQuantifier *)quantifier
93
105
{
94
106
OCMVerifier *recorder = [[[OCMVerifier alloc ] init ] autorelease ];
95
- [ recorder setLocation: aLocation] ;
107
+ recorder. ocm_location = aLocation;
96
108
[recorder setQuantifier: quantifier];
97
109
OCMMacroState *macroState = [[OCMMacroState alloc ] initWithRecorder: recorder];
98
110
[NSThread currentThread ].threadDictionary [OCMGlobalStateKey] = macroState;
0 commit comments