Module: TestProf::MinitestSample

Defined in:
lib/test_prof/recipes/minitest/sample.rb

Overview

Add ability to run only a specified number of example groups (randomly selected)

Constant Summary collapse

CORE_RUNNABLES =

Do not add these classes to resulted sample

[
  Minitest::Test,
  Minitest::Unit::TestCase,
  Minitest::Spec
].freeze

Instance Method Summary collapse

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/test_prof/recipes/minitest/sample.rb', line 13

def run(*)
  unless ENV['SAMPLE'].nil?
    sample_size = ENV['SAMPLE'].to_i
    # Make sure that sample contains only _real_ suites
    runnables = Minitest::Runnable.runnables
                                  .sample(sample_size + CORE_RUNNABLES.size)
                                  .reject { |suite| CORE_RUNNABLES.include?(suite) }
                                  .take(sample_size)
    Minitest::Runnable.reset
    runnables.each { |r| Minitest::Runnable.runnables << r }
  end
  super
end