@@ -2,26 +2,25 @@ require('../../support/spec_helper');
2
2
3
3
describe ( "Cucumber.Listener.ProgressFormatter" , function ( ) {
4
4
var Cucumber = requireLib ( 'cucumber' ) ;
5
- var listener , listenerHearMethod , summarizer , progressFormatter ;
5
+ var formatter , formatterHearMethod , summarizer , progressFormatter , options ;
6
6
7
7
beforeEach ( function ( ) {
8
- var ProgressFormatter = Cucumber . Listener . ProgressFormatter ;
9
- listener = createSpy ( "listener" ) ;
10
- listenerHearMethod = spyOnStub ( listener , 'hear' ) ;
11
- summarizer = createSpy ( "summarizer" ) ;
12
- spyOn ( Cucumber , 'Listener' ) . andReturn ( listener ) ;
13
- spyOnStub ( Cucumber . Listener , 'Summarizer' ) . andReturn ( summarizer ) ;
14
- Cucumber . Listener . ProgressFormatter = ProgressFormatter ;
15
- progressFormatter = Cucumber . Listener . ProgressFormatter ( ) ;
8
+ options = createSpy ( options ) ;
9
+ formatter = createSpyWithStubs ( "formatter" , { log : null } ) ;
10
+ formatterHearMethod = spyOnStub ( formatter , 'hear' ) ;
11
+ summarizer = createSpy ( "summarizer" ) ;
12
+ spyOn ( Cucumber . Listener , 'Formatter' ) . andReturn ( formatter ) ;
13
+ spyOn ( Cucumber . Listener , 'Summarizer' ) . andReturn ( summarizer ) ;
14
+ progressFormatter = Cucumber . Listener . ProgressFormatter ( options ) ;
16
15
} ) ;
17
16
18
17
describe ( "constructor" , function ( ) {
19
- it ( "creates a listener " , function ( ) {
20
- expect ( Cucumber . Listener ) . toHaveBeenCalled ( ) ;
18
+ it ( "creates a formatter " , function ( ) {
19
+ expect ( Cucumber . Listener . Formatter ) . toHaveBeenCalledWith ( options ) ;
21
20
} ) ;
22
21
23
- it ( "extends the listener " , function ( ) {
24
- expect ( progressFormatter ) . toBe ( listener ) ;
22
+ it ( "extends the formatter " , function ( ) {
23
+ expect ( progressFormatter ) . toBe ( formatter ) ;
25
24
} ) ;
26
25
27
26
it ( "creates a summarizer" , function ( ) {
@@ -53,87 +52,13 @@ describe("Cucumber.Listener.ProgressFormatter", function () {
53
52
summarizerCallback = summarizer . hear . mostRecentCall . args [ 1 ] ;
54
53
} ) ;
55
54
56
- it ( "tells the listener to listen to the event" , function ( ) {
55
+ it ( "tells the formatter to listen to the event" , function ( ) {
57
56
summarizerCallback ( ) ;
58
- expect ( listenerHearMethod ) . toHaveBeenCalledWith ( event , callback ) ;
57
+ expect ( formatterHearMethod ) . toHaveBeenCalledWith ( event , callback ) ;
59
58
} ) ;
60
59
} ) ;
61
60
} ) ;
62
61
63
- describe ( "log()" , function ( ) {
64
- var logged , alsoLogged , loggedBuffer ;
65
-
66
- beforeEach ( function ( ) {
67
- logged = "this was logged" ;
68
- alsoLogged = "this was also logged" ;
69
- loggedBuffer = logged + alsoLogged ;
70
- spyOn ( process . stdout , 'write' ) ;
71
- } ) ;
72
-
73
- it ( "records logged strings" , function ( ) {
74
- progressFormatter . log ( logged ) ;
75
- progressFormatter . log ( alsoLogged ) ;
76
- expect ( progressFormatter . getLogs ( ) ) . toBe ( loggedBuffer ) ;
77
- } ) ;
78
-
79
- it ( "outputs the logged string to STDOUT by default" , function ( ) {
80
- progressFormatter . log ( logged ) ;
81
- expect ( process . stdout . write ) . toHaveBeenCalledWith ( logged ) ;
82
- } ) ;
83
-
84
- describe ( "when asked to output to STDOUT" , function ( ) {
85
- beforeEach ( function ( ) {
86
- progressFormatter = Cucumber . Listener . ProgressFormatter ( { logToConsole : true } ) ;
87
- } ) ;
88
-
89
- it ( "outputs the logged string to STDOUT" , function ( ) {
90
- progressFormatter . log ( logged ) ;
91
- expect ( process . stdout . write ) . toHaveBeenCalledWith ( logged ) ;
92
- } ) ;
93
- } ) ;
94
-
95
- describe ( "when asked to not output to STDOUT" , function ( ) {
96
- beforeEach ( function ( ) {
97
- progressFormatter = Cucumber . Listener . ProgressFormatter ( { logToConsole : false } ) ;
98
- } ) ;
99
-
100
- it ( "does not output anything to STDOUT" , function ( ) {
101
- progressFormatter . log ( logged ) ;
102
- expect ( process . stdout . write ) . not . toHaveBeenCalledWith ( logged ) ;
103
- } ) ;
104
- } ) ;
105
-
106
- describe ( "when asked to output to a function" , function ( ) {
107
- var userFunction ;
108
-
109
- beforeEach ( function ( ) {
110
- userFunction = createSpy ( "output user function" ) ;
111
- progressFormatter = Cucumber . Listener . ProgressFormatter ( { logToFunction : userFunction } ) ;
112
- } ) ;
113
-
114
- it ( "calls the function with the logged string" , function ( ) {
115
- progressFormatter . log ( logged ) ;
116
- expect ( userFunction ) . toHaveBeenCalledWith ( logged ) ;
117
- } ) ;
118
- } ) ;
119
- } ) ;
120
-
121
- describe ( "getLogs()" , function ( ) {
122
- it ( "returns the logged buffer" , function ( ) {
123
- var logged = "this was logged" ;
124
- var alsoLogged = "this was also logged" ;
125
- var loggedBuffer = logged + alsoLogged ;
126
- spyOn ( process . stdout , 'write' ) ; // prevent actual output during spec execution
127
- progressFormatter . log ( logged ) ;
128
- progressFormatter . log ( alsoLogged ) ;
129
- expect ( progressFormatter . getLogs ( ) ) . toBe ( loggedBuffer ) ;
130
- } ) ;
131
-
132
- it ( "returns an empty string when the progress formatter did not log anything yet" , function ( ) {
133
- expect ( progressFormatter . getLogs ( ) ) . toBe ( "" ) ;
134
- } ) ;
135
- } ) ;
136
-
137
62
describe ( "handleStepResultEvent()" , function ( ) {
138
63
var event , callback , stepResult ;
139
64
@@ -283,32 +208,20 @@ describe("Cucumber.Listener.ProgressFormatter", function () {
283
208
} ) ;
284
209
285
210
describe ( "handleSuccessfulStepResult()" , function ( ) {
286
- beforeEach ( function ( ) {
287
- spyOn ( progressFormatter , 'log' ) ;
288
- } ) ;
289
-
290
211
it ( "logs the passing step character" , function ( ) {
291
212
progressFormatter . handleSuccessfulStepResult ( ) ;
292
213
expect ( progressFormatter . log ) . toHaveBeenCalledWith ( Cucumber . Listener . ProgressFormatter . PASSED_STEP_CHARACTER ) ;
293
214
} ) ;
294
215
} ) ;
295
216
296
217
describe ( "handlePendingStepResult()" , function ( ) {
297
- beforeEach ( function ( ) {
298
- spyOn ( progressFormatter , 'log' )
299
- } ) ;
300
-
301
218
it ( "logs the pending step character" , function ( ) {
302
219
progressFormatter . handlePendingStepResult ( ) ;
303
220
expect ( progressFormatter . log ) . toHaveBeenCalledWith ( Cucumber . Listener . ProgressFormatter . PENDING_STEP_CHARACTER ) ;
304
221
} ) ;
305
222
} ) ;
306
223
307
224
describe ( "handleSkippedStepResult()" , function ( ) {
308
- beforeEach ( function ( ) {
309
- spyOn ( progressFormatter , 'log' ) ;
310
- } ) ;
311
-
312
225
it ( "logs the skipped step character" , function ( ) {
313
226
progressFormatter . handleSkippedStepResult ( ) ;
314
227
expect ( progressFormatter . log ) . toHaveBeenCalledWith ( Cucumber . Listener . ProgressFormatter . SKIPPED_STEP_CHARACTER ) ;
@@ -320,7 +233,6 @@ describe("Cucumber.Listener.ProgressFormatter", function () {
320
233
321
234
beforeEach ( function ( ) {
322
235
step = createSpy ( "step" ) ;
323
- spyOn ( progressFormatter , 'log' ) ;
324
236
} ) ;
325
237
326
238
it ( "logs the undefined step character" , function ( ) {
@@ -334,7 +246,6 @@ describe("Cucumber.Listener.ProgressFormatter", function () {
334
246
335
247
beforeEach ( function ( ) {
336
248
stepResult = createSpy ( "failed step result" ) ;
337
- spyOn ( progressFormatter , 'log' ) ;
338
249
} ) ;
339
250
340
251
it ( "logs the failed step character" , function ( ) {
@@ -351,7 +262,6 @@ describe("Cucumber.Listener.ProgressFormatter", function () {
351
262
callback = createSpy ( "callback" ) ;
352
263
summaryLogs = createSpy ( "summary logs" ) ;
353
264
spyOnStub ( summarizer , 'getLogs' ) . andReturn ( summaryLogs ) ;
354
- spyOn ( progressFormatter , 'log' ) ;
355
265
} ) ;
356
266
357
267
it ( "gets the summary" , function ( ) {
0 commit comments