class TravisBuildMatrix::SpecDistributor

Constants

EXTRACT_DURATION_AND_FILE_PATH

Public Class Methods

new(travis_yml_file, profile_results, &block) click to toggle source
# File lib/spec_tiller/distribute_spec_files.rb, line 34
def initialize(travis_yml_file, profile_results, &block)
  num_buckets = travis_yml_file['num_builds'] || DEFAULT_NUM_BUILDS

  @spec_files = parse_profile_results(profile_results)
  @test_buckets = Array.new(num_buckets){ |_| TestBucket.new }
  
  distribute_tests

  TravisBuildMatrix::TravisFile.new(@test_buckets, travis_yml_file, &block)
end

Private Instance Methods

distribute_tests() click to toggle source
# File lib/spec_tiller/distribute_spec_files.rb, line 68
def distribute_tests
  @spec_files.each { |test| smallest_bucket.add_to_list(test) }
end
parse_profile_results(profile_results) click to toggle source
# File lib/spec_tiller/distribute_spec_files.rb, line 47
def parse_profile_results(profile_results)

  #Input: Walnuts
  #        9.96 seconds average (69.69 seconds / 7 examples) ./spec/features/walnut_spec.rb:3
  #Output: ["9.96", "spec/features/walnut_spec.rb"]
  extracted_info = profile_results.scan(EXTRACT_DURATION_AND_FILE_PATH).uniq { |spec_file| spec_file.last }
  
  tests = extracted_info.map do |capture_groups|
    test_duration = capture_groups.first.strip.to_f
    test_file_path = capture_groups.last
    
    SpecFile.new(test_file_path, test_duration)
  end

  tests.sort_by(&:test_duration).reverse
end
smallest_bucket() click to toggle source
# File lib/spec_tiller/distribute_spec_files.rb, line 64
def smallest_bucket
  @test_buckets.min_by(&:total_duration)
end