【问题标题】:How do you get cucumber/guard to filter on tags like @wip?你如何让 cucumber/guard 过滤像@wip 这样的标签?
【发布时间】:2012-02-29 21:02:00
【问题描述】:

我正在运行 spork 和 guard,并且我的 RSpec 测试运行正常,一切都进行得很好。为了加快测试速度,我可以使用我放置在.rspec 文件中的标签成功过滤我的 RSpec 测试。

.rspec

--colour
--debug
--tag focus
--tag now

很遗憾,虽然我无法过滤我的黄瓜标签。每次 cucumber 运行时,它都会运行 everything 或仅运行已更改的文件。

如何让 cucumber/spork/guard 尊重 @wip、@now 等标签并只运行这些测试?是否有一些相当于.rspec 文件的黄瓜标签?

【问题讨论】:

    标签: cucumber spork guard


    【解决方案1】:

    您可以使用黄瓜配置文件来定义要执行的标签。使用 YML 文件,您可以定义执行 @wip 标签的配置文件:

    wip: --tags @wip
    

    更多信息请访问:

    https://github.com/cucumber/cucumber/wiki/cucumber.yml

    你也可以从命令行运行 cucumber 并传递 -t 参数:

    cucumber -t @wip,@now
    

    来自帮助(黄瓜 -h):

    只执行标签匹配的功能或场景 TAG_EXPRESSION。 场景继承在功能级别上声明的标签。最简单的 TAG_EXPRESSION 只是一个标签。示例:--tags @dev。当标签中的标签 表达式以 ~ 开头,这表示布尔 NOT。示例:--tags ~@dev。 一个标签表达式可以有多个标签,用逗号分隔,表示 逻辑或。示例:--tags @dev,@wip。可以指定 --tags 选项 几次,这表示逻辑与。示例:--tags @foo,~@bar --tags @zap。 这表示布尔表达式 (@foo || !@bar) && @zap

    因此,理论上我们可以通过以下选项使用保护文件:

    guard 'cucumber', :cli => "--drb --tags @now" do
      watch(%r{^features/.+\.feature$})
      ...
    end
    

    【讨论】:

    • 感谢丹。我可以从命令行运行标签,但据我所知,我不能将选项传递给bundle exec guard 命令,因此您建议配置文件必须是关键。当我可以确认我已经得到它的工作时,我会回来
    • 嗨,丹,我刚刚尝试了你的建议,虽然我无法让它发挥作用,但我怀疑这是我在实施中的错误。我想将您的答案标记为正确答案。您能否结合我在下面给出的答案来展示如何通过保护文件传递命令行参数。如果你能做到,那么我会删除我的并将你的标记为正确。
    • Pete 怎么样?让我知道你的 cmets。
    • 感谢 Dan - 出于某种原因,它没有告诉我您发表了评论 - 现在标记为正确。干杯!
    【解决方案2】:

    要理解的一个重要概念是标签配置文件之间存在差异。我也在将 Guard 与 Cucumber 一起使用,并且对继续使用默认配置文件并且我的 @wip(正在进行的工作)标签都没有被拾取感到沮丧。现在很明显为什么会这样。正如其他论坛中的一些人所说,我的默认配置文件过滤掉了@wip。

    <%
    rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
    rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
    base_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}"
    std_opts = "#{base_opts} --strict --tags ~@wip"
    wip_opts = base_opts
    %>
    default: --drb <%= std_opts %> features
    wip: --drb <%= wip_opts %> --tags @wip:3 --wip features
    rerun: --drb <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
    

    "std_opts = "#{base_opts} --strict --tags ~@wip" wip在std_opts中被过滤掉

    我想使用“wip”配置文件,其中包含用“@wip”标记的场景或功能!

    wip: --drb --tags @wip:3 --wip features" 该数字表示要运行的最大场景数;' --wip' 表示 Cuc 预计测试将失败(因为我们正在处理它)

    所以标签已经配置好了,我已经在我的 *.feature 文件中包含了“@wip”。简介呢?使用 Guard (Spork) 时,为了使用“wip”配置文件,需要对其进行配置。这说得通;电脑读不懂我的心!更新 Guardfile 以使用“wip”配置文件。

    guard 'cucumber', :cli => "--drb -p wip", :all_on_start => false, :all_after_pass => false do
      watch(%r{^features/.+\.feature$})
      watch(%r{^features/support/.+$})          { 'features' }
      watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
    end
    

    guard 'cucumber', :cli => "--drb -p wip" '-p' 指定所需的配置文件

    现在我的场景已成功被“wip”过滤。

    【讨论】:

      【解决方案3】:

      不确定何时引入此选项,但guard-cucumber 能够专注于特定标签(这与硬编码特定标签以始终过滤不同)。您可以将此配置选项保留在您的 Guardfile 中,并且仅在需要时使用您的焦点标签:

      # Guardfile
      guard 'cucumber', :focus_on => 'myfocustag' do
        ...
      end
      
      # example.feature
      Feature: Example
      
        @myfocustag
        Scenario: Only run this one
        ...
      

      cucumber-guard 将过滤这些场景,然后将它们传递给 cucumber 命令。删除这些标签将导致默认行为(运行所有场景,而不是不运行)。

      【讨论】:

        【解决方案4】:

        虽然理论上应该可以使用黄瓜配置文件来完成这项工作,但我发现我必须使用guardfile

        原始保护文件

        guard 'cucumber', :cli => "--drb" do
          watch(%r{^features/.+\.feature$})
          ...
        end
        

        修改后的保护文件

        guard 'cucumber', :cli => "--drb --tags @now" do
          watch(%r{^features/.+\.feature$})
          ...
        end
        

        【讨论】:

          【解决方案5】:

          现在,如果您希望 Guard 始终像我一样运行 @wip,那么在您的添加中:

          cucumber.yml

          guard: --format pretty --tags @wip
          

          保护文件

          guard 'cucumber', :command_prefix => 'spring', :cli => '--profile guard', :bundler => false do
            # your watches
          end
          

          如果一个被监视的文件被修改,那么只有@wip 会运行,而且当你在守卫控制台中输入cucumber 时也会运行。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2023-03-28
            • 2015-05-05
            • 1970-01-01
            • 2018-05-14
            • 2014-01-21
            • 1970-01-01
            • 2012-03-03
            相关资源
            最近更新 更多