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
|
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 a file named "features/one_passing_one_failing.feature" with:
"""
@a
Feature: One passing scenario, one failing scenario
@b
Scenario: Passing
Given a passing step
@c
Scenario: Failing
Given a failing step
"""
And a file named "features/step_definitions/steps.rb" with:
"""
Given /a passing step/ do
#does nothing
end
Given /a failing step/ do
fail
end
Given /a pending step/ do
pending
end
Given /^I add (\d+) and (\d+)$/ do |a,b|
@result = a.to_i + b.to_i
end
Then /^I the result should be (\d+)$/ do |c|
@result.should == c.to_i
end
Then /^I should see/ do |string|
end
Given /^I pass a table argument/ do |table|
end
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/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/outline.feature" with:
"""
Feature: An outline feature
Scenario Outline: outline
Given a <type> step
Examples: examples1
| type |
| passing |
| failing |
Examples: examples2
| type |
| passing |
"""
And a file named "features/embed_data_directly.feature" with:
"""
Feature: An embed data directly feature
Scenario:
Given I embed data directly
"""
# 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": "@b",
"line": 4
}
],
"type": "scenario",
"steps": [
{
"keyword": "Given ",
"name": "a passing step",
"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": "@c",
"line": 8
}
],
"type": "scenario",
"steps": [
{
"keyword": "Given ",
"name": "a failing step",
"line": 10,
"match": {
"location": "features/step_definitions/steps.rb:5"
},
"result": {
"status": "failed",
"error_message": " (RuntimeError)\n./features/step_definitions/steps.rb:6:in `/a failing step/'\nfeatures/one_passing_one_failing.feature:10:in `Given a failing step'",
"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": "@b",
"line": 4
}
],
"type": "scenario",
"steps": [
{
"keyword": "Given ",
"name": "a passing step",
"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": "@c",
"line": 8
}
],
"type": "scenario",
"steps": [
{
"keyword": "Given ",
"name": "a failing step",
"line": 10,
"match": {
"location": "features/step_definitions/steps.rb:5"
},
"result": {
"status": "failed",
"error_message": " (RuntimeError)\n./features/step_definitions/steps.rb:6:in `/a failing step/'\nfeatures/one_passing_one_failing.feature:10:in `Given a failing step'",
"duration": 1
}
}
]
}
]
}
]
"""
@spawn
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/doc_string_steps.rb" with:
"""
Then /I should fail with/ do |s|
raise 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/doc_string_steps.rb:1"
},
"result": {
"status": "failed",
"error_message": "a string (RuntimeError)\n./features/step_definitions/doc_string_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 -b --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/steps.rb:29"
},
"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/steps.rb:34"
},
"result": {
"status": "passed",
"duration": 1
}
},
{
"keyword": "And ",
"name": "I print from step definition",
"line": 5,
"output": [
"from step definition"
],
"match": {
"location": "features/step_definitions/steps.rb:34"
},
"result": {
"status": "passed",
"duration": 1
}
}
]
}
]
}
]
"""
Scenario: embedding data directly
When I run `cucumber -b --format json 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/steps.rb:38"
},
"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",
"keyword": "Scenario Outline",
"name": "outline",
"line": 3,
"description": "",
"type": "scenario_outline",
"steps": [
{
"keyword": "Given ",
"name": "a <type> step",
"line": 4,
"match": {
"location": "features/step_definitions/steps.rb:1"
}
}
],
"examples": [
{
"keyword": "Examples",
"name": "examples1",
"line": 6,
"description": "",
"id": "an-outline-feature;outline;examples1",
"rows": [
{
"cells": [
"type"
],
"line": 7,
"id": "an-outline-feature;outline;examples1;1"
},
{
"cells": [
"passing"
],
"line": 8,
"id": "an-outline-feature;outline;examples1;2"
},
{
"cells": [
"failing"
],
"line": 9,
"id": "an-outline-feature;outline;examples1;3"
}
]
},
{
"keyword": "Examples",
"name": "examples2",
"line": 11,
"description": "",
"id": "an-outline-feature;outline;examples2",
"rows": [
{
"cells": [
"type"
],
"line": 12,
"id": "an-outline-feature;outline;examples2;1"
},
{
"cells": [
"passing"
],
"line": 13,
"id": "an-outline-feature;outline;examples2;2"
}
]
}
]
}
]
}
]
"""
@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": "a passing step",
"line": 4,
"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": "a failing step",
"line": 4,
"match": {
"location": "features/step_definitions/steps.rb:5"
},
"result": {
"status": "failed",
"error_message" : " (RuntimeError)\n./features/step_definitions/steps.rb:6:in `/a failing step/'\nfeatures/outline.feature:4:in `Given a <type> step'",
"duration": 1
}
}
]
},
{
"id": "an-outline-feature;outline;examples2;2",
"keyword": "Scenario Outline",
"name": "outline",
"line": 13,
"description": "",
"type": "scenario",
"steps": [
{
"keyword": "Given ",
"name": "a passing step",
"line": 4,
"match": {
"location": "features/step_definitions/steps.rb:1"
},
"result": {
"status": "passed",
"duration": 1
}
}
]
}
]
}
]
"""
|