123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- module RSpec
- module Core
- class World
- SLICES = ENV.fetch('RSPEC_SLICES', 1).to_i
- CURRENT_SLICE = ENV.fetch('RSPEC_CURRENT_SLICE', 1).to_i
- if !method_defined?(:orig_ordered_example_groups)
- alias orig_ordered_example_groups ordered_example_groups
-
-
-
- def ordered_example_groups
- return orig_ordered_example_groups if SLICES == 1
- start_size = 0
- slice_size = total_size / SLICES
- current_slice_start_size = slice_size * (CURRENT_SLICE - 1)
- current_slice_end_size = current_slice_start_size + slice_size
- orig_ordered_example_groups.select do |group|
- (start_size >= current_slice_start_size && start_size < current_slice_end_size).tap do
- start_size += File.size(group.file_path)
- end
- end
- end
-
- def total_size
- example_groups.inject(0) do |sum, group|
- sum + File.size(group.file_path)
- end
- end
- end
- end
- end
- end
|