@@ -4,16 +4,13 @@ describe("Cucumber.Listener.SummaryFormatter", function () {
4
4
var Cucumber = requireLib ( 'cucumber' ) ;
5
5
var colors = require ( 'colors/safe' ) ;
6
6
colors . enabled = true ;
7
- var formatter , formatterHearMethod , summaryFormatter , statsJournal , failedStepResults , options ;
7
+ var formatter , formatterHearMethod , summaryFormatter , statsJournal , options ;
8
8
9
9
beforeEach ( function ( ) {
10
10
options = { useColors : true } ;
11
11
formatter = createSpyWithStubs ( "formatter" , { finish : null , log : null } ) ;
12
12
formatterHearMethod = spyOnStub ( formatter , 'hear' ) ;
13
13
statsJournal = createSpy ( "stats journal" ) ;
14
- failedStepResults = createSpyObj ( "failed steps" , [ "length" ] ) ;
15
- failedStepResults . length . and . returnValue ( 0 ) ;
16
- spyOn ( Cucumber . Type , 'Collection' ) . and . returnValue ( failedStepResults ) ;
17
14
spyOn ( Cucumber . Listener , 'Formatter' ) . and . returnValue ( formatter ) ;
18
15
spyOn ( Cucumber . Listener , 'StatsJournal' ) . and . returnValue ( statsJournal ) ;
19
16
summaryFormatter = Cucumber . Listener . SummaryFormatter ( options ) ;
@@ -28,10 +25,6 @@ describe("Cucumber.Listener.SummaryFormatter", function () {
28
25
expect ( summaryFormatter ) . toBe ( formatter ) ;
29
26
} ) ;
30
27
31
- it ( "creates a collection to store the failed steps" , function ( ) {
32
- expect ( Cucumber . Type . Collection ) . toHaveBeenCalled ( ) ;
33
- } ) ;
34
-
35
28
it ( "creates a stats journal" , function ( ) {
36
29
expect ( Cucumber . Listener . StatsJournal ) . toHaveBeenCalled ( ) ;
37
30
} ) ;
@@ -227,16 +220,34 @@ describe("Cucumber.Listener.SummaryFormatter", function () {
227
220
228
221
229
222
describe ( "storeFailedStepResult()" , function ( ) {
230
- var failedStepResult ;
223
+ var failureException , stepResult ;
231
224
232
225
beforeEach ( function ( ) {
233
- failedStepResult = createSpy ( "failed step result" ) ;
234
- spyOnStub ( failedStepResults , 'add' ) ;
226
+ spyOn ( summaryFormatter , 'appendStringToFailedStepResultLogBuffer' ) ;
235
227
} ) ;
236
228
237
- it ( "adds the result to the failed step result collection" , function ( ) {
238
- summaryFormatter . storeFailedStepResult ( failedStepResult ) ;
239
- expect ( failedStepResults . add ) . toHaveBeenCalledWith ( failedStepResult ) ;
229
+ describe ( "when the failure exception has a stack" , function ( ) {
230
+ beforeEach ( function ( ) {
231
+ failureException = { stack : 'failure exception stack' } ;
232
+ stepResult = createSpyWithStubs ( "failed step result" , { getFailureException : failureException } ) ;
233
+ } ) ;
234
+
235
+ it ( "appends the stack to the failed step results log buffer" , function ( ) {
236
+ summaryFormatter . storeFailedStepResult ( stepResult ) ;
237
+ expect ( summaryFormatter . appendStringToFailedStepResultLogBuffer ) . toHaveBeenCalledWith ( 'failure exception stack' ) ;
238
+ } ) ;
239
+ } ) ;
240
+
241
+ describe ( "when the failure exception has no stack" , function ( ) {
242
+ beforeEach ( function ( ) {
243
+ failureException = 'failure exception' ;
244
+ stepResult = createSpyWithStubs ( "failed step result" , { getFailureException : failureException } ) ;
245
+ } ) ;
246
+
247
+ it ( "appends the expception to the failed step results log buffer" , function ( ) {
248
+ summaryFormatter . storeFailedStepResult ( stepResult ) ;
249
+ expect ( summaryFormatter . appendStringToFailedStepResultLogBuffer ) . toHaveBeenCalledWith ( 'failure exception' ) ;
250
+ } ) ;
240
251
} ) ;
241
252
} ) ;
242
253
@@ -428,72 +439,20 @@ describe("Cucumber.Listener.SummaryFormatter", function () {
428
439
} ) ;
429
440
430
441
describe ( "logFailedStepResults()" , function ( ) {
431
- beforeEach ( function ( ) {
432
- spyOnStub ( failedStepResults , 'forEach' ) ;
433
- } ) ;
434
-
435
- it ( "logs a failed steps header" , function ( ) {
436
- summaryFormatter . logFailedStepResults ( ) ;
437
- expect ( summaryFormatter . log ) . toHaveBeenCalledWith ( "(::) failed steps (::)\n\n" ) ;
438
- } ) ;
439
-
440
- it ( "iterates synchronously over the failed step results" , function ( ) {
441
- summaryFormatter . logFailedStepResults ( ) ;
442
- expect ( failedStepResults . forEach ) . toHaveBeenCalled ( ) ;
443
- expect ( failedStepResults . forEach ) . toHaveBeenCalledWithAFunctionAsNthParameter ( 1 ) ;
444
- } ) ;
445
-
446
- describe ( "for each failed step result" , function ( ) {
447
- var userFunction , failedStepResult ;
448
-
449
- beforeEach ( function ( ) {
450
- summaryFormatter . logFailedStepResults ( ) ;
451
- userFunction = failedStepResults . forEach . calls . mostRecent ( ) . args [ 0 ] ;
452
- failedStepResult = createSpy ( "failed step result" ) ;
453
- spyOn ( summaryFormatter , 'logFailedStepResult' ) ;
454
- } ) ;
455
-
456
- it ( "tells the visitor to visit the feature and call back when finished" , function ( ) {
457
- userFunction ( failedStepResult ) ;
458
- expect ( summaryFormatter . logFailedStepResult ) . toHaveBeenCalledWith ( failedStepResult ) ;
459
- } ) ;
460
- } ) ;
461
- } ) ;
462
-
463
- describe ( "logFailedStepResult()" , function ( ) {
464
- var stepResult , failureException ;
442
+ var failedStepResultLogBuffer ;
465
443
466
444
beforeEach ( function ( ) {
467
- failureException = createSpy ( 'caught exception' ) ;
468
- stepResult = createSpyWithStubs ( "failed step result" , { getFailureException : failureException } ) ;
469
- } ) ;
470
-
471
- it ( "gets the failure exception from the step result" , function ( ) {
472
- summaryFormatter . logFailedStepResult ( stepResult ) ;
473
- expect ( stepResult . getFailureException ) . toHaveBeenCalled ( ) ;
474
- } ) ;
475
-
476
- describe ( "when the failure exception has a stack" , function ( ) {
477
- beforeEach ( function ( ) {
478
- failureException . stack = createSpy ( 'failure exception stack' ) ;
479
- } ) ;
480
-
481
- it ( "logs the stack" , function ( ) {
482
- summaryFormatter . logFailedStepResult ( stepResult ) ;
483
- expect ( summaryFormatter . log ) . toHaveBeenCalledWith ( failureException . stack ) ;
484
- } ) ;
445
+ failedStepResultLogBuffer = "failed step result log buffer" ;
446
+ spyOn ( summaryFormatter , 'getFailedStepResultLogBuffer' ) . and . returnValue ( failedStepResultLogBuffer ) ;
447
+ summaryFormatter . logFailedStepResults ( ) ;
485
448
} ) ;
486
449
487
- describe ( "when the failure exception has no stack" , function ( ) {
488
- it ( "logs the exception itself" , function ( ) {
489
- summaryFormatter . logFailedStepResult ( stepResult ) ;
490
- expect ( summaryFormatter . log ) . toHaveBeenCalledWith ( failureException ) ;
491
- } ) ;
450
+ it ( "logs a failed step results header" , function ( ) {
451
+ expect ( summaryFormatter . log ) . toHaveBeenCalledWith ( '(::) failed steps (::)\n\n' ) ;
492
452
} ) ;
493
453
494
- it ( "logs two line breaks" , function ( ) {
495
- summaryFormatter . logFailedStepResult ( stepResult ) ;
496
- expect ( summaryFormatter . log ) . toHaveBeenCalledWith ( "\n\n" ) ;
454
+ it ( "logs the failed step results details" , function ( ) {
455
+ expect ( summaryFormatter . log ) . toHaveBeenCalledWith ( failedStepResultLogBuffer ) ;
497
456
} ) ;
498
457
} ) ;
499
458
0 commit comments