【问题标题】:How to exclude files/directories when running a Cucumber Rake task?运行 Cucumber Rake 任务时如何排除文件/目录?
【发布时间】:2015-09-03 04:20:46
【问题描述】:

我的场景文件夹中目前有两个具有不同功能的文件夹:

features
  scenarios
    folder_1
      first_feature.feature
    folder_2
      second_feature.feature

在这些功能中,我有许多共享一些不同标签的场景

first_feature.feature:

Feature: One
  @tag1 @tag2
  Scenario: Scenario 1

  @tag3
  Scenario: Scenario 2

second_feature.feature:

Feature: Two
  @tag1 @tag4
  Scenario: Scenario 3

所以问题来了:我有一个 rake 任务,它遍历我的场景并使用标签 @tag1 运行所有内容。现在,其中包括功能 1 中的场景 1 和功能 2 中的场景 3。在不更改任何标签或场景的情况下,我可以在我的 rake 任务中添加任何内容来告诉它忽略某个文件/文件夹中的任何测试吗?在上面的示例中,我希望我的 rake 任务忽略它在 folder_2 中找到的任何场景,因此即使场景 3 有 @tag1,它也不会运行。

我目前的 rake 任务:

Cucumber::Rake::Task.new(:all_tag_1) do |t|
  tags = '--tags ~@wip --tags @tag1'
  t.cucumber_opts = "--format html --out features/build_results/all_tag_1.html --format pretty #{tags} --format junit --out features/build_results/reports"
end

部分问题是我搜索了互联网和 Cucumber 文档,但无法找到列出 cucumber_opts 的所有有效选项的任何地方。如果有人能指出我正确的方向以找到不同可能性的列表,那将不胜感激。

谢谢。

【问题讨论】:

    标签: ruby tags cucumber rake


    【解决方案1】:

    Cucumber::Rake::Task.new(:all_tag_1) do |t| tags = '--tags ~@wip --tags @tag1' t.cucumber_opts = "features/scenarios/folder_1 --format html --out features/build_results/all_tag_1.html --format pretty #{tags} --format junit --out features/build_results/reports" end

    此命令只会运行 features/scenarios/folder_1 文件夹中的场景...

    【讨论】:

    • 感谢运行单个文件夹的帮助,这肯定会有所帮助。正如您可以想象的那样,这个特定的场景有点简化。实际上,我想运行 100 个文件夹,但我只想排除几个。我想我可以使用您的建议来运行多个文件夹或使用通配符,但我真正想要的是一个“排除”命令。
    • 好的,我明白了。我认为您可以使用标签功能(--tags ~@exclude)来排除场景。让我知道这是否适合您。
    • 这就是我们最终要做的。但是,在我们要排除的文件夹中,有大约 25 个功能和 100 个场景。即使我们在功能级别添加标签,也需要管理 25 个额外的标签。如果 Cucumber 有办法包含/排除整个文件夹,那会更简单,但我开始认为这只是不存在的功能。谢谢你的帮助:)
    猜你喜欢
    • 1970-01-01
    • 2012-05-30
    • 2010-10-09
    • 1970-01-01
    • 2014-06-16
    • 2011-11-02
    • 2011-08-04
    • 2020-06-18
    • 1970-01-01
    相关资源
    最近更新 更多