From f54ed85081cbf054e41e0db77b1ac5aa32c5373d Mon Sep 17 00:00:00 2001 From: vveliev Date: Mon, 31 Jul 2017 15:47:05 -0400 Subject: [PATCH 1/2] adding parser to extract files from cucumber profile --- lib/parallel_tests/cli.rb | 7 +++++++ lib/parallel_tests/cucumber/runner.rb | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/lib/parallel_tests/cli.rb b/lib/parallel_tests/cli.rb index 7b7bf72e..8b8043fe 100644 --- a/lib/parallel_tests/cli.rb +++ b/lib/parallel_tests/cli.rb @@ -174,6 +174,7 @@ def parse_options!(argv) opts.on("--only-group INT[, INT]", Array) { |groups| options[:only_group] = groups.map(&:to_i) } opts.on("-e", "--exec [COMMAND]", "execute this code parallel and with ENV['TEST_ENV_NUMBER']") { |path| options[:execute] = path } + opts.on("--cucumber_profile [PROFILE]", "execute cucumber profile") {|profile| options[:cucumber_profile] = profile} opts.on("-o", "--test-options '[OPTIONS]'", "execute test commands with those options") { |arg| options[:test_options] = arg.lstrip } opts.on("-t", "--type [TYPE]", "test(default) / rspec / cucumber / spinach") do |type| begin @@ -211,6 +212,7 @@ def parse_options!(argv) files, remaining = extract_file_paths(argv) unless options[:execute] + files = extract_files_from_cucumber_profile(options[:cucumber_profile]) if (!files.any?)&&options.key?(:cucumber_profile) abort "Pass files or folders to run" unless files.any? options[:files] = files end @@ -228,6 +230,11 @@ def parse_options!(argv) options end + def extract_files_from_cucumber_profile(profile) + return unless @runner.name.eql?('cucumber') + @runner.files_from_profile(profile) + end + def extract_file_paths(argv) dash_index = argv.rindex("--") file_args_at = (dash_index || -1) + 1 diff --git a/lib/parallel_tests/cucumber/runner.rb b/lib/parallel_tests/cucumber/runner.rb index a8466754..0176094d 100644 --- a/lib/parallel_tests/cucumber/runner.rb +++ b/lib/parallel_tests/cucumber/runner.rb @@ -1,4 +1,5 @@ require "parallel_tests/gherkin/runner" +require 'cucumber' module ParallelTests module Cucumber @@ -28,6 +29,12 @@ def summarize_results(results) output.join("\n\n") end + + def files_from_profile(name) + profile = ::Cucumber::Cli::ProfileLoader.new.args_from(name) + profile.delete_if{|x| !x.match(self.test_suffix)} + end + def command_with_seed(cmd, seed) clean = cmd.sub(/\s--order\s+random(:\d+)?\b/, '') "#{clean} --order random:#{seed}" From 38d31d2581190eaa119cf048a89162fdf0665cc1 Mon Sep 17 00:00:00 2001 From: vveliev Date: Tue, 1 Aug 2017 11:31:34 -0400 Subject: [PATCH 2/2] revisiting cucumber profile, better to extract it from test_options --- lib/parallel_tests/cli.rb | 15 ++++++++++----- lib/parallel_tests/cucumber/runner.rb | 3 +-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/parallel_tests/cli.rb b/lib/parallel_tests/cli.rb index 8b8043fe..0abb3342 100644 --- a/lib/parallel_tests/cli.rb +++ b/lib/parallel_tests/cli.rb @@ -174,7 +174,6 @@ def parse_options!(argv) opts.on("--only-group INT[, INT]", Array) { |groups| options[:only_group] = groups.map(&:to_i) } opts.on("-e", "--exec [COMMAND]", "execute this code parallel and with ENV['TEST_ENV_NUMBER']") { |path| options[:execute] = path } - opts.on("--cucumber_profile [PROFILE]", "execute cucumber profile") {|profile| options[:cucumber_profile] = profile} opts.on("-o", "--test-options '[OPTIONS]'", "execute test commands with those options") { |arg| options[:test_options] = arg.lstrip } opts.on("-t", "--type [TYPE]", "test(default) / rspec / cucumber / spinach") do |type| begin @@ -212,7 +211,7 @@ def parse_options!(argv) files, remaining = extract_file_paths(argv) unless options[:execute] - files = extract_files_from_cucumber_profile(options[:cucumber_profile]) if (!files.any?)&&options.key?(:cucumber_profile) + files = extract_files_from_cucumber_profile(options) if files.empty? abort "Pass files or folders to run" unless files.any? options[:files] = files end @@ -230,9 +229,15 @@ def parse_options!(argv) options end - def extract_files_from_cucumber_profile(profile) - return unless @runner.name.eql?('cucumber') - @runner.files_from_profile(profile) + def extract_files_from_cucumber_profile(options) + return unless @runner.name == 'cucumber' + profile = nil + if options.key?(:test_options) + OptionParser.new do |opts| + opts.on("-p", "--profile [PROFILE]") { |option| profile = option } + end.parse!(options[:test_options].split(' ')) + end + @runner.files_from_profile(profile) if profile end def extract_file_paths(argv) diff --git a/lib/parallel_tests/cucumber/runner.rb b/lib/parallel_tests/cucumber/runner.rb index 0176094d..30d857bd 100644 --- a/lib/parallel_tests/cucumber/runner.rb +++ b/lib/parallel_tests/cucumber/runner.rb @@ -31,8 +31,7 @@ def summarize_results(results) def files_from_profile(name) - profile = ::Cucumber::Cli::ProfileLoader.new.args_from(name) - profile.delete_if{|x| !x.match(self.test_suffix)} + ::Cucumber::Cli::ProfileLoader.new.args_from(name).grep(self.test_suffix) end def command_with_seed(cmd, seed)