6

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

.rspec

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

不幸的是,虽然我无法过滤我的黄瓜标签。每次 cucumber 运行时,它要么运行所有内容,要么只运行已更改的文件。

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

4

5 回答 5

3

您可以使用黄瓜配置文件来定义要执行的标签。使用 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。当标记表达式中的标记以 ~ 开头时,这表示布尔非。示例:--tags ~@dev。一个标签表达式可以有多个标签,用逗号分隔,表示逻辑或。示例:--tags @dev,@wip。--tags 选项可以指定多次,这表示逻辑与。示例:--tags @foo,~@bar --tags @zap。这表示布尔表达式 (@foo || !

因此,理论上我们可以使用带有这些选项的保护文件:

guard 'cucumber', :cli => "--drb --tags @now" do
  watch(%r{^features/.+\.feature$})
  ...
end
于 2012-02-10T09:59:39.770 回答
2

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

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

# example.feature
Feature: Example

  @myfocustag
  Scenario: Only run this one
  ...

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

于 2013-06-04T18:41:37.033 回答
2

An important concept to understand is there is a difference between tags and profiles. I am also using Guard with Cucumber and was frustrated that the default profile continued to be used and none of my @wip (Work In Progress) tags were being picked up. It's obvious now why that was the case. As stated by some in other forums, my default profile filters out @wip.

<config/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" <= wip is filtered out here in std_opts

I want to use the 'wip' profile, which would include scenarios or features marked by '@wip'!

wip: --drb <%= wip_opts %> --tags @wip:3 --wip features" <= the number represents the max number of scenarios to run; '--wip' indicates that Cuc expects the test will fail (because we're working on it)

So the tags are already configured and I've included '@wip' in my *.feature file. What about the profiles? When using Guard (Spork), in order for the 'wip' profile to be used, it needs to be configured. It makes sense; the computer can't read my mind! Update the Guardfile to use the 'wip' profile.

<Guardfile>

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' to specify desired profile

And now my scenarios are successfully being filtered by 'wip'.

于 2012-06-08T20:20:49.993 回答
0

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

原始保护文件

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

修改后的保护文件

guard 'cucumber', :cli => "--drb --tags @now" do
  watch(%r{^features/.+\.feature$})
  ...
end
于 2012-02-10T11:19:16.717 回答
0

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

黄瓜.yml

guard: --format pretty --tags @wip

保护文件

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

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

于 2015-06-25T21:04:08.517 回答