Calling Block multiple times in Cucumber Around Hook (Ruby)

前端 未结 2 1246
眼角桃花
眼角桃花 2021-01-14 20:24

I\'m trying to run a scenario several (30) times in order to get a nice statistical sample. However the block is only executing once; each subsequent time results in the sce

2条回答
  •  庸人自扰
    2021-01-14 20:25

    Currently Cucumber does not seem to support calling the block twice in an around hook. This can be demonstrated by the following feature file:

    Feature: This scenario will print a line
    
      Scenario: Print a line
        When I print a line
    

    And step definitions:

    Around do |scenario, block|
      Kernel.puts "START AROUND, status=#{scenario.status}"
      block.call
      Kernel.puts "BETWEEN CALLS, status=#{scenario.status}"
      block.call
      Kernel.puts "END AROUND, status=#{scenario.status}"
    end
    
    When /^I print a line$/ do
      Kernel.puts "IN THE STEP DEFINITION"
    end
    

    When this is executed, Cucumber will print:

      Scenario: Print line  # features/test1.feature:3
    START AROUND, status=skipped
    IN THE STEP DEFINITION
        When I print a line # features/test.rb:9
    BETWEEN CALLS, status=passed
        When I print a line # features/test.rb:9
    END AROUND, status=passed
    

    Evidently since the status of the scenario is already "passed", Cucumber does not re-execute it, though the output formatter receives the steps. I have not found any way to "reset" the status in the scenario API to get them to be re-run.

    There are other problems with around hooks as well, for example you cannot set variables to the World in around hooks (like you can in before hooks). See also Cucumber issues 52 and 116 for more gory details.

提交回复
热议问题