Cukes: Allow running features specified by file/folder/scenario name

pull/75/head
Michael Frister 12 years ago
parent 55fbe5ab62
commit 0db5704de5
  1. 41
      doc/RUNNING_TESTS.rdoc
  2. 42
      lib/tasks/cucumber.rake

@ -1,3 +1,40 @@
= Testing ChiliProject
= Testing OpenProject
The detailed upgrade instructions are located on the {official website}[https://www.chiliproject.org/projects/chiliproject/wiki/Testing]
== Cucumber
The cucucmber features can be run using rake. You can run the following
rake tasks using the command `bundle exec rake <task>`.
* `cucumber`: Runs core features
* `cucumber:plugins`: Runs plugin features
* `cucumber:all`: Runs core and plugin features
* `cucumber:custom[features]`: Allows running single features or folders
of features
Example: `cucumber:custom[features/issues/issue.feature]`
* When providing moultiple features, the task name and arguments must
be enclosed in quotation marks.
Example: `bundle exec rake "cucumber:custom[features/issues features/projects]"`
`cucumber:plugins` and `cucumber:all` accept an optional parameter which
allows specifying custom options to cucumber. This can be used for
executing scenarios by name, e.g. `"cucumber:all[-n 'Adding an issue link']"`.
Like with spaces in `cucumber:custom` arguments, task name and arguments
have to be enclosed in quotation marks.
Here are two bash functions which allow using shorter commands for running
cucumber features:
# Run OpenProject cucumber features (like arguments to the cucumber command)
# Example: cuke features/issues/issue.feature
cuke() { bundle exec rake "cucumber:custom[$1]"; }
# Run OpenProject cucumber scenarios by name
# Example: cuken 'Adding an issue link'
cuken() { bundle exec rake "cucumber:all[-n '$1']"; }
== Spec
TBD

@ -23,40 +23,50 @@ begin
::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features')
end
def get_plugin_features
def get_plugin_features(prefix = '')
features = []
Rails.application.config.plugins_to_test_paths.each do |dir|
if File.directory?( dir )
feature_dir = Shellwords.escape(File.join(dir, 'features'))
# tell cucumber to load support files from feature_dir
features << '-r ' + feature_dir
# add feature_dir as features
features << feature_dir
features << prefix + feature_dir
end
end
features
end
[:plugins, :all].each do |selection|
desc "Run #{selection.to_s} features"
task selection => 'db:test:prepare' do
def define_cucumber_task(name, description, arguments=[])
desc description
task name, arguments => 'db:test:prepare' do |t, args|
if name == :custom
if not args[:features]
raise 'Please provide :features argument, e.g. rake cucumber:custom[features/my_feature.feature]'
end
features = args[:features].split(/\s+/)
else
features = get_plugin_features
if name == :all
features += [File.join(Rails.root, 'features')]
end
end
Cucumber::Rake::Task.new({:cucumber_run => 'db:test:prepare'}, 'Run features that should pass') do |t|
opts = (ENV['CUCUMBER_OPTS'] ? ENV['CUCUMBER_OPTS'].split(/\s+/) : [])
ENV.delete('CUCUMBER_OPTS')
opts += args[:options].split(/\s+/) if args[:options]
# always load feature support files from Rails root
base_features = ['-r ' + Shellwords.escape(File.join(Rails.root, 'features'))]
# load feature support files from Rails root
support_files = ['-r ' + Shellwords.escape(File.join(Rails.root, 'features'))]
support_files += get_plugin_features(prefix=' -r ')
if selection == :all
base_features += [File.join(Rails.root, 'features')]
end
plugin_features = get_plugin_features
t.cucumber_opts = opts + base_features + plugin_features
t.cucumber_opts = opts + support_files + features
end
Rake::Task['cucumber_run'].invoke
end
end
define_cucumber_task(:plugins, 'Run plugin features', [:options])
define_cucumber_task(:all, 'Run core and plugin features', [:options])
define_cucumber_task(:custom, 'Run features selected via features argument', [:features])
end
desc 'Alias for cucumber:ok'

Loading…
Cancel
Save