Definition of a change in cucumber

I work with a very large set of existing functions of the cucumber and add additional tests. For these new tests, I am also trying to use transforms to simplify repetitive tasks.

How can I add a transform without breaking existing tests? I already added context to the capture group, but since the context belongs to the same business domain as the existing tests, it can easily be combined with it.

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

+5
source share
1 answer

You can use the tag and filter Before to set the instance variable in World. This is then available to your Transform so that it can perform tag specific conversions. For example, if you want to convert integers when the @hook tag is present:

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

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

A new world is created for each scenario and Before filters are called. So @hook will reset for each scenario.

+2
source

All Articles