Class: Undercover::Formatter

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

Constant Summary collapse

WARNINGS_TO_S =
{
  stale_coverage: Rainbow('🚨 WARNING: Coverage data is older than your ' \
                          'latest changes and results might be incomplete. ' \
                          'Re-run tests to update').yellow,
  no_changes: Rainbow('✅ No reportable changes').green
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(results, validation_error = nil) ⇒ Formatter

Returns a new instance of Formatter.



12
13
14
15
# File 'lib/undercover/formatter.rb', line 12

def initialize(results, validation_error = nil)
  @results = results
  @validation_error = validation_error
end

Instance Method Details

#exit_codeObject



25
26
27
28
29
30
# File 'lib/undercover/formatter.rb', line 25

def exit_code
  return 0 if @validation_error
  return 0 unless @results.any?

  1
end

#to_sObject



17
18
19
20
21
22
23
# File 'lib/undercover/formatter.rb', line 17

def to_s
  return WARNINGS_TO_S[@validation_error] if @validation_error

  return success unless @results.any?

  ([warnings_header] + formatted_warnings).join("\n")
end