Module: Mutineer::MinitestIntegration::FileOrder

Defined in:
lib/mutineer/minitest_integration/file_order.rb

Overview

Extends the list of test classes. shuffle orders files by FileOrder.rank and shuffles each file on its own.

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.rank ⇒ Hash{Class => Integer}?

Each test class's file position.

Returns:

  • (Hash{Class => Integer}, nil)


28
29
30
# File 'lib/mutineer/minitest_integration/file_order.rb', line 28

def rank
  @rank
end

Instance Method Details

#reject ⇒ Array<Class>

Minitest 5.15 and older drop empty classes before the shuffle, so the filtered list keeps the file order too.

Returns:

  • (Array<Class>)


51
52
53
# File 'lib/mutineer/minitest_integration/file_order.rb', line 51

def reject(...)
  super.extend(FileOrder)
end

#shuffle ⇒ Array<Class>

Files in rank order. Classes that share a file are shuffled with Random.new(Minitest.seed), so their order does not depend on the other files in the run. A nil seed keeps load order.

Returns:

  • (Array<Class>)


36
37
38
39
40
41
42
43
44
45
# File 'lib/mutineer/minitest_integration/file_order.rb', line 36

def shuffle(*)
  rank = FileOrder.rank || {}
  seed = ::Minitest.seed
  grouped = group_by { |klass| rank.fetch(klass, rank.size) }
  grouped.sort.flat_map do |_index, classes|
    next classes if classes.size < 2 || seed.nil?

    classes.shuffle(random: Random.new(seed.to_i))
  end
end