Skip to content

Instantly share code, notes, and snippets.

@esaborit4code
Last active September 26, 2016 08:34
Show Gist options
  • Save esaborit4code/1db6eaa06a06225ca0c011f4ee649a90 to your computer and use it in GitHub Desktop.
Save esaborit4code/1db6eaa06a06225ca0c011f4ee649a90 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'json'
exec 'rspec --format json --out rspec_results.json' unless File.exists? 'rspec_results.json'
results = JSON.parse(File.read 'rspec_results.json')
total_runtime = results['summary']['duration']
total_examples = results['examples']
grouped = total_examples.group_by do |example|
example['file_path'].split('/')[0...-1].join '/'
end
files = grouped.map do |file_path, file_examples|
[file_path, file_examples.inject(0) { |file_run_time, example| file_run_time += example['run_time']}]
end
files.sort_by!(&:last).reverse!
first_pipeline = []
first_pipeline_run_time = 0
ideal_pipeline_run_time = total_runtime / 2.0
files.each do |file_path, file_run_time|
first_pipeline << file_path
first_pipeline_run_time += file_run_time
break if first_pipeline_run_time > ideal_pipeline_run_time
end
p "Total runtime: #{total_runtime}"
p "Ideal runtime per pipeline: #{ideal_pipeline_run_time}"
p "FIRST PIPELINE (Runtime: #{first_pipeline_run_time}):"
p "bundle exec rspec #{first_pipeline.join ' '}"
p "SECOND PIPELINE (Runtime: #{total_runtime - first_pipeline_run_time}):"
p 'bundle exec rspec --exclude-pattern ' + first_pipeline.join('|')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment