Skip to content

Commit

Permalink
Rework profile handling for dry-run report generation
Browse files Browse the repository at this point in the history
  • Loading branch information
bayandin committed Dec 11, 2015
1 parent 65e317f commit dac7cf3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
parallel_cucumber (0.1.14)
parallel_cucumber (0.1.15)
parallel (~> 1.6)

GEM
Expand Down
4 changes: 0 additions & 4 deletions lib/parallel_cucumber/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ def parse_options!(argv)
options[:thread_delay] = thread_delay
end
opts.on('-n [PROCESSES]', Integer, 'How many processes to use') { |n| options[:n] = n }

opts.on('--workaround-for-profile-with-reporters "[OPTIONS]"') do |profile_with_reporters|
options[:profile_with_reporters] = profile_with_reporters
end
end

option_parser.parse!(argv)
Expand Down
35 changes: 30 additions & 5 deletions lib/parallel_cucumber/feature_grouper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require 'erb'
require 'json'
require 'yaml'

module ParallelCucumber
class FeatureGrouper
Expand Down Expand Up @@ -43,11 +45,9 @@ def scenario_groups(group_size, options)
end

def generate_dry_run_report(options)
cucumber_options = options[:cucumber_options].gsub(/(--format|-f|--output|-o)\s+[^\s]+/, '')
unless options[:profile_with_reporters].nil?
profile_with_reporters = options[:profile_with_reporters]
cucumber_options = cucumber_options.gsub(/(--profile|-p)\s+#{profile_with_reporters}(\s+|$)/, '')
end
cucumber_options = options[:cucumber_options]
cucumber_options = expand_profiles(cucumber_options) unless cucumber_config_file.nil?
cucumber_options = cucumber_options.gsub(/(--format|-f|--out|-o)\s+[^\s]+/, '')

cmd = "cucumber #{cucumber_options} --dry-run --format json #{options[:cucumber_args].join(' ')}"
dry_run_report = `#{cmd} 2>/dev/null`
Expand All @@ -65,6 +65,31 @@ def generate_dry_run_report(options)
end
end

def cucumber_config_file
Dir.glob('{,.config/,config/}cucumber{.yml,.yaml}').first
end

def expand_profiles(cucumber_options)
config = YAML.load(ERB.new(File.read(cucumber_config_file)).result)
_expand_profiles(cucumber_options, config)
end

def _expand_profiles(options, config)
expand_next = false
options.split.map do |option|
case
when %w(-p --profile).include?(option)
expand_next = true
next
when expand_next
expand_next = false
_expand_profiles(config[option], config)
else
option
end
end.compact.join(' ')
end

def group_creator(groups_count, tasks)
groups = Array.new(groups_count) { [] }

Expand Down
2 changes: 1 addition & 1 deletion lib/parallel_cucumber/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ParallelCucumber
VERSION = '0.1.14'
VERSION = '0.1.15'
end # ParallelCucumber

0 comments on commit dac7cf3

Please sign in to comment.