Class: Mutant::Integration::Rspec::Ordering

Inherits:
Object
  • Object
show all
Defined in:
lib/mutant/integration/rspec.rb

Overview

Rspec ordering strategy driven by the order mutant selected the tests in

Rspec runs one group at a time, so a group is ranked by the best test it holds, and the ranking survives as group order plus example order within a group. Anything rspec asks about that was not selected sorts last.

Constant Summary collapse

UNRANKED =
Float::INFINITY

Instance Method Summary collapse

Constructor Details

#initializeOrdering

Returns a new instance of Ordering.



42
# File 'lib/mutant/integration/rspec.rb', line 42

def initialize = @rank = {}

Instance Method Details

#call(examples) ⇒ self

Rank examples, best first

Parameters:

  • examples (Enumerable<RSpec::Core::Example>)

Returns:

  • (self)


49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/mutant/integration/rspec.rb', line 49

def call(examples)
  @rank.clear

  examples.each_with_index do |example, rank|
    @rank[example] = rank

    example.example_group.parent_groups.each do |group|
      @rank[group] = rank if @rank.fetch(group, UNRANKED) > rank
    end
  end

  self
end

#order(list) ⇒ Array<Object>

Order the groups or the examples rspec is about to run

Rspec's own id breaks a tie, so the order does not depend on the order rspec happened to hand the list over in.

Parameters:

  • list (Array<Object>)

Returns:

  • (Array<Object>)


71
72
73
# File 'lib/mutant/integration/rspec.rb', line 71

def order(list)
  list.sort_by { |item| [@rank.fetch(item, UNRANKED), item.id] }
end