File: json_formatter.feature

package info (click to toggle)
cucumber 2.4.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,076 kB
  • sloc: ruby: 17,016; javascript: 4,641; makefile: 12; sh: 10; tcl: 3
file content (767 lines) | stat: -rw-r--r-- 21,846 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
Feature: JSON output formatter
  In order to simplify processing of Cucumber features and results
  Developers should be able to consume features as JSON

  Background:
    Given the standard step definitions
    And a file named "features/one_passing_one_failing.feature" with:
      """
      @a
      Feature: One passing scenario, one failing scenario

        @b
        Scenario: Passing
          Given this step passes

        @c
        Scenario: Failing
          Given this step fails
      """
    And a file named "features/step_definitions/json_steps.rb" with:
      """
      Given /^I embed a screenshot/ do
        File.open("screenshot.png", "w") { |file| file << "foo" }
        embed "screenshot.png", "image/png"
      end

      Given /^I print from step definition/ do
        puts "from step definition"
      end

      Given /^I embed data directly/ do
        data = "YWJj"
        embed data, "mime-type;base64"
      end
      """
    And a file named "features/embed.feature" with:
      """
      Feature: A screenshot feature

        Scenario:
          Given I embed a screenshot

      """
    And a file named "features/outline.feature" with:
      """
      Feature: An outline feature

        Scenario Outline: outline
          Given this step <status>

          Examples: examples1
            | status |
            | passes |
            | fails  |

          Examples: examples2
            | status |
            | passes |
      """
    And a file named "features/print_from_step_definition.feature" with:
      """
      Feature: A print from step definition feature

        Scenario:
          Given I print from step definition
          And I print from step definition

      """
    And a file named "features/print_from_step_definition.feature" with:
      """
      Feature: A print from step definition feature

        Scenario:
          Given I print from step definition
          And I print from step definition

      """
    And a file named "features/embed_data_directly.feature" with:
      """
      Feature: An embed data directly feature

        Scenario:
          Given I embed data directly

        Scenario Outline:
          Given I embed data directly

	  Examples:
	  | dummy |
	  |  1    |
	  |  2    |

      """
    And a file named "features/out_scenario_out_scenario_outline.feature" with:
      """
      Feature:
        Scenario:
          Given this step passes
        Scenario Outline:
          Given this step <status>
          Examples:
          | status |
          | passes |
      """

  # Need to investigate why this won't pass in-process. error_message doesn't get det?
  @spawn
  Scenario: one feature, one passing scenario, one failing scenario
    When I run `cucumber --format json features/one_passing_one_failing.feature`
    Then it should fail with JSON:
      """
      [
        {
          "uri": "features/one_passing_one_failing.feature",
          "keyword": "Feature",
          "id": "one-passing-scenario,-one-failing-scenario",
          "name": "One passing scenario, one failing scenario",
          "line": 2,
          "description": "",
          "tags": [
            {
              "name": "@a",
              "line": 1
            }
          ],
          "elements": [
            {
              "keyword": "Scenario",
              "id": "one-passing-scenario,-one-failing-scenario;passing",
              "name": "Passing",
              "line": 5,
              "description": "",
              "tags": [
                {
                  "name": "@a",
                  "line": 1
                },
                {
                  "name": "@b",
                  "line": 4
                }
              ],
              "type": "scenario",
              "steps": [
                {
                  "keyword": "Given ",
                  "name": "this step passes",
                  "line": 6,
                  "match": {
                    "location": "features/step_definitions/steps.rb:1"
                  },
                  "result": {
                    "status": "passed",
                    "duration": 1
                  }
                }
              ]
            },
            {
              "keyword": "Scenario",
              "id": "one-passing-scenario,-one-failing-scenario;failing",
              "name": "Failing",
              "line": 9,
              "description": "",
              "tags": [
                {
                  "name": "@a",
                  "line": 1
                },
                {
                  "name": "@c",
                  "line": 8
                }
              ],
              "type": "scenario",
              "steps": [
                {
                  "keyword": "Given ",
                  "name": "this step fails",
                  "line": 10,
                  "match": {
                    "location": "features/step_definitions/steps.rb:4"
                  },
                  "result": {
                    "status": "failed",
                    "error_message": " (RuntimeError)\n./features/step_definitions/steps.rb:4:in `/^this step fails$/'\nfeatures/one_passing_one_failing.feature:10:in `Given this step fails'",
                    "duration": 1
                  }
                }
              ]
            }
          ]
        }
      ]

      """

  @spawn
  Scenario: one feature, one passing scenario, one failing scenario with prettyfied json
    When I run `cucumber --format json_pretty features/one_passing_one_failing.feature`
    Then it should fail with JSON:
      """
      [
        {
          "uri": "features/one_passing_one_failing.feature",
          "keyword": "Feature",
          "id": "one-passing-scenario,-one-failing-scenario",
          "name": "One passing scenario, one failing scenario",
          "line": 2,
          "description": "",
          "tags": [
            {
              "name": "@a",
              "line": 1
            }
          ],
          "elements": [
            {
              "keyword": "Scenario",
              "id": "one-passing-scenario,-one-failing-scenario;passing",
              "name": "Passing",
              "line": 5,
              "description": "",
              "tags": [
                {
                  "name": "@a",
                  "line": 1
                },
                {
                  "name": "@b",
                  "line": 4
                }
              ],
              "type": "scenario",
              "steps": [
                {
                  "keyword": "Given ",
                  "name": "this step passes",
                  "line": 6,
                  "match": {
                    "location": "features/step_definitions/steps.rb:1"
                  },
                  "result": {
                    "status": "passed",
                    "duration": 1
                  }
                }
              ]
            },
            {
              "keyword": "Scenario",
              "id": "one-passing-scenario,-one-failing-scenario;failing",
              "name": "Failing",
              "line": 9,
              "description": "",
              "tags": [
                {
                  "name": "@a",
                  "line": 1
                },
                {
                  "name": "@c",
                  "line": 8
                }
              ],
              "type": "scenario",
              "steps": [
                {
                  "keyword": "Given ",
                  "name": "this step fails",
                  "line": 10,
                  "match": {
                    "location": "features/step_definitions/steps.rb:4"
                  },
                  "result": {
                    "status": "failed",
                    "error_message": " (RuntimeError)\n./features/step_definitions/steps.rb:4:in `/^this step fails$/'\nfeatures/one_passing_one_failing.feature:10:in `Given this step fails'",
                    "duration": 1
                  }
                }
              ]
            }
          ]
        }
      ]

      """

  Scenario: DocString
    Given a file named "features/doc_string.feature" with:
      """
      Feature: A DocString feature

        Scenario:
          Then I should fail with
            \"\"\"
            a string
            \"\"\"
      """
    And a file named "features/step_definitions/steps.rb" with:
      """
      Then /I should fail with/ do |s|
        raise RuntimeError, s
      end
      """
    When I run `cucumber --format json features/doc_string.feature`
    Then it should fail with JSON:
      """
      [
        {
          "id": "a-docstring-feature",
          "uri": "features/doc_string.feature",
          "keyword": "Feature",
          "name": "A DocString feature",
          "line": 1,
          "description": "",
          "elements": [
            {
              "id": "a-docstring-feature;",
              "keyword": "Scenario",
              "name": "",
              "line": 3,
              "description": "",
              "type": "scenario",
              "steps": [
                {
                  "keyword": "Then ",
                  "name": "I should fail with",
                  "line": 4,
                  "doc_string": {
                    "content_type": "",
                    "value": "a string",
                    "line": 5
                  },
                  "match": {
                    "location": "features/step_definitions/steps.rb:1"
                  },
                  "result": {
                    "status": "failed",
                    "error_message": "a string (RuntimeError)\n./features/step_definitions/steps.rb:2:in `/I should fail with/'\nfeatures/doc_string.feature:4:in `Then I should fail with'",
                    "duration": 1
                  }
                }
              ]
            }
          ]
        }
      ]
      """

  Scenario: embedding screenshot
    When I run `cucumber --format json features/embed.feature`
    Then it should pass with JSON:
    """
    [
      {
        "uri": "features/embed.feature",
        "id": "a-screenshot-feature",
        "keyword": "Feature",
        "name": "A screenshot feature",
        "line": 1,
        "description": "",
        "elements": [
          {
            "id": "a-screenshot-feature;",
            "keyword": "Scenario",
            "name": "",
            "line": 3,
            "description": "",
            "type": "scenario",
            "steps": [
              {
                "keyword": "Given ",
                "name": "I embed a screenshot",
                "line": 4,
                "embeddings": [
                  {
                    "mime_type": "image/png",
                    "data": "Zm9v"
                  }
                ],
                "match": {
                  "location": "features/step_definitions/json_steps.rb:1"
                },
                "result": {
                  "status": "passed",
                  "duration": 1
                }
              }
            ]
          }
        ]
      }
    ]

    """

  @spawn
  Scenario: scenario outline
    When I run `cucumber --format json features/outline.feature`
    Then it should fail with JSON:
    """
    [
      {
        "uri": "features/outline.feature",
        "id": "an-outline-feature",
        "keyword": "Feature",
        "name": "An outline feature",
        "line": 1,
        "description": "",
        "elements": [
          {
            "id": "an-outline-feature;outline;examples1;2",
            "keyword": "Scenario Outline",
            "name": "outline",
            "description": "",
            "line": 8,
            "type": "scenario",
            "steps": [
              {
                "keyword": "Given ",
                "name": "this step passes",
                "line": 8,
                "match": {
                  "location": "features/step_definitions/steps.rb:1"
                },
                "result": {
                  "status": "passed",
                  "duration": 1
                }
              }
            ]
          },
          {
            "id": "an-outline-feature;outline;examples1;3",
            "keyword": "Scenario Outline",
            "name": "outline",
            "description": "",
            "line": 9,
            "type": "scenario",
            "steps": [
              {
                "keyword": "Given ",
                "name": "this step fails",
                "line": 9,
                "match": {
                  "location": "features/step_definitions/steps.rb:4"
                },
                "result": {
                  "status": "failed",
                  "error_message": " (RuntimeError)\n./features/step_definitions/steps.rb:4:in `/^this step fails$/'\nfeatures/outline.feature:9:in `Given this step fails'\nfeatures/outline.feature:4:in `Given this step <status>'",
                  "duration": 1
                }
              }
            ]
          },
          {
            "id": "an-outline-feature;outline;examples2;2",
            "keyword": "Scenario Outline",
            "name": "outline",
            "description": "",
            "line": 13,
            "type": "scenario",
            "steps": [
              {
                "keyword": "Given ",
                "name": "this step passes",
                "line": 13,
                "match": {
                  "location": "features/step_definitions/steps.rb:1"
                },
                "result": {
                  "status": "passed",
                  "duration": 1
                }
              }
            ]
          }
        ]
      }
    ]

    """

  Scenario: print from step definition
    When I run `cucumber --format json features/print_from_step_definition.feature`
    Then it should pass with JSON:
    """
    [
      {
        "uri": "features/print_from_step_definition.feature",
        "id": "a-print-from-step-definition-feature",
        "keyword": "Feature",
        "name": "A print from step definition feature",
        "line": 1,
        "description": "",
        "elements": [
          {
            "id": "a-print-from-step-definition-feature;",
            "keyword": "Scenario",
            "name": "",
            "line": 3,
            "description": "",
            "type": "scenario",
            "steps": [
              {
                "keyword": "Given ",
                "name": "I print from step definition",
                "line": 4,
                "output": [
                  "from step definition"
                ],
                "match": {
                  "location": "features/step_definitions/json_steps.rb:6"
                },
                "result": {
                  "status": "passed",
                  "duration": 1
                }
              },
              {
                "keyword": "And ",
                "name": "I print from step definition",
                "line": 5,
                "output": [
                  "from step definition"
                ],
                "match": {
                  "location": "features/step_definitions/json_steps.rb:6"
                },
                "result": {
                  "status": "passed",
                  "duration": 1
                }
              }
            ]
          }
        ]
      }
    ]

    """

  @spawn
  Scenario: scenario outline expanded
    When I run `cucumber --expand --format json features/outline.feature`
    Then it should fail with JSON:
    """
    [
      {
        "uri": "features/outline.feature",
        "id": "an-outline-feature",
        "keyword": "Feature",
        "name": "An outline feature",
        "line": 1,
        "description": "",
        "elements": [
          {
            "id": "an-outline-feature;outline;examples1;2",
            "keyword": "Scenario Outline",
            "name": "outline",
            "line": 8,
            "description": "",
            "type": "scenario",
            "steps": [
              {
                "keyword": "Given ",
                "name": "this step passes",
                "line": 8,
                "match": {
                  "location": "features/step_definitions/steps.rb:1"
                },
                "result": {
                  "status": "passed",
                  "duration": 1
                }
              }
            ]
          },
          {
            "id": "an-outline-feature;outline;examples1;3",
            "keyword": "Scenario Outline",
            "name": "outline",
            "line": 9,
            "description": "",
            "type": "scenario",
            "steps": [
              {
                "keyword": "Given ",
                "name": "this step fails",
                "line": 9,
                "match": {
                  "location": "features/step_definitions/steps.rb:4"
                },
                "result": {
                  "status": "failed",
                  "error_message" : " (RuntimeError)\n./features/step_definitions/steps.rb:4:in `/^this step fails$/'\nfeatures/outline.feature:9:in `Given this step fails'\nfeatures/outline.feature:4:in `Given this step <status>'",
		  "duration": 1
                }
              }
            ]
          },
          {
            "id": "an-outline-feature;outline;examples2;2",
            "keyword": "Scenario Outline",
            "name": "outline",
            "line": 13,
            "description": "",
            "type": "scenario",
            "steps": [
              {
                "keyword": "Given ",
                "name": "this step passes",
                "line": 13,
                "match": {
                  "location": "features/step_definitions/steps.rb:1"
                },
                "result": {
                  "status": "passed",
                  "duration": 1
                }
              }
            ]
          }
        ]
      }
    ]

    """

  Scenario: embedding data directly
    When I run `cucumber --format json -x features/embed_data_directly.feature`
    Then it should pass with JSON:
    """
    [
      {
        "uri": "features/embed_data_directly.feature",
        "id": "an-embed-data-directly-feature",
        "keyword": "Feature",
        "name": "An embed data directly feature",
        "line": 1,
        "description": "",
        "elements": [
          {
            "id": "an-embed-data-directly-feature;",
            "keyword": "Scenario",
            "name": "",
            "line": 3,
            "description": "",
            "type": "scenario",
            "steps": [
              {
                "keyword": "Given ",
                "name": "I embed data directly",
                "line": 4,
                "embeddings": [
                  {
		    "mime_type": "mime-type",
		    "data": "YWJj"
                  }
                ],
                "match": {
                  "location": "features/step_definitions/json_steps.rb:10"
                },
                "result": {
                  "status": "passed",
                  "duration": 1
                }
              }
            ]
          },
          {
            "keyword": "Scenario Outline",
            "name": "",
            "line": 11,
            "description": "",
            "id": "an-embed-data-directly-feature;;;2",
            "type": "scenario",
            "steps": [
              {
                "keyword": "Given ",
                "name": "I embed data directly",
                "line": 11,
                "embeddings": [
                  {
                    "mime_type": "mime-type",
                    "data": "YWJj"
                  }
                ],
                "match": {
                  "location": "features/step_definitions/json_steps.rb:10"
                },
                "result": {
                  "status": "passed",
                  "duration": 1
                }
              }
            ]
          },
          {
            "keyword": "Scenario Outline",
            "name": "",
            "line": 12,
            "description": "",
            "id": "an-embed-data-directly-feature;;;3",
            "type": "scenario",
            "steps": [
              {
                "keyword": "Given ",
                "name": "I embed data directly",
                "line": 12,
                "embeddings": [
                  {
                    "mime_type": "mime-type",
                    "data": "YWJj"
                  }
                ],
                "match": {
                  "location": "features/step_definitions/json_steps.rb:10"
                },
                "result": {
                  "status": "passed",
                  "duration": 1
                }
              }
            ]
          }
        ]
      }
    ]

    """
  Scenario: handle output from hooks
     Given a file named "features/step_definitions/output_steps.rb" with:
      """
      Before do
        puts "Before hook 1"
        embed "src", "mime_type", "label"
      end

      Before do
        puts "Before hook 2"
        embed "src", "mime_type", "label"
      end

      AfterStep do
        puts "AfterStep hook 1"
        embed "src", "mime_type", "label"
      end

      AfterStep do
        puts "AfterStep hook 2"
        embed "src", "mime_type", "label"
      end

      After do
        puts "After hook 1"
        embed "src", "mime_type", "label"
      end

      After do
        puts "After hook 2"
        embed "src", "mime_type", "label"
      end
      """
    When I run `cucumber --format json features/out_scenario_out_scenario_outline.feature`
    Then it should pass