Class: RspecLogFormatter::Analysis::Analyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_log_formatter/analysis/analyzer.rb

Instance Method Summary collapse

Constructor Details

#initialize(history_provider, options = {}) ⇒ Analyzer

Returns a new instance of Analyzer.



6
7
8
9
10
11
# File 'lib/rspec_log_formatter/analysis/analyzer.rb', line 6

def initialize(history_provider, options={})
  @builds_to_analyze = options[:builds_to_analyze]
  @max_reruns = options[:max_reruns]
  @limit_history = options[:limit_history]
  @history_provider = history_provider
end

Instance Method Details

#analyzeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rspec_log_formatter/analysis/analyzer.rb', line 13

def analyze
  build_numbers = @history_provider.builds
  results = @history_provider.results.reject do |res|
    @builds_to_analyze && !build_numbers.last(@builds_to_analyze).include?(res.build_number.to_i)
  end

  scores = []
  results.group_by(&:description).each do |description, results|
    score = Score.new(description, max_reruns: @max_reruns)

    results.group_by(&:build_number).each do |build_number, results|
      next if results.all?(&:failure?) #not flaky

      results.each{|r| score.absorb(r) }
      score.runs += results.count
      score.failures += results.count(&:failure?)
      score.failure_messages += results.select(&:failure?).map { |r| "#{r.klass}\n      #{r.message}" }
    end
    scores << score if score.runs > 0
  end

  scores.select(&:flaky?).sort.map(&:as_hash)
end