如何根据正在执行的功能文件加载 Cucumber 步骤定义

发布于 2024-09-28 11:07:44 字数 202 浏览 9 评论 0原文

我想修改 Cucumber,以便在执行给定功能时(例如“login.feature”),我只想为 Web 步骤加载 login_steps.rb 。不应加载其他步骤文件。

在我看来,如果具有相同的步骤,但在实施工作中与正在执行的功能名称有所不同,这将非常有用。

由于我有近一百个场景,并且我希望这些步骤是高级步骤,这才有意义。

有什么想法吗?

I would like to modify cucumber so that when a given feature is being executed (say "login.feature") I want only login_steps.rb to be loaded for the web steps. Other step files should not be loaded.

IMO this would be very useful to have the same steps but which differ in implementation work accordingly from the feature's name which is being executed.

Since I have almost a hundred scenarios and I would prefer if the steps were of high level steps this would make sense.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

柠北森屋 2024-10-05 11:07:44

目前,实现此目的的唯一方法(无需修补 Cucumber 本身)是将每个功能放入一个单独的目录树中,并具有自己的 env.rb 文件和 step_definitions 目录。

有关详细信息,请参阅邮件列表上的此帖子

Currently, the only way to accomplish this (short of patching cucumber itself) is to put each feature into a separate directory tree with its own env.rb file and step_definitions directory.

See this post on the mailing list for more details.

离线来电— 2024-10-05 11:07:44

您可以使用 Cellophane gem 实现类似的功能。它支持嵌套步骤定义,您可以关闭查找共享步骤。我不确定这是否能让你到达你想要的地方,但我发现如果可以修改玻璃纸来得到你想要的东西,开发人员会非常敏感。

You may be able to achieve something like this using the Cellophane gem. It supports nested step definitions and you can turn off looking for shared steps. I'm not sure this will get you all the way to where you want to be, but I've found the developer to be very responsive if cellophane could be modified to get you what you're looking for.

凉宸 2024-10-05 11:07:44

以下是为您提供的示例代码,

.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 是通用的。


Also, you can read behat document for better understanding - http://behat.readthedocs.org/

Here is sample code for you,

.feature file

Scenario: Some description of the scenario
Given [some context]
When [some event]
Then [outcome]

.rb (Step Definition in ruby)

Given /^[some context]$/ do
// code module
// code module
end
  • This step definition will execute whenever [some context] comes in feature file.

says,

Given [some context]
When [some context]
Then [some context]
And [some context]

will perform in same operation. i.e Given, When, Then and And are generic.


Also, you can read behat document for better understanding - http://behat.readthedocs.org/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文