@@ -161,9 +161,10 @@ describe("Cucumber.Listener.PrettyFormatter", function () {
161
161
beforeEach ( function ( ) {
162
162
keyword = "step-keyword " ;
163
163
name = "step-name" ;
164
- step = createSpyWithStubs ( "step" , { getKeyword : keyword , getName : name } ) ;
164
+ step = createSpyWithStubs ( "step" , { getKeyword : keyword , hasDataTable : null , getDataTable : null , getName : name } ) ;
165
165
stepResult = createSpyWithStubs ( "step result" , { getStep : step , isFailed : null } ) ;
166
166
event = createSpyWithStubs ( "event" , { getPayloadItem : stepResult } ) ;
167
+ spyOn ( prettyFormatter , 'logDataTable' ) ;
167
168
spyOn ( prettyFormatter , 'logIndented' ) ;
168
169
callback = createSpy ( "callback" ) ;
169
170
} ) ;
@@ -194,6 +195,47 @@ describe("Cucumber.Listener.PrettyFormatter", function () {
194
195
expect ( prettyFormatter . logIndented ) . toHaveBeenCalledWith ( text , 2 ) ;
195
196
} ) ;
196
197
198
+ it ( "checks whether the step result has a data table or not" , function ( ) {
199
+ prettyFormatter . handleStepResultEvent ( event , callback ) ;
200
+ expect ( step . hasDataTable ) . toHaveBeenCalled ( ) ;
201
+ } ) ;
202
+
203
+ describe ( "when the step has a data table" , function ( ) {
204
+ var dataTable ;
205
+
206
+ beforeEach ( function ( ) {
207
+ dataTable = createSpy ( "data table" ) ;
208
+ step . hasDataTable . andReturn ( true ) ;
209
+ step . getDataTable . andReturn ( dataTable ) ;
210
+ } ) ;
211
+
212
+ it ( "gets the data table" , function ( ) {
213
+ prettyFormatter . handleStepResultEvent ( event , callback ) ;
214
+ expect ( step . getDataTable ) . toHaveBeenCalled ( ) ;
215
+ } ) ;
216
+
217
+ it ( "logs the data table" , function ( ) {
218
+ prettyFormatter . handleStepResultEvent ( event , callback ) ;
219
+ expect ( prettyFormatter . logDataTable ) . toHaveBeenCalledWith ( dataTable ) ;
220
+ } ) ;
221
+ } ) ;
222
+
223
+ describe ( "when the step has no data table" , function ( ) {
224
+ beforeEach ( function ( ) {
225
+ step . hasDataTable . andReturn ( false ) ;
226
+ } ) ;
227
+
228
+ it ( "does no get the data table" , function ( ) {
229
+ prettyFormatter . handleStepResultEvent ( event , callback ) ;
230
+ expect ( step . getDataTable ) . not . toHaveBeenCalled ( ) ;
231
+ } ) ;
232
+
233
+ it ( "does not log the data table" , function ( ) {
234
+ prettyFormatter . handleStepResultEvent ( event , callback ) ;
235
+ expect ( prettyFormatter . logDataTable ) . not . toHaveBeenCalled ( ) ;
236
+ } ) ;
237
+ } ) ;
238
+
197
239
it ( "checks whether the step result is failed or not" , function ( ) {
198
240
prettyFormatter . handleStepResultEvent ( event , callback ) ;
199
241
expect ( stepResult . isFailed ) . toHaveBeenCalled ( ) ;
@@ -267,6 +309,32 @@ describe("Cucumber.Listener.PrettyFormatter", function () {
267
309
} ) ;
268
310
} ) ;
269
311
312
+ describe ( "logDataTable()" , function ( ) {
313
+ var dataTable , rows ;
314
+
315
+ beforeEach ( function ( ) {
316
+ rows = [
317
+ [ "cuk" , "cuke" , "cukejs" ] ,
318
+ [ "c" , "cuke" , "cuke.js" ] ,
319
+ [ "cu" , "cuke" , "cucumber" ]
320
+ ] ;
321
+ dataTable = createSpyWithStubs ( "data table" , { raw : rows } ) ;
322
+ spyOn ( prettyFormatter , "logIndented" ) ;
323
+ } ) ;
324
+
325
+ it ( "gets the rows from the table" , function ( ) {
326
+ prettyFormatter . logDataTable ( dataTable ) ;
327
+ expect ( dataTable . raw ) . toHaveBeenCalled ( ) ;
328
+ } ) ;
329
+
330
+ it ( "logs the lines with padding, indented by 3 levels" , function ( ) {
331
+ prettyFormatter . logDataTable ( dataTable ) ;
332
+ expect ( prettyFormatter . logIndented ) . toHaveBeenCalledWith ( "| cuk | cuke | cukejs |\n" , 3 ) ;
333
+ expect ( prettyFormatter . logIndented ) . toHaveBeenCalledWith ( "| c | cuke | cuke.js |\n" , 3 ) ;
334
+ expect ( prettyFormatter . logIndented ) . toHaveBeenCalledWith ( "| cu | cuke | cucumber |\n" , 3 ) ;
335
+ } ) ;
336
+ } ) ;
337
+
270
338
describe ( "logIndented()" , function ( ) {
271
339
var text , level , indented ;
272
340
0 commit comments