Class: RSpecTracer::ReportGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_tracer/report_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(reporter, cache) ⇒ ReportGenerator

Returns a new instance of ReportGenerator.



5
6
7
8
# File 'lib/rspec_tracer/report_generator.rb', line 5

def initialize(reporter, cache)
  @reporter = reporter
  @cache = cache
end

Instance Method Details

#generate_reportObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rspec_tracer/report_generator.rb', line 39

def generate_report
  generate_last_run_report
  generate_examples_status_report

  %i[all_files all_examples dependency examples_coverage reverse_dependency].each do |report_type|
    starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)

    send("generate_#{report_type}_report")

    ending = Process.clock_gettime(Process::CLOCK_MONOTONIC)
    elapsed = RSpecTracer::TimeFormatter.format_time(ending - starting)

    puts "RSpec tracer generated #{report_type.to_s.tr('_', ' ')} report (took #{elapsed})" if RSpecTracer.verbose?
  end
end

#reverse_dependency_reportObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rspec_tracer/report_generator.rb', line 10

def reverse_dependency_report
  reverse_dependency = Hash.new do |examples, file_name|
    examples[file_name] = {
      example_count: 0,
      examples: Hash.new(0)
    }
  end

  @reporter.dependency.each_pair do |example_id, files|
    next if @reporter.interrupted_examples.include?(example_id)

    example_file = @reporter.all_examples[example_id][:rerun_file_name]

    files.each do |file_name|
      reverse_dependency[file_name][:example_count] += 1
      reverse_dependency[file_name][:examples][example_file] += 1
    end
  end

  reverse_dependency.transform_values! do |data|
    {
      example_count: data[:example_count],
      examples: data[:examples].sort_by { |file_name, count| [-count, file_name] }.to_h
    }
  end

  reverse_dependency.sort_by { |file_name, data| [-data[:example_count], file_name] }.to_h
end