简体   繁体   English

通过ERB预处理程序运行Cucumber .feature文件

[英]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. 我了解到Cucumber .feature文件中不存在对变量的支持,但是如果我可以通过ERB预处理程序运行它们,则没有必要。

I'd like to be able to make a file like my_tests.feature.erb : 我希望能够制作一个像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. 我想知道是否已经有东西了。

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. 您始终可以将需求下推到步骤定义和支持代码中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM