【问题标题】:How to make Cucumber step definitions load according to feature file being executed如何根据正在执行的功能文件加载 Cucumber 步骤定义
【发布时间】:2010-10-22 10:03:08
【问题描述】:
我想修改 cucumber,以便在执行给定功能时(比如“login.feature”),我只希望为 web 步骤加载 login_steps.rb。不应加载其他步骤文件。
IMO 如果具有相同的步骤,但在实现工作上与正在执行的功能名称不同,这将非常有用。
因为我有将近一百个场景,如果这些步骤是高级步骤,我更愿意这样做。
有什么想法吗?
【问题讨论】:
标签:
ruby-on-rails
open-source
cucumber
bdd
gherkin
【解决方案1】:
目前,实现这一点的唯一方法(不修补黄瓜本身)是将每个功能放入一个单独的目录树中,其中包含自己的 env.rb 文件和 step_definitions 目录。
有关详细信息,请参阅邮件列表中的this post。
【解决方案2】:
您可以使用Cellophane gem 实现类似的效果。它支持嵌套步骤定义,您可以关闭查找共享步骤。我不确定这是否会让你一直到达你想去的地方,但我发现如果可以修改玻璃纸来获得你想要的东西,开发人员会非常敏感。
【解决方案3】:
这是给你的示例代码,
.feature 文件
Scenario: Some description of the scenario
Given [some context]
When [some event]
Then [outcome]
.rb(ruby 中的步骤定义)
Given /^[some context]$/ do
// code module
// code module
end
- 只要
[some context] 进入功能文件,就会执行此步骤定义。
说,
Given [some context]
When [some context]
Then [some context]
And [some context]
将执行相同的操作。即 Given、When、Then 和 And 是通用的。
此外,您可以阅读 behat 文档以更好地理解 -
http://behat.readthedocs.org/