Class: Mutant::Integration::Rspec::Ordering
- Inherits:
-
Object
- Object
- Mutant::Integration::Rspec::Ordering
- 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
-
#call(examples) ⇒ self
Rank examples, best first.
-
#initialize ⇒ Ordering
constructor
A new instance of Ordering.
-
#order(list) ⇒ Array<Object>
Order the groups or the examples rspec is about to run.
Constructor Details
#initialize ⇒ Ordering
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
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.
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 |