max pleaner max pleaner - 1 year ago 55
Ruby Question

Run cucumber .feature file through ERB preprocessor

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

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

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 = path
result =
new_path = path.gsub(".feature.erb", ".feature"), 'w') do |f|
f.write result

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download