Class: RSpecTracer::ReportWriter

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

Instance Method Summary collapse

Constructor Details

#initialize(report_dir, reporter) ⇒ ReportWriter

Returns a new instance of ReportWriter.



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

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

Instance Method Details



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rspec_tracer/report_writer.rb', line 37

def print_duplicate_examples
  return if @reporter.duplicate_examples.empty?

  total = @reporter.duplicate_examples.sum { |_, examples| examples.count }

  puts '=' * 80
  puts '   IMPORTANT NOTICE -- RSPEC TRACER COULD NOT IDENTIFY SOME EXAMPLES UNIQUELY'
  puts '=' * 80
  puts "RSpec tracer could not uniquely identify the following #{total} examples:"

  justify = ' ' * 2
  nested_justify = justify * 3

  @reporter.duplicate_examples.each_pair do |example_id, examples|
    puts "#{justify}- Example ID: #{example_id} (#{examples.count} examples)"

    examples.each do |example|
      description = example[:full_description].strip
      file_name = example[:rerun_file_name].sub(%r{^/}, '')
      line_number = example[:rerun_line_number]
      location = "#{file_name}:#{line_number}"

      puts "#{nested_justify}* #{description} (#{location})"
    end
  end

  puts
end

#write_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
# File 'lib/rspec_tracer/report_writer.rb', line 10

def write_report
  starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)

  @run_id = Digest::MD5.hexdigest(@reporter.all_examples.keys.sort.to_json)
  @cache_dir = File.join(@report_dir, @run_id)

  FileUtils.mkdir_p(@cache_dir)

  write_all_examples_report
  write_duplicate_examples_report
  write_interrupted_examples_report
  write_flaky_examples_report
  write_failed_examples_report
  write_pending_examples_report
  write_skipped_examples_report
  write_all_files_report
  write_dependency_report
  write_reverse_dependency_report
  write_examples_coverage_report
  write_last_run_report

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

  puts "RSpec tracer reports written to #{@cache_dir} (took #{elapsed})"
end