Class: ParallelCalabash::FeatureGrouper
- Inherits:
-
Object
- Object
- ParallelCalabash::FeatureGrouper
- Defined in:
- lib/parallel_calabash/feature_grouper.rb
Class Method Summary collapse
- .concurrent_feature_groups(feature_folder, number_of_groups) ⇒ Object
- .feature_files_in_folder(feature_dir_or_file) ⇒ Object
- .feature_folder_has_single_feature?(feature_dir) ⇒ Boolean
- .feature_groups(options, group_size) ⇒ Object
- .feature_groups_by_feature_files(feature_folder, group_size) ⇒ Object
- .feature_groups_by_scenarios(features_scenarios, group_size) ⇒ Object
- .feature_groups_by_weight(feature_folder, group_size, weighing_factor) ⇒ Object
- .features_with_weights(feature_dir, weighing_factor) ⇒ Object
- .generate_dry_run_report(options) ⇒ Object
- .group_creator(group_size, files) ⇒ Object
- .index_of_lightest_group(feature_groups) ⇒ Object
- .scenario_groups(group_size, options) ⇒ Object
- .weight_of_feature(feature_file, weighing_factor) ⇒ Object
- .weight_of_group(group) ⇒ Object
Class Method Details
.concurrent_feature_groups(feature_folder, number_of_groups) ⇒ Object
30 31 32 33 34 |
# File 'lib/parallel_calabash/feature_grouper.rb', line 30 def concurrent_feature_groups(feature_folder, number_of_groups) groups = [] (0...number_of_groups).each{ groups << feature_files_in_folder(feature_folder) } groups end |
.feature_files_in_folder(feature_dir_or_file) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/parallel_calabash/feature_grouper.rb', line 86 def feature_files_in_folder(feature_dir_or_file) if File.directory?(feature_dir_or_file.first) files = Dir[File.join(feature_dir_or_file, "**{,/*/**}/*")].uniq files.grep(/\.feature$/) elsif feature_folder_has_single_feature?(feature_dir_or_file) feature_dir_or_file elsif File.file?(feature_dir_or_file.first) scenarios = File.open(feature_dir_or_file.first).collect{ |line| line.split(' ') } scenarios.flatten end end |
.feature_folder_has_single_feature?(feature_dir) ⇒ Boolean
98 99 100 |
# File 'lib/parallel_calabash/feature_grouper.rb', line 98 def feature_folder_has_single_feature?(feature_dir) feature_dir.first.include?('.feature') end |
.feature_groups(options, group_size) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/parallel_calabash/feature_grouper.rb', line 7 def feature_groups(, group_size) return concurrent_feature_groups([:feature_folder], group_size) if [:concurrent] return scenario_groups group_size, if [:group_by_scenarios] return feature_groups_by_weight([:feature_folder], group_size,[:distribution_tag]) if [:distribution_tag] feature_groups_by_feature_files([:feature_folder], group_size) end |
.feature_groups_by_feature_files(feature_folder, group_size) ⇒ Object
36 37 38 39 40 |
# File 'lib/parallel_calabash/feature_grouper.rb', line 36 def feature_groups_by_feature_files(feature_folder, group_size) files = feature_files_in_folder feature_folder groups = group_creator group_size,files groups.reject(&:empty?) end |
.feature_groups_by_scenarios(features_scenarios, group_size) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/parallel_calabash/feature_grouper.rb', line 14 def feature_groups_by_scenarios(features_scenarios,group_size) puts "Scenarios: #{features_scenarios.size}" min_number_scenarios_per_group = features_scenarios.size/group_size remaining_number_of_scenarios = features_scenarios.size % group_size groups = Array.new(group_size) { [] } groups.each do |group| min_number_scenarios_per_group.times { group << features_scenarios.delete_at(0) } end unless remaining_number_of_scenarios==0 groups[0..(remaining_number_of_scenarios-1)].each do |group| group << features_scenarios.delete_at(0) end end groups.reject(&:empty?) end |
.feature_groups_by_weight(feature_folder, group_size, weighing_factor) ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/parallel_calabash/feature_grouper.rb', line 116 def feature_groups_by_weight(feature_folder, group_size, weighing_factor) features = features_with_weights feature_folder, weighing_factor feature_groups = Array.new(group_size).map{|e| e = []} features.each do |feature| feature_groups[index_of_lightest_group(feature_groups)] << feature end feature_groups.reject!{|group| group.empty?} feature_groups.map{|group| group.map{|feature_hash| feature_hash[:feature]}} end |
.features_with_weights(feature_dir, weighing_factor) ⇒ Object
107 108 109 110 111 112 113 114 |
# File 'lib/parallel_calabash/feature_grouper.rb', line 107 def features_with_weights(feature_dir, weighing_factor) files = feature_files_in_folder feature_dir features_and_weight = [] files.each do |file| features_and_weight << {:feature => file, :weight => weight_of_feature(file, weighing_factor)} end features_and_weight end |
.generate_dry_run_report(options) ⇒ Object
82 83 84 |
# File 'lib/parallel_calabash/feature_grouper.rb', line 82 def generate_dry_run_report %x( cucumber #{[:cucumber_options]} --dry-run -f json --out parallel_calabash_dry_run.json #{[:feature_folder].join(' ')} ) end |
.group_creator(group_size, files) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/parallel_calabash/feature_grouper.rb', line 42 def group_creator group_size, files min_number_files_per_group = files.size/group_size remaining_number_of_files = files.size % group_size groups = Array.new(group_size) { [] } groups.each do |group| min_number_files_per_group.times { group << files.delete_at(0) } end unless remaining_number_of_files==0 groups[0..(remaining_number_of_files-1)].each do |group| group << files.delete_at(0) end end groups.reject &:empty? end |
.index_of_lightest_group(feature_groups) ⇒ Object
126 127 128 129 |
# File 'lib/parallel_calabash/feature_grouper.rb', line 126 def index_of_lightest_group feature_groups lightest = feature_groups.min { |x, y| weight_of_group(x) <=> weight_of_group(y) } index = feature_groups.index(lightest) end |
.scenario_groups(group_size, options) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/parallel_calabash/feature_grouper.rb', line 57 def scenario_groups group_size, generate_dry_run_report raise "Can not create dry run for scenario distribution" unless File.exists?("parallel_calabash_dry_run.json") distribution_data = JSON.parse(File.read("parallel_calabash_dry_run.json")) # puts "SCENARIO GROUPS #{distribution_data}" all_runnable_scenarios = distribution_data.map do |feature| unless feature["elements"].nil? feature["elements"].map do |scenario| if scenario["keyword"] == 'Scenario' "#{feature["uri"]}:#{scenario["line"]}" elsif scenario['keyword'] == 'Scenario Outline' if scenario["examples"] scenario["examples"].map { |example| "#{feature["uri"]}:#{example["line"]}" } else "#{feature["uri"]}:#{scenario["line"]}" # Cope with --expand end end end end end.flatten.compact groups = group_creator group_size,all_runnable_scenarios end |
.weight_of_feature(feature_file, weighing_factor) ⇒ Object
102 103 104 105 |
# File 'lib/parallel_calabash/feature_grouper.rb', line 102 def weight_of_feature(feature_file, weighing_factor) content = File.read(feature_file) content.scan(/#{weighing_factor}\b/).size end |
.weight_of_group(group) ⇒ Object
131 132 133 |
# File 'lib/parallel_calabash/feature_grouper.rb', line 131 def weight_of_group group group.inject(0) { |sum, b| sum + b[:weight] } end |