max pleaner max pleaner - 13 days ago 5
Ruby Question

Run cucumber .feature file through ERB preprocessor

I get that there's not existing support for variables in Cucumber

.feature
files, but if I could run them through a ERB preprocessor there'd be no need.

I'd like to be able to make a file like
my_tests.feature.erb
:

Feature: Do something
Scenario: Thing
When I have the secret password <%= ENV["PASSWORD"] %>
Then my credentials are valid


I've written a quick solution here:

require 'erb'

Dir.glob("./*.feature.erb").each do |path|
erb = File.read path
result = ERB.new(erb).result(binding)
new_path = path.gsub(".feature.erb", ".feature")
File.open(new_path, 'w') do |f|
f.write result
end
end


I'm wondering if there's something already out there.

Answer

Why on earth would you do this when you can just write

When 'I use the secret password' 

and have your step definition call code to get the password. By adding an extra pre-processing step you are making your whole test suite much more complex and fragile.

There is never any need for the language of scenarios to get information about how to do something from external sources. You can always push that requirement down into step definitions and supporting code.

Comments