5

I'm working with a very large set of already existing cucumber features, and adding additional tests. For those new tests I'm also trying to use transforms to simplify repetitive tasks.

How can I add a transform without breaking already existing tests? I've already added context to the capture group, but since the context is from the same business domain as the pre-existing tests it can easily end up matching.

Is there a way to only apply a transform to certain steps?

4

1 回答 1

2

您可以使用标签和 Before 过滤器在 World 中设置实例变量。然后,您的 Transform 可以使用它,以便它可以执行特定于标签的转换。例如,如果您只想在存在 @hook 标记时转换整数:

Transform /(\d+)/ do |num|
  if @hook
    num.to_i
  else
    num
  end
end

Before('@hook') do
  @hook = true
end

为每个场景创建一个新世界,并调用 Before 过滤器。所以@hook 将为每个场景重置。

于 2012-04-30T12:51:11.290 回答