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.

after_hooks.feature 2.6 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. Feature: After Hooks
  2. After hooks can be used to clean up any state you've altered during your
  3. scenario, or to check the status of the scenario and act accordingly.
  4. You can ask a scenario whether it has failed, for example.
  5. Mind you, even if it hasn't failed yet, you can still make the scenario
  6. fail if your After hook throws an error.
  7. Background:
  8. Given the standard step definitions
  9. Scenario Outline: Retrieve the status of a scenario as a symbol
  10. Given a file named "features/support/debug_hook.rb" with:
  11. """
  12. After do |scenario|
  13. log scenario.status.inspect
  14. end
  15. """
  16. And a file named "features/result.feature" with:
  17. """
  18. Feature:
  19. Scenario:
  20. Given this step <result>
  21. """
  22. When I run `cucumber -f progress`
  23. Then the output should contain "<status symbol>"
  24. Examples:
  25. | result | status symbol |
  26. | passes | :passed |
  27. | fails | :failed |
  28. | is pending | :pending |
  29. Scenario: Check the failed status of a scenario in a hook
  30. Given a file named "features/support/debug_hook.rb" with:
  31. """
  32. After do |scenario|
  33. if scenario.failed?
  34. log "eek"
  35. end
  36. end
  37. """
  38. And a file named "features/fail.feature" with:
  39. """
  40. Feature:
  41. Scenario:
  42. Given this step fails
  43. """
  44. When I run `cucumber -f progress`
  45. Then the output should contain:
  46. """
  47. eek
  48. """
  49. Scenario: Make a scenario fail from an After hook
  50. Given a file named "features/support/bad_hook.rb" with:
  51. """
  52. After do
  53. fail 'yikes'
  54. end
  55. """
  56. And a file named "features/pass.feature" with:
  57. """
  58. Feature:
  59. Scenario:
  60. Given this step passes
  61. """
  62. When I run `cucumber -f pretty`
  63. Then it should fail with:
  64. """
  65. Scenario: # features/pass.feature:2
  66. Given this step passes # features/step_definitions/steps.rb:1
  67. yikes (RuntimeError)
  68. ./features/support/bad_hook.rb:2:in `After'
  69. """
  70. Scenario: After hooks are executed in reverse order of definition
  71. Given a file named "features/support/hooks.rb" with:
  72. """
  73. After do
  74. log "First"
  75. end
  76. After do
  77. log "Second"
  78. end
  79. """
  80. And a file named "features/pass.feature" with:
  81. """
  82. Feature:
  83. Scenario:
  84. Given this step passes
  85. """
  86. When I run `cucumber -f progress`
  87. Then the output should contain:
  88. """
  89. Second
  90. First
  91. """

No Description

Contributors (1)