File: hook_order.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 (61 lines) | stat: -rw-r--r-- 1,829 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
  @spawn
  Feature: Hooks execute in defined order

  Background:
    Given a file named "features/step_definitions/steps.rb" with:
      """
      Given /^background step$/ do; $EventOrder.push(:background_step) end
      Given /^scenario step$/ do; $EventOrder.push(:scenario_step) end
      """
    And a file named "features/support/hooks.rb" with:
      """
      $EventOrder = []
      Around('@around') do |scenario,block|
        $EventOrder.push :around_begin
        block.call
        $EventOrder.push :around_end
      end
      Before('@before') do
        $EventOrder.push :before
      end
      After('@after') do |scenario|
        $EventOrder.push :after
      end
      at_exit {
        puts "Event order: #{$EventOrder.join(' ')}"
      }
      """
    And a file named "features/around_hook_covers_background.feature" with:
      """
      @around
      Feature: Around hooks cover background steps
        Background:
          Given background step
        Scenario:
          Given scenario step
      """
    And a file named "features/all_hook_order.feature" with:
      """
      @around
      @before
      @after
      Feature: All hooks execute in expected order
        Background:
          Given background step
        Scenario:
          Given scenario step
      """

  Scenario: Around hooks cover background steps
    When I run `cucumber -o /dev/null features/around_hook_covers_background.feature`
    Then the output should contain:
      """
      Event order: around_begin background_step scenario_step around_end
      """

  Scenario: All hooks execute in expected order
    When I run `cucumber -o /dev/null features/all_hook_order.feature`
    Then the output should contain:
      """
      Event order: around_begin before background_step scenario_step after around_end
      """