how do I optionally not run a cucumber feature
I want to not run certain cucumber feature if, say, I'm on windows. Google and the cucumber docs seemed to turn up dry so appealing here.
Thank开发者_StackOverflow中文版s!
Supporting Tyler's answer I would like to propose this additional information:
Use Cucumber Profiles
If you are running the system on multiple different environments you may want to create a profile file and then simply define a default profile for you which excludes the file.
# config/cucumber.yml
##YAML Template
---
windows: --tags ~@not-windows
default: --tags @not-windows
Execution (on a non-windows system / default)
$ cucumber
Execution (on a windows system):
$ cucumber -p windows
You could set the default to whichever environment you are currently on to save yourself having to remember which features do not executing; allowing you to just execute cucumber
.
Use Cucumber Rake Task
Create a rake task that checks your environment and includes the tag you want:
require 'rubygems'
require 'cucumber'
require 'cucumber/rake/task'
WINDOWS_PLATFORM = /mswin|win32|mingw/ unless defined? WINDOWS_PLATFORM
Cucumber::Rake::Task.new(:features) do |t|
tags = (RUBY_PLATFORM =~ WINDOWS_PLATFORM ? "~@not-windows" : "@not-windows")
t.cucumber_opts = "features #{tags}"
end
Execution (on either platform):
$ rake features
This should automatically include the right tag based on your environment.
The best way to approach this would likely be using tags.
For example, if you add a tag like @not-windows
to a feature you can then customize your cucumber execution to ignore this.
@not-windows
Feature: Your feature that causes a problem
your scenarios
If you then run your tests with cucumber --tags ~@not-windows
it will run all cukes that are not tagged by @not-windows. The ~ is what causes the "not" behavior, you could run ONLY these tags by doing cucumber --tags @not-windows
. Using the first cucumber line while in Windows, you can block the problematic features (or individual scenarios) from running but if you're on another OS and run cucumber normally, these will still be ran.
Reference: https://github.com/cucumber/cucumber/wiki/Tags
精彩评论