你怎么得到黄瓜/警卫来过滤像@wip这样的标签?

时间:2012-02-08 12:15:07

标签: cucumber spork guard

我正在运行spork和后卫,我的RSpec测试都运行正常。为了加快测试速度,我可以使用放在.rspec文件中的标签成功过滤我的RSpec测试。

.rspec

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

不幸的是,虽然我无法过滤黄瓜标签。每次黄瓜运行时,它都会运行所有或仅运行更改的文件。

我怎样才能让黄瓜/ spork / guard尊重像@ wip,@ no等标签并只运行那些测试?是否有一些等同于黄瓜标签的.rspec文件?

5 个答案:

答案 0 :(得分:3)

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

wip: --tags @wip

更多信息:

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

您也可以从命令行运行黄瓜并将其传递给-t参数:

cucumber -t @wip,@now

从帮助(黄瓜-h):

  

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

因此,理论上我们可以使用带有以下选项的guardfile:

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

答案 1 :(得分:2)

要理解的一个重要概念是标记个人资料之间存在差异。我也使用Guard with Cucumber,并且对于继续使用默认配置文件并且我的@wip(Work In Progress)标签都没有被选中感到沮丧。现在很明显为什么会这样。正如其他论坛中的一些人所说,我的默认个人资料会过滤掉@wip。

<配置/ cucumber.yml>

<%
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 “&lt; = wip在std_opts过滤掉

我想使用'wip'配置文件,其中包含由'@wip'标记的方案或功能!

wip: - dr&lt;%= wip_opts%&gt; - tags @wip:3 --wip features“&lt; = 数字表示要运行的最大方案数;'--wip'表示Cuc预计测试将失败(因为我们正在研究它)

所以标签已经配置好,我在我的* .feature文件中加入了'@wip'。配置文件怎么样?使用Guard(Spork)时,为了使用'wip'配置文件,需要对其进行配置。这说得通;电脑无法读懂我的想法!更新Guardfile以使用'wip'配置文件。

&LT; Guardfile&GT;

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

护卫'黄瓜',:cli =&gt; “--drb -p wip ”&lt; = ' - p'指定所需的个人资料

现在我的方案已成功通过'wip'过滤。

答案 2 :(得分:2)

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

# Guardfile
guard 'cucumber', :focus_on => 'myfocustag' do
  ...
end

# example.feature
Feature: Example

  @myfocustag
  Scenario: Only run this one
  ...

然后,在将黄瓜命令传递给黄瓜命令之前,黄瓜防护将过滤这些情景。删除这些标记将导致默认行为(运行所有方案,而不是没有)。

答案 3 :(得分:0)

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

原始保护档案

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

修改后的警卫文件

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

答案 4 :(得分:0)

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

<强> cucumber.yml

guard: --format pretty --tags @wip

<强> Guardfile

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

修改了监视文件,然后只有@wip才能运行,但是当你在防护控制台中输入cucumber时也是如此。

相关问题