Calling Block multiple times in Cucumber Around Hook (Ruby)

前端 未结 2 1251
眼角桃花
眼角桃花 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:29

    One possibility might be to keep the passed-in block as it is, and call the ".call" method on a duplicate? Something like (untested):

    Around do |scenario, block|
      30.times do
        duplicate = block.dup
        before_hook(scenario)
        duplicate.call
        after_hook(scenario)
      end
    end
    

    Just make sure not to use ".clone" on the block, since clone will create an object with the same Id, resulting in every change made to the duplicate also affecting the original.

提交回复
热议问题