Class: Uncov::Formatter::Terminal
- Inherits:
-
Object
- Object
- Uncov::Formatter::Terminal
- Includes:
- Cache
- Defined in:
- lib/plugins/uncov/formatter/terminal.rb
Overview
print report to terminal with colors
Instance Attribute Summary collapse
-
#report ⇒ Object
readonly
Returns the value of attribute report.
Instance Method Summary collapse
- #format_line(line, max) ⇒ Object
-
#initialize(report) ⇒ Terminal
constructor
A new instance of Terminal.
- #number_length(file_coverage) ⇒ Object
- #output ⇒ Object
- #output_file(file_coverage) ⇒ Object
- #output_file_header(file_coverage) ⇒ Object
- #output_files ⇒ Object
- #output_header ⇒ Object
- #output_line(line, max) ⇒ Object
- #output_summary ⇒ Object
Constructor Details
#initialize(report) ⇒ Terminal
Returns a new instance of Terminal.
11 12 13 |
# File 'lib/plugins/uncov/formatter/terminal.rb', line 11 def initialize(report) @report = report end |
Instance Attribute Details
#report ⇒ Object (readonly)
Returns the value of attribute report.
9 10 11 |
# File 'lib/plugins/uncov/formatter/terminal.rb', line 9 def report @report end |
Instance Method Details
#format_line(line, max) ⇒ Object
67 68 69 |
# File 'lib/plugins/uncov/formatter/terminal.rb', line 67 def format_line(line, max) format("%#{max}d: %s", line.number, line.content) end |
#number_length(file_coverage) ⇒ Object
71 72 73 |
# File 'lib/plugins/uncov/formatter/terminal.rb', line 71 def number_length(file_coverage) file_coverage.display_lines.last.number.to_s.length end |
#output ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/plugins/uncov/formatter/terminal.rb', line 15 def output return puts 'No files to report.'.green if report.files.empty? return puts "All changed files(#{report.files.count}) have 100% test coverage!".green unless report.trigger? output_header output_files output_summary end |
#output_file(file_coverage) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/plugins/uncov/formatter/terminal.rb', line 34 def output_file(file_coverage) puts output_file_header(file_coverage) max = number_length(file_coverage) file_coverage.display_lines.each do |line| output_line(line, max) end end |
#output_file_header(file_coverage) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/plugins/uncov/formatter/terminal.rb', line 43 def output_file_header(file_coverage) puts format( '%<name>s -> %<coverage>.2f%% (%<covered_lines>d / %<relevant_lines>d) changes covered, uncovered lines:', name: file_coverage.file_name, coverage: file_coverage.coverage, covered_lines: file_coverage.covered_lines_count, relevant_lines: file_coverage.relevant_lines_count ).yellow end |
#output_files ⇒ Object
28 29 30 31 32 |
# File 'lib/plugins/uncov/formatter/terminal.rb', line 28 def output_files report.display_files.each do |file_coverage| output_file(file_coverage) end end |
#output_header ⇒ Object
24 25 26 |
# File 'lib/plugins/uncov/formatter/terminal.rb', line 24 def output_header puts "Files with uncovered changes: (#{report.display_files.size} / #{report.files.count})".yellow end |
#output_line(line, max) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/plugins/uncov/formatter/terminal.rb', line 53 def output_line(line, max) if line.uncov? puts format_line(line, max).red elsif line.context puts format_line(line, max).green elsif line.nocov_covered? puts format_line(line, max).blue else # :nocov: raise 'unknown display line' # unreachable code # :nocov: end end |
#output_summary ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/plugins/uncov/formatter/terminal.rb', line 75 def output_summary puts puts format( 'Overall coverage of changes: %<coverage>.2f%% (%<covered_lines>d / %<relevant_lines>d)', coverage: report.coverage, covered_lines: report.covered_lines_count, relevant_lines: report.relevant_lines_count ).yellow end |