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?
You could use a tag and a Before filter to set an instance variable in the World. This is then available to your Transform so that it can perform tag-specific transforms. For example, if you only wanted to Transform 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 the Before filters are called. So @hook will be reset for each Scenario.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With