Class: RspecLogFormatter::Analysis::Analyzer
- Inherits:
-
Object
- Object
- RspecLogFormatter::Analysis::Analyzer
- Defined in:
- lib/rspec_log_formatter/analysis/analyzer.rb
Instance Method Summary collapse
Instance Method Details
#analyze(filepath, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rspec_log_formatter/analysis/analyzer.rb', line 6 def analyze(filepath, = {}) window = [:last_builds] build_numbers, results = result_numbers(filepath, = {}) scores = [] results.group_by(&:description).each do |description, results| score = Score.new(description) results.group_by(&:build_number).each do |build_number, results| next if (window && !build_numbers.last(window).include?(build_number)) next if results.all?(&:failure?) #not flaky score.runs += results.count score.failures += results.count(&:failure?) score. += results.select(&:failure?).map { |r| "#{r.klass}\n #{r.message}" } end scores << score if score.runs > 0 end scores.sort.map(&:as_hash) end |
#truncate(filepath, opts = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rspec_log_formatter/analysis/analyzer.rb', line 30 def truncate(filepath, opts = {}) builds = opts.fetch(:keep_builds) build_numbers, results = result_numbers(filepath, = {}) sio = StringIO.new File.open(filepath, 'r').each_line do |line| result = parse_line(line) next unless build_numbers.last(builds).include? result.build_number sio.puts line end sio.rewind File.open(filepath, 'w') do |f| f.write sio.read end end |