Skip to content

Commit

Permalink
refactor: minitest sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed May 8, 2024
1 parent 545464e commit 6575956
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/test_prof/recipes/minitest/sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,18 @@ def sample_examples(sample_size)
all_examples = suites.flat_map do |runnable|
runnable.runnable_methods.map { |method| [runnable, method] }
end
sample = all_examples.sample(sample_size)

sample = all_examples.sample(sample_size).group_by(&:first)
sample.transform_values! { |v| v.map(&:last) }

# Filter examples by overriding #runnable_methods for all suites
suites.each do |runnable|
runnable.define_singleton_method(:runnable_methods) do
super() & sample.select { |ex| ex.first.equal?(runnable) }.map(&:last)
if sample.key?(runnable)
runnable.define_singleton_method(:runnable_methods) do
super() & sample[runnable]
end
else
runnable.define_singleton_method(:runnable_methods) { [] }
end
end
end
Expand Down

0 comments on commit 6575956

Please sign in to comment.