@@ -157,104 +157,126 @@ class SubSpec extends SuperSpec {
157157 specInfo. specsBottomToTop* . addSharedInitializerInterceptor {
158158 assertSpecContext(it)
159159 proceed(it, ' shared initializer' , " $it . spec . name " )
160+ assertSpecContext(it)
160161 }
161162 specInfo. allSharedInitializerMethods* . addInterceptor {
162163 assertSpecMethodContext(it)
163164 proceed(it, ' shared initializer method' , " $it . spec . name . $it . method . name ()" )
165+ assertSpecMethodContext(it)
164166 }
165167 specInfo. addInterceptor {
166168 assertSpecContext(it)
167169 proceed(it, ' specification' , " $it . spec . name " )
170+ assertSpecContext(it)
168171 }
169172 specInfo. specsBottomToTop* . addSetupSpecInterceptor {
170173 assertSpecContext(it)
171174 proceed(it, ' setup spec' , " $it . spec . name " )
175+ assertSpecContext(it)
172176 }
173177 specInfo. allSetupSpecMethods* . addInterceptor {
174178 assertSpecMethodContext(it)
175179 proceed(it, ' setup spec method' , " $it . spec . name . $it . method . name ()" )
180+ assertSpecMethodContext(it)
176181 }
177182 allFeatures* . addInterceptor {
178183 assertFeatureContext(it)
179184 proceed(it, ' feature' , " $it . spec . name . $it . feature . name " )
185+ assertFeatureContext(it)
180186 }
181187 specInfo. specsBottomToTop. each { spec ->
182188 spec. addInitializerInterceptor {
183189 assertIterationContext(it)
184190 proceed(it, ' initializer' , " $it . spec . name . $it . feature . name [#$it . iteration . iterationIndex ] / $spec . name " )
191+ assertIterationContext(it)
185192 }
186193 }
187194 specInfo. allInitializerMethods* . addInterceptor {
188195 assertIterationMethodContext(it)
189196 proceed(it, ' initializer method' , " $it . feature . parent . name . $it . feature . name [#$it . iteration . iterationIndex ] / $it . spec . name . $it . method . name ()" )
197+ assertIterationMethodContext(it)
190198 }
191199 allFeatures. each { feature ->
192200 specInfo. allInitializerMethods. each { mi ->
193201 feature. addScopedMethodInterceptor(mi) {
194202 assertIterationMethodContext(it)
195203 proceed(it, ' feature scoped initializer method' , " $it . feature . parent . name . $it . feature . name [#$it . iteration . iterationIndex ] / $it . spec . name . $it . method . name () / from $feature . name " )
204+ assertIterationMethodContext(it)
196205 }
197206 }
198207 specInfo. allSetupMethods. each { mi ->
199208 feature. addScopedMethodInterceptor(mi) {
200209 assertIterationMethodContext(it)
201210 proceed(it, ' feature scoped setup method' , " $it . feature . parent . name . $it . feature . name [#$it . iteration . iterationIndex ] / $it . spec . name . $it . method . name () / from $feature . name " )
211+ assertIterationMethodContext(it)
202212 }
203213 }
204214 specInfo. allCleanupMethods. each { mi ->
205215 feature. addScopedMethodInterceptor(mi) {
206216 assertIterationMethodContext(it)
207217 proceed(it, ' feature scoped cleanup method' , " $it . feature . parent . name . $it . feature . name [#$it . iteration . iterationIndex ] / $it . spec . name . $it . method . name () / from $feature . name " )
218+ assertIterationMethodContext(it)
208219 }
209220 }
210221 }
211222 allFeatures* . addInitializerInterceptor {
212223 assertIterationContext(it)
213224 proceed(it, ' feature scoped initializer' , " $it . spec . name . $it . feature . name [#$it . iteration . iterationIndex ]" )
225+ assertIterationContext(it)
214226 }
215227 allFeatures* . addIterationInterceptor {
216228 assertIterationContext(it)
217229 proceed(it, ' iteration' , " $it . spec . name . $it . feature . name [#$it . iteration . iterationIndex ]" )
230+ assertIterationContext(it)
218231 }
219232 specInfo. specsBottomToTop. each { spec ->
220233 spec. addSetupInterceptor {
221234 assertIterationContext(it)
222235 proceed(it, ' setup' , " $it . spec . name . $it . feature . name [#$it . iteration . iterationIndex ] / $spec . name " )
236+ assertIterationContext(it)
223237 }
224238 }
225239 allFeatures* . addSetupInterceptor {
226240 assertIterationContext(it)
227241 proceed(it, ' feature scoped setup' , " $it . spec . name . $it . feature . name [#$it . iteration . iterationIndex ]" )
242+ assertIterationContext(it)
228243 }
229244 specInfo. allSetupMethods* . addInterceptor {
230245 assertIterationMethodContext(it)
231246 proceed(it, ' setup method' , " $it . feature . parent . name . $it . feature . name [#$it . iteration . iterationIndex ] / $it . spec . name . $it . method . name ()" )
247+ assertIterationMethodContext(it)
232248 }
233249 allFeatures* . featureMethod* . addInterceptor {
234250 assertIterationMethodContext(it)
235251 proceed(it, ' feature method' , " $it . feature . parent . name . $it . feature . name [#$it . iteration . iterationIndex ] / $it . spec . name . $it . method . name ()" )
252+ assertIterationMethodContext(it)
236253 }
237254 specInfo. specsBottomToTop. each { spec ->
238255 spec. addCleanupInterceptor {
239256 assertIterationContext(it)
240257 proceed(it, ' cleanup' , " $it . spec . name . $it . feature . name [#$it . iteration . iterationIndex ] / $spec . name " )
258+ assertIterationContext(it)
241259 }
242260 }
243261 allFeatures* . addCleanupInterceptor {
244262 assertIterationContext(it)
245263 proceed(it, ' feature scoped cleanup' , " $it . spec . name . $it . feature . name [#$it . iteration . iterationIndex ]" )
264+ assertIterationContext(it)
246265 }
247266 specInfo. allCleanupMethods* . addInterceptor {
248267 assertIterationMethodContext(it)
249268 proceed(it, ' cleanup method' , " $it . feature . parent . name . $it . feature . name [#$it . iteration . iterationIndex ] / $it . spec . name . $it . method . name ()" )
269+ assertIterationMethodContext(it)
250270 }
251271 specInfo. specsBottomToTop* . addCleanupSpecInterceptor {
252272 assertSpecContext(it)
253273 proceed(it, ' cleanup spec' , " $it . spec . name " )
274+ assertSpecContext(it)
254275 }
255276 specInfo. allCleanupSpecMethods* . addInterceptor {
256277 assertSpecMethodContext(it)
257278 proceed(it, ' cleanup spec method' , " $it . spec . name . $it . method . name ()" )
279+ assertSpecMethodContext(it)
258280 }
259281 specInfo. allFixtureMethods* . addInterceptor {
260282 it. with {
@@ -266,6 +288,14 @@ class SubSpec extends SuperSpec {
266288 }
267289 }
268290 proceed(it, ' fixture method' , " ${ it.feature?.with { feature -> "$feature.parent.name.$feature.name[#$it.iteration.iterationIndex] / " } ?: ''} $it . spec . name . $it . method . name ()" )
291+ it. with {
292+ def specFixture = method. name. endsWith(' Spec' )
293+ if (specFixture) {
294+ assertSpecMethodContext(it)
295+ } else {
296+ assertIterationMethodContext(it)
297+ }
298+ }
269299 }
270300 }
271301
@@ -282,7 +312,7 @@ class SubSpec extends SuperSpec {
282312 currentFeature
283313 assert false : ' currentFeature should not be set'
284314 } catch (IllegalStateException ise) {
285- assert ise. message == ' Cannot request current feature in @Shared context'
315+ assert ise. message == ' Cannot request current feature in @Shared context, or feature context '
286316 }
287317 try {
288318 currentIteration
@@ -319,7 +349,6 @@ class SubSpec extends SuperSpec {
319349 assert method
320350 instance. specificationContext. with {
321351 assert currentSpec
322- assert currentFeature
323352 }
324353 }
325354 }
@@ -333,6 +362,12 @@ class SubSpec extends SuperSpec {
333362 assert ! method. reflection
334363 assert ! method. name
335364 instance. specificationContext. with {
365+ try {
366+ currentFeature
367+ assert false : ' currentFeature should not be set'
368+ } catch (IllegalStateException ise) {
369+ assert ise. message == ' Cannot request current feature in @Shared context, or feature context'
370+ }
336371 try {
337372 currentIteration
338373 assert false : ' currentIteration should not be set'
@@ -349,6 +384,7 @@ class SubSpec extends SuperSpec {
349384 assert iteration
350385 assert instance != sharedInstance
351386 instance. specificationContext. with {
387+ assert currentFeature
352388 assert currentIteration
353389 }
354390 }
0 commit comments