@@ -97,10 +97,10 @@ describe("Cucumber.Runtime.AstTreeWalker", function() {
97
97
var feature , callback , event , payload ;
98
98
99
99
beforeEach ( function ( ) {
100
- feature = createSpyWithStubs ( "Feature AST element" , { acceptVisitor : null } ) ;
101
- callback = createSpy ( "Callback" ) ;
102
- event = createSpy ( "Event" ) ;
103
- payload = { feature : feature } ;
100
+ feature = createSpyWithStubs ( "Feature AST element" , { acceptVisitor : null } ) ;
101
+ callback = createSpy ( "Callback" ) ;
102
+ event = createSpy ( "Event" ) ;
103
+ payload = { feature : feature } ;
104
104
spyOn ( Cucumber . Runtime . AstTreeWalker , 'Event' ) . andReturn ( event ) ;
105
105
spyOn ( treeWalker , 'broadcastEventAroundUserFunction' ) ;
106
106
} ) ;
@@ -177,19 +177,21 @@ describe("Cucumber.Runtime.AstTreeWalker", function() {
177
177
} ) ;
178
178
179
179
describe ( "on world instantiation completion" , function ( ) {
180
- var worldInstantiationCompletionCallback , world , event , payload ;
180
+ var worldInstantiationCompletionCallback , world , event , payload , hookedUpFunction ;
181
181
182
182
beforeEach ( function ( ) {
183
183
world = createSpy ( "world instance" ) ;
184
184
treeWalker . visitScenario ( scenario , callback ) ;
185
185
worldInstantiationCompletionCallback = supportCodeLibrary . instantiateNewWorld . mostRecentCall . args [ 0 ] ;
186
186
187
- event = createSpy ( "Event" ) ;
188
- payload = { scenario : scenario } ;
187
+ event = createSpy ( "Event" ) ;
188
+ payload = { scenario : scenario } ;
189
+ scenarioVisitWithHooks = createSpy ( "scenario visit with hooks" ) ;
189
190
spyOn ( Cucumber . Runtime . AstTreeWalker , 'Event' ) . andReturn ( event ) ;
190
191
spyOn ( treeWalker , 'broadcastEventAroundUserFunction' ) ;
191
192
spyOn ( treeWalker , 'setWorld' ) ;
192
193
spyOn ( treeWalker , 'witnessNewScenario' ) ;
194
+ spyOn ( treeWalker , 'hookUpFunction' ) . andReturn ( scenarioVisitWithHooks ) ;
193
195
} ) ;
194
196
195
197
it ( "sets the new World instance" , function ( ) {
@@ -207,31 +209,31 @@ describe("Cucumber.Runtime.AstTreeWalker", function() {
207
209
expect ( Cucumber . Runtime . AstTreeWalker . Event ) . toHaveBeenCalledWith ( Cucumber . Runtime . AstTreeWalker . SCENARIO_EVENT_NAME , payload ) ;
208
210
} ) ;
209
211
210
- it ( "broadcasts the visit of the scenario " , function ( ) {
212
+ it ( "hooks up a function " , function ( ) {
211
213
worldInstantiationCompletionCallback ( world ) ;
212
- expect ( treeWalker . broadcastEventAroundUserFunction ) . toHaveBeenCalled ( ) ;
213
- expect ( treeWalker . broadcastEventAroundUserFunction ) .
214
- toHaveBeenCalledWithValueAsNthParameter ( event , 1 ) ;
215
- expect ( treeWalker . broadcastEventAroundUserFunction ) .
216
- toHaveBeenCalledWithAFunctionAsNthParameter ( 2 ) ;
217
- expect ( treeWalker . broadcastEventAroundUserFunction ) .
218
- toHaveBeenCalledWithValueAsNthParameter ( callback , 3 ) ;
214
+ expect ( treeWalker . hookUpFunction ) . toHaveBeenCalled ( ) ;
215
+ expect ( treeWalker . hookUpFunction ) . toHaveBeenCalledWithAFunctionAsNthParameter ( 1 ) ;
219
216
} ) ;
220
217
221
- describe ( "user function" , function ( ) {
222
- var userFunction , userFunctionCallback ;
218
+ describe ( "hooked up function" , function ( ) {
219
+ var hookedUpFunction , hookedUpFunctionCallback ;
223
220
224
221
beforeEach ( function ( ) {
225
- userFunctionCallback = createSpy ( "User function callback" ) ;
222
+ hookedUpFunctionCallback = createSpy ( "hooked up function callback" ) ;
226
223
worldInstantiationCompletionCallback ( world ) ;
227
- userFunction = treeWalker . broadcastEventAroundUserFunction . mostRecentCall . args [ 1 ] ;
224
+ hookedUpFunction = treeWalker . hookUpFunction . mostRecentCall . args [ 0 ] ;
228
225
} ) ;
229
226
230
- it ( "visits the scenario, passing it the received callback " , function ( ) {
231
- userFunction ( userFunctionCallback ) ;
232
- expect ( scenario . acceptVisitor ) . toHaveBeenCalledWith ( treeWalker , userFunctionCallback ) ;
227
+ it ( "tells the scenario to accept the tree walker itself as a visitor " , function ( ) {
228
+ hookedUpFunction ( hookedUpFunctionCallback ) ;
229
+ expect ( scenario . acceptVisitor ) . toHaveBeenCalledWith ( treeWalker , hookedUpFunctionCallback ) ;
233
230
} ) ;
234
231
} ) ;
232
+
233
+ it ( "broadcasts the visit of the scenario" , function ( ) {
234
+ worldInstantiationCompletionCallback ( world ) ;
235
+ expect ( treeWalker . broadcastEventAroundUserFunction ) . toHaveBeenCalledWith ( event , scenarioVisitWithHooks , callback ) ;
236
+ } ) ;
235
237
} ) ;
236
238
} ) ;
237
239
0 commit comments