@@ -4,10 +4,23 @@ describe("Cucumber.Listener.JsonFormatterWrapper", function() {
4
4
var Cucumber = requireLib ( 'cucumber' ) ;
5
5
var listener , failedStepResults ;
6
6
7
- var fakeFormatter = createSpyObj ( 'formatter' , [ 'step' , 'uri' , 'feature' , 'background' , 'scenario' , 'result' , 'match' , 'eof' , 'done' ] ) ;
7
+ // var fakeFormatter = createSpyObj('formatter', ['step', 'uri', 'feature', 'background', 'scenario', 'result', 'match', 'eof', 'done']);
8
8
9
9
beforeEach ( function ( ) {
10
- listener = Cucumber . Listener . JsonFormatterWrapper ( fakeFormatter ) ;
10
+ spyOn ( process . stdout , 'write' ) ; // prevent actual output during spec execution
11
+ listener = Cucumber . Listener . JsonFormatterWrapper ( process . stdout ) ;
12
+ formatter = listener . getGherkinFormatter ( ) ;
13
+
14
+ spyOn ( formatter , 'uri' ) ;
15
+ spyOn ( formatter , 'feature' ) ;
16
+ spyOn ( formatter , 'step' ) ;
17
+ spyOn ( formatter , 'background' ) ;
18
+ spyOn ( formatter , 'scenario' ) ;
19
+ spyOn ( formatter , 'result' ) ;
20
+ spyOn ( formatter , 'match' ) ;
21
+ spyOn ( formatter , 'eof' ) ;
22
+ spyOn ( formatter , 'done' ) ;
23
+
11
24
} ) ;
12
25
13
26
// Handle Feature
@@ -31,8 +44,8 @@ describe("Cucumber.Listener.JsonFormatterWrapper", function() {
31
44
32
45
it ( "adds the feature attributes to the output" , function ( ) {
33
46
listener . handleBeforeFeatureEvent ( event , callback ) ;
34
- expect ( fakeFormatter . uri ) . toHaveBeenCalledWith ( 'TODO' ) ;
35
- expect ( fakeFormatter . feature ) . toHaveBeenCalledWith ( { id : 'A-Name' ,
47
+ expect ( formatter . uri ) . toHaveBeenCalledWith ( 'TODO' ) ;
48
+ expect ( formatter . feature ) . toHaveBeenCalledWith ( { id : 'A-Name' ,
36
49
name : 'A Name' ,
37
50
description : 'A Description' ,
38
51
line : 3 ,
@@ -82,7 +95,7 @@ describe("Cucumber.Listener.JsonFormatterWrapper", function() {
82
95
83
96
it ( "adds the background attributes to the output" , function ( ) {
84
97
listener . handleBackgroundEvent ( event , callback ) ;
85
- expect ( fakeFormatter . background ) . toHaveBeenCalledWith ( { name : 'A Name' ,
98
+ expect ( formatter . background ) . toHaveBeenCalledWith ( { name : 'A Name' ,
86
99
keyword : 'Background' ,
87
100
description : 'A Description' ,
88
101
type : 'background' ,
@@ -120,7 +133,7 @@ describe("Cucumber.Listener.JsonFormatterWrapper", function() {
120
133
121
134
it ( "adds the scenario attributes to the output" , function ( ) {
122
135
listener . handleBeforeScenarioEvent ( event , callback ) ;
123
- expect ( fakeFormatter . scenario ) . toHaveBeenCalledWith ( { name : 'A Name' ,
136
+ expect ( formatter . scenario ) . toHaveBeenCalledWith ( { name : 'A Name' ,
124
137
id : 'undefined;a-name' ,
125
138
line : 3 ,
126
139
keyword : 'Scenario' ,
@@ -145,7 +158,7 @@ describe("Cucumber.Listener.JsonFormatterWrapper", function() {
145
158
} ) ;
146
159
147
160
listener . formatStep ( step ) ;
148
- expect ( fakeFormatter . step ) . toHaveBeenCalledWith ( { name : 'Step' , line : 3 , keyword : 'Step' } ) ;
161
+ expect ( formatter . step ) . toHaveBeenCalledWith ( { name : 'Step' , line : 3 , keyword : 'Step' } ) ;
149
162
150
163
} ) ;
151
164
@@ -166,7 +179,7 @@ describe("Cucumber.Listener.JsonFormatterWrapper", function() {
166
179
} ) ;
167
180
168
181
listener . formatStep ( step ) ;
169
- expect ( fakeFormatter . step ) . toHaveBeenCalledWith ( { name : 'Step' ,
182
+ expect ( formatter . step ) . toHaveBeenCalledWith ( { name : 'Step' ,
170
183
line : 3 ,
171
184
keyword : 'Step' ,
172
185
doc_string : { value : 'This is a DocString' , line : 3 , content_type : null }
@@ -194,7 +207,7 @@ describe("Cucumber.Listener.JsonFormatterWrapper", function() {
194
207
} ) ;
195
208
196
209
listener . formatStep ( step ) ;
197
- expect ( fakeFormatter . step ) . toHaveBeenCalledWith ( { name : 'Step' ,
210
+ expect ( formatter . step ) . toHaveBeenCalledWith ( { name : 'Step' ,
198
211
line : 3 ,
199
212
keyword : 'Step' ,
200
213
rows : [ { line : 'TODO' , cells : [ 'a:1' , 'a:2' , 'a:3' ] } ,
@@ -271,9 +284,9 @@ describe("Cucumber.Listener.JsonFormatterWrapper", function() {
271
284
272
285
listener . handleStepResultEvent ( fakeEvent , callback ) ;
273
286
274
- expect ( fakeFormatter . step ) . toHaveBeenCalledWith ( { name : 'Step' , line : 3 , keyword : 'Step' } ) ;
275
- expect ( fakeFormatter . result ) . toHaveBeenCalledWith ( { status : 'failed' } ) ;
276
- expect ( fakeFormatter . match ) . toHaveBeenCalledWith ( { location : 'TODO' } ) ;
287
+ expect ( formatter . step ) . toHaveBeenCalledWith ( { name : 'Step' , line : 3 , keyword : 'Step' } ) ;
288
+ expect ( formatter . result ) . toHaveBeenCalledWith ( { status : 'failed' } ) ;
289
+ expect ( formatter . match ) . toHaveBeenCalledWith ( { location : 'TODO' } ) ;
277
290
278
291
} ) ;
279
292
@@ -302,9 +315,9 @@ describe("Cucumber.Listener.JsonFormatterWrapper", function() {
302
315
303
316
listener . handleStepResultEvent ( fakeEvent , callback ) ;
304
317
305
- expect ( fakeFormatter . step ) . toHaveBeenCalledWith ( { name : 'Step' , line : 3 , keyword : 'Step' } ) ;
306
- expect ( fakeFormatter . result ) . toHaveBeenCalledWith ( { status : 'passed' } ) ;
307
- expect ( fakeFormatter . match ) . toHaveBeenCalledWith ( { location : 'TODO' } ) ;
318
+ expect ( formatter . step ) . toHaveBeenCalledWith ( { name : 'Step' , line : 3 , keyword : 'Step' } ) ;
319
+ expect ( formatter . result ) . toHaveBeenCalledWith ( { status : 'passed' } ) ;
320
+ expect ( formatter . match ) . toHaveBeenCalledWith ( { location : 'TODO' } ) ;
308
321
309
322
} ) ;
310
323
@@ -333,9 +346,9 @@ describe("Cucumber.Listener.JsonFormatterWrapper", function() {
333
346
334
347
listener . handleStepResultEvent ( fakeEvent , callback ) ;
335
348
336
- expect ( fakeFormatter . step ) . toHaveBeenCalledWith ( { name : 'Step' , line : 3 , keyword : 'Step' } ) ;
337
- expect ( fakeFormatter . result ) . toHaveBeenCalledWith ( { status : 'pending' , error_message : 'TODO' } ) ;
338
- expect ( fakeFormatter . match ) . toHaveBeenCalledWith ( { location : 'TODO' } ) ;
349
+ expect ( formatter . step ) . toHaveBeenCalledWith ( { name : 'Step' , line : 3 , keyword : 'Step' } ) ;
350
+ expect ( formatter . result ) . toHaveBeenCalledWith ( { status : 'pending' , error_message : 'TODO' } ) ;
351
+ expect ( formatter . match ) . toHaveBeenCalledWith ( { location : 'TODO' } ) ;
339
352
340
353
} ) ;
341
354
@@ -364,9 +377,9 @@ describe("Cucumber.Listener.JsonFormatterWrapper", function() {
364
377
365
378
listener . handleStepResultEvent ( fakeEvent , callback ) ;
366
379
367
- expect ( fakeFormatter . step ) . toHaveBeenCalledWith ( { name : 'Step' , line : 3 , keyword : 'Step' } ) ;
368
- expect ( fakeFormatter . result ) . toHaveBeenCalledWith ( { status : 'failed' } ) ;
369
- expect ( fakeFormatter . match ) . toHaveBeenCalledWith ( { location : 'TODO' } ) ;
380
+ expect ( formatter . step ) . toHaveBeenCalledWith ( { name : 'Step' , line : 3 , keyword : 'Step' } ) ;
381
+ expect ( formatter . result ) . toHaveBeenCalledWith ( { status : 'failed' } ) ;
382
+ expect ( formatter . match ) . toHaveBeenCalledWith ( { location : 'TODO' } ) ;
370
383
371
384
} ) ;
372
385
@@ -395,9 +408,9 @@ describe("Cucumber.Listener.JsonFormatterWrapper", function() {
395
408
396
409
listener . handleStepResultEvent ( fakeEvent , callback ) ;
397
410
398
- expect ( fakeFormatter . step ) . toHaveBeenCalledWith ( { name : 'Step' , line : 3 , keyword : 'Step' } ) ;
399
- expect ( fakeFormatter . result ) . toHaveBeenCalledWith ( { status : 'skipped' } ) ;
400
- expect ( fakeFormatter . match ) . toHaveBeenCalledWith ( { location : 'TODO' } ) ;
411
+ expect ( formatter . step ) . toHaveBeenCalledWith ( { name : 'Step' , line : 3 , keyword : 'Step' } ) ;
412
+ expect ( formatter . result ) . toHaveBeenCalledWith ( { status : 'skipped' } ) ;
413
+ expect ( formatter . match ) . toHaveBeenCalledWith ( { location : 'TODO' } ) ;
401
414
402
415
} ) ;
403
416
@@ -426,9 +439,9 @@ describe("Cucumber.Listener.JsonFormatterWrapper", function() {
426
439
427
440
listener . handleStepResultEvent ( fakeEvent , callback ) ;
428
441
429
- expect ( fakeFormatter . step ) . toHaveBeenCalledWith ( { name : 'Step' , line : 3 , keyword : 'Step' } ) ;
430
- expect ( fakeFormatter . result ) . toHaveBeenCalledWith ( { status : 'undefined' } ) ;
431
- expect ( fakeFormatter . match ) . toHaveBeenCalledWith ( { location : 'TODO' } ) ;
442
+ expect ( formatter . step ) . toHaveBeenCalledWith ( { name : 'Step' , line : 3 , keyword : 'Step' } ) ;
443
+ expect ( formatter . result ) . toHaveBeenCalledWith ( { status : 'undefined' } ) ;
444
+ expect ( formatter . match ) . toHaveBeenCalledWith ( { location : 'TODO' } ) ;
432
445
433
446
} ) ;
434
447
@@ -447,8 +460,8 @@ describe("Cucumber.Listener.JsonFormatterWrapper", function() {
447
460
448
461
it ( "finalises output" , function ( ) {
449
462
listener . handleAfterFeaturesEvent ( event , callback ) ;
450
- expect ( fakeFormatter . eof ) . toHaveBeenCalled ( ) ;
451
- expect ( fakeFormatter . done ) . toHaveBeenCalled ( ) ;
463
+ expect ( formatter . eof ) . toHaveBeenCalled ( ) ;
464
+ expect ( formatter . done ) . toHaveBeenCalled ( ) ;
452
465
} ) ;
453
466
454
467
it ( "calls back" , function ( ) {
0 commit comments