Class: RSpec::Covers::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/covers/formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ Formatter

Returns a new instance of Formatter.



10
11
12
# File 'lib/rspec/covers/formatter.rb', line 10

def initialize(output)
  @output = output
end

Instance Method Details

#dump_summary(_notification) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rspec/covers/formatter.rb', line 14

def dump_summary(_notification)
  reporter = RSpec::Covers.reporter
  return if reporter.results.empty?

  @output.puts "\nrspec-covers:"
  @output.puts "  risky examples: #{reporter.risky_results.length}"
  @output.puts "  declaration warnings: #{reporter.validation_warnings.length}"
  @output.puts "  suggestions: #{reporter.suggestions.length}"

  reporter.risky_results.each do |result|
    @output.puts "  risky: #{result.file}:#{result.line} #{result.description}"
    result.verdict.grouped_evidence(limit: 5).each do |evidence|
      @output.puts "    #{evidence[:file]}:#{evidence[:lines].join(",")}"
      @output.puts "      methods: #{evidence[:methods].join(", ")}" if evidence[:methods].any?
      @output.puts "      note: #{evidence[:note]}" if evidence[:note]
    end
  end

  reporter.validation_warnings.each do |result|
    validation = result.declaration_validation
    @output.puts "  declaration warning: #{result.file}:#{result.line} #{result.description}"
    @output.puts "    weak: #{validation.unsupported_labels.join(", ")}"
  end

  reporter.results.each do |result|
    next if Array(result.unchecked_locations).empty?

    @output.puts colorize("  unchecked: #{result.file}:#{result.line} #{result.description}", 33)
    result.unchecked_locations.group_by(&:file).each do |file, locations|
      @output.puts colorize("    #{file}:#{locations.map(&:line).sort.join(",")}", 33)
    end
  end
end

#example_finished(notification) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/rspec/covers/formatter.rb', line 48

def example_finished(notification)
  return unless RSpec::Covers.configuration.json_events

  result = RSpec::Covers.reporter.results.find { |item| item.id == notification.example.id }
  return unless result

  @output.puts JSON.generate(type: "rspec_covers.example", example: result.to_h)
end