How do you get a cucumber / guard to filter on tags like @wip?

I run spork and guard and everything went very well with my RSpec checks, which all worked correctly. To speed up the tests, I was able to successfully filter out my RSpec tests with tags that I placed in my .rspec file.

.rspec

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

Unfortunately, although I could not filter out the cucumber tags. Every time a cucumber starts, it starts either everything or just the file that has changed.

How can I get a cucumber / spork / guard to respect tags like @wip, @now, etc. and run only those tests? Is there an equivalent .rspec file for cucumber tags?

+6
source share
5 answers

You can use the cucumber profile to identify the tags that you want to execute. Using a YML file, you can define the profile that runs your @wip tags:

 wip: --tags @wip 

Additional Information:

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

You can also just start the cucumber from the command line and pass the -t argument to it:

 cucumber -t @wip,@now 

From the reference (cucumber -h):

Only execute functions or scripts that use TAG_EXPRESSION tags. Scripts inherit tags declared at the function level. The simplest TAG_EXPRESSION is just a tag. Example: --tags @dev. When a tag in an expression tag begins with a ~, this is a logical NOT. Example: --tags ~ @dev. A tag expression can have multiple tags, separated by a comma, which represents a logical OR. Example: --tags @dev, @wip. You can specify the -tags option several times, and this is a logical AND. Example: --tags @foo, ~ @bar --tags @zap. This is a logical expression (@foo ||! @Bar) && & @zap

Therefore, in theory, we can use a protective file with these parameters:

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

An important concept to understand is the difference between tags and profiles . I also use Guard with Cucumber and was disappointed that the default profile continued to be used and none of my @Wip (Work In Progress) tags were selected. Now it’s obvious why this was so. As pointed out by some other forums, my profile filters @wip by default.

<configurations /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 will include scripts or features marked with "@wip"!

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

So the tags are already set up, and I included "@wip" in my * .feature file. What about profiles? When using Guard (Spork), for the wip profile to be used, it must be configured. It makes sense; the computer cannot read my mind! Update the Guard file 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 indicate the desired profile

And now my scripts are successfully filtered using "wip".

+2
source

I'm not sure when this parameter was entered, but the cucumber protection has the ability to focus on a specific tag (which differs from hard coding with a specific tag that will always be filtered). You can leave this configuration in your Guardfile and use only your focus tag if you need it:

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

The cucumber guard will then filter out these scenarios before passing them on to the cucumber team. Removing these tags will result in a default behavior (all scripts are executed, not a single one).

+2
source

Although theoretically it should be possible to do this work using the cucumber profiles that I found, I had to use a guardfile .

Original security file

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

modified protection file

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

Now, if you want Guard to always run @wip like me, then in your add:

cucumber.yml

 guard: --format pretty --tags @wip 

Guardfile

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

that the viewed file will be changed, then only @wip will be launched, and also when cucumber entered into the security console.

0
source

Source: https://habr.com/ru/post/907937/


All Articles