Class: Crystalball::Predictor::AssociatedSpecs

Inherits:
Object
  • Object
show all
Includes:
Strategy
Defined in:
lib/crystalball/predictor/associated_specs.rb

Overview

Used with ‘predictor.use Crystalball::Predictor::AssociatedSpecs.new(from: %rmodels/(models/(.*)models/(.*).rb, to: “./spec/models/%s_spec.rb”)`. When used will look for files matched to `from` regex and use captures to fill `to` string to get paths of proper specs

Instance Method Summary collapse

Methods included from Helpers::PathFormatter

#format_path, #format_paths

Constructor Details

#initialize(from:, to:) ⇒ AssociatedSpecs

Returns a new instance of AssociatedSpecs.

Parameters:

  • from (Regexp)
    • regular expression to match specific files and get proper captures

  • to (String)
    • string in sprintf format to get proper files using captures of regexp



15
16
17
18
# File 'lib/crystalball/predictor/associated_specs.rb', line 15

def initialize(from:, to:)
  @from = from
  @to = to
end

Instance Method Details

#call(diff, _map) ⇒ Array<String>

This strategy does not depend on a previously generated example group map. It uses the defined regex rules to infer which specs to run.

Parameters:

Returns:

  • (Array<String>)

    the spec paths associated with the changes



25
26
27
28
29
# File 'lib/crystalball/predictor/associated_specs.rb', line 25

def call(diff, _map)
  super do
    diff.map(&:relative_path).grep(from).map { |source_file_path| to % captures(source_file_path) }
  end
end