You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

exception_in_after_step_hook.feature 3.3 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. Feature: Exception in AfterStep Block
  2. In order to use custom assertions at the end of each step
  3. As a developer
  4. I want exceptions raised in AfterStep blocks to be handled gracefully and reported by the formatters
  5. Background:
  6. Given the standard step definitions
  7. And a file named "features/step_definitions/naughty_steps.rb" with:
  8. """
  9. Given /^this step does something naughty$/ do x=1
  10. @naughty = true
  11. end
  12. """
  13. And a file named "features/support/env.rb" with:
  14. """
  15. class NaughtyStepException < Exception; end
  16. AfterStep do
  17. if @naughty
  18. raise NaughtyStepException.new("This step has been very very naughty")
  19. end
  20. end
  21. """
  22. Scenario: Handle Exception in standard scenario step and carry on
  23. Given a file named "features/naughty_step_in_scenario.feature" with:
  24. """
  25. Feature: Sample
  26. Scenario: Naughty Step
  27. Given this step does something naughty
  28. Scenario: Success
  29. Given this step passes
  30. """
  31. When I run `cucumber features`
  32. Then it should fail with:
  33. """
  34. Feature: Sample
  35. Scenario: Naughty Step # features/naughty_step_in_scenario.feature:3
  36. Given this step does something naughty # features/step_definitions/naughty_steps.rb:1
  37. This step has been very very naughty (NaughtyStepException)
  38. ./features/support/env.rb:4:in `AfterStep'
  39. Scenario: Success # features/naughty_step_in_scenario.feature:6
  40. Given this step passes # features/step_definitions/steps.rb:1
  41. Failing Scenarios:
  42. cucumber features/naughty_step_in_scenario.feature:3 # Scenario: Naughty Step
  43. 2 scenarios (1 failed, 1 passed)
  44. 2 steps (2 passed)
  45. """
  46. Scenario: Handle Exception in scenario outline table row and carry on
  47. Given a file named "features/naughty_step_in_scenario_outline.feature" with:
  48. """
  49. Feature: Sample
  50. Scenario Outline: Naughty Step
  51. Given this step <Might Work>
  52. Examples:
  53. | Might Work |
  54. | passes |
  55. | does something naughty |
  56. | passes |
  57. Scenario: Success
  58. Given this step passes
  59. """
  60. When I run `cucumber features`
  61. Then it should fail with:
  62. """
  63. Feature: Sample
  64. Scenario Outline: Naughty Step # features/naughty_step_in_scenario_outline.feature:3
  65. Given this step <Might Work> # features/naughty_step_in_scenario_outline.feature:4
  66. Examples:
  67. | Might Work |
  68. | passes |
  69. | does something naughty |
  70. This step has been very very naughty (NaughtyStepException)
  71. ./features/support/env.rb:4:in `AfterStep'
  72. | passes |
  73. Scenario: Success # features/naughty_step_in_scenario_outline.feature:12
  74. Given this step passes # features/step_definitions/steps.rb:1
  75. Failing Scenarios:
  76. cucumber features/naughty_step_in_scenario_outline.feature:9 # Scenario Outline: Naughty Step
  77. 4 scenarios (1 failed, 3 passed)
  78. 4 steps (4 passed)
  79. """

No Description

Contributors (1)