Class: Crystalball::Predictor

Inherits:
Object
  • Object
show all
Defined in:
lib/crystalball/predictor.rb,
lib/crystalball/predictor/strategy.rb,
lib/crystalball/predictor/modified_specs.rb,
lib/crystalball/predictor/associated_specs.rb,
lib/crystalball/predictor/helpers/path_formatter.rb,
lib/crystalball/predictor/modified_support_specs.rb,
lib/crystalball/predictor/modified_execution_paths.rb,
lib/crystalball/predictor/helpers/affected_example_groups_detector.rb

Overview

Class to predict test failures with given execution map and sources diff

Defined Under Namespace

Modules: Helpers, Strategy Classes: AssociatedSpecs, ModifiedExecutionPaths, ModifiedSpecs, ModifiedSupportSpecs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(map, repo, from: 'HEAD', to: nil) {|_self| ... } ⇒ Predictor

Returns a new instance of Predictor.

Parameters:

  • map (Crystalball::ExecutionMap)

    execution map

  • repo (Crystalball::GitRepo)

    to build execution list on

  • from (String) (defaults to: 'HEAD')

    starting commit for diff. Default: HEAD

  • to (String) (defaults to: nil)

    ending commit for diff. Default: nil

Yields:

  • (_self)

Yield Parameters:



12
13
14
15
16
17
18
19
# File 'lib/crystalball/predictor.rb', line 12

def initialize(map, repo, from: 'HEAD', to: nil)
  @map = map
  @repo = repo
  @from = from
  @to = to
  @prediction_strategies = []
  yield self if block_given?
end

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



6
7
8
# File 'lib/crystalball/predictor.rb', line 6

def from
  @from
end

#mapObject (readonly)

Returns the value of attribute map.



6
7
8
# File 'lib/crystalball/predictor.rb', line 6

def map
  @map
end

#prediction_strategiesObject (readonly)

Returns the value of attribute prediction_strategies.



6
7
8
# File 'lib/crystalball/predictor.rb', line 6

def prediction_strategies
  @prediction_strategies
end

#toObject (readonly)

Returns the value of attribute to.



6
7
8
# File 'lib/crystalball/predictor.rb', line 6

def to
  @to
end

Instance Method Details

#diffObject



33
34
35
36
37
38
# File 'lib/crystalball/predictor.rb', line 33

def diff
  @diff ||= begin
              ancestor = repo.merge_base(from, to || 'HEAD').sha
              repo.diff(ancestor, to)
            end
end

#predictionCrystalball::Prediction

Returns list of examples which may fail.

Returns:



29
30
31
# File 'lib/crystalball/predictor.rb', line 29

def prediction
  Prediction.new(filter(raw_prediction(diff)))
end

#use(strategy) ⇒ Object

Adds additional predictor to use

Parameters:

  • strategy (#call)
    • the strategy can be any object that responds to #call



24
25
26
# File 'lib/crystalball/predictor.rb', line 24

def use(strategy)
  prediction_strategies << strategy
end