Class: SimpleCov::Formatter::Terminal::ResultPrinter
- Inherits:
-
Object
- Object
- SimpleCov::Formatter::Terminal::ResultPrinter
- Extended by:
- Forwardable
- Includes:
- MemoWise, BranchCoverage, ColorPrinting
- Defined in:
- lib/simple_cov/formatter/terminal/result_printer.rb
Instance Method Summary collapse
-
#initialize(file_determiner) ⇒ ResultPrinter
constructor
A new instance of ResultPrinter.
- #print_coverage_details(sourcefile) ⇒ Object
- #print_coverage_info(result) ⇒ Object
- #print_coverage_summary(sourcefile, log_addendum = nil) ⇒ Object
- #print_info_for_no_executed_specs ⇒ Object
- #print_info_for_nonexistent_application_target ⇒ Object
- #print_info_for_undeterminable_application_target ⇒ Object
- #print_info_for_undetermined_application_target ⇒ Object
- #print_no_coverage_info_found ⇒ Object
- #print_skipped_lines(skipped_lines) ⇒ Object
Methods included from ColorPrinting
Constructor Details
#initialize(file_determiner) ⇒ ResultPrinter
Returns a new instance of ResultPrinter.
15 16 17 |
# File 'lib/simple_cov/formatter/terminal/result_printer.rb', line 15 def initialize(file_determiner) @file_determiner = file_determiner end |
Instance Method Details
#print_coverage_details(sourcefile) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/simple_cov/formatter/terminal/result_printer.rb', line 49 def print_coverage_details(sourcefile) @sourcefile = sourcefile puts("---- Coverage for #{targeted_application_file} ".ljust(80, '-').rstrip) skipped_lines = [] sourcefile.lines.each do |line| if print_line?(line.line_number) if skipped_lines.any? print_skipped_lines(skipped_lines) end puts(line_printer.colored_line(line, sourcefile)) skipped_lines = [] else skipped_lines << line.line_number end end if skipped_lines.any? print_skipped_lines(skipped_lines) end puts(" ----\n Line coverage: \#{colorized_coverage(sourcefile.covered_percent)}\n |\n Uncovered branches: \#{colorized_uncovered_branches(uncovered_branches(sourcefile).size)}\n ----\n LOG\nend\n".squish) |
#print_coverage_info(result) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/simple_cov/formatter/terminal/result_printer.rb', line 19 def print_coverage_info(result) sourcefile = result.files.find { it.filename.end_with?(targeted_application_file) } force_coverage = ENV.fetch('SIMPLECOV_FORCE_DETAILS', nil) == '1' if sourcefile.nil? print_no_coverage_info_found elsif failure_occurred? && !force_coverage print_coverage_summary(sourcefile, 'Not showing detailed coverage because an example failed.') elsif sourcefile.covered_percent < 100 || uncovered_branches(sourcefile).any? || force_coverage print_coverage_details(sourcefile) else print_coverage_summary(sourcefile) end end |
#print_coverage_summary(sourcefile, log_addendum = nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/simple_cov/formatter/terminal/result_printer.rb', line 34 def print_coverage_summary(sourcefile, log_addendum = nil) summary = "-- Coverage for #{targeted_application_file} --\n" summary << "Line coverage: #{colorized_coverage(sourcefile.covered_percent)}" if SimpleCov.branch_coverage? summary << ' ' summary << " | Uncovered branches: \#{colorized_uncovered_branches(uncovered_branches(sourcefile).size)}\n LOG\n else\n summary << \"\\n\"\n end\n summary << log_addendum if log_addendum\n puts(summary)\nend\n" |
#print_info_for_no_executed_specs ⇒ Object
107 108 109 |
# File 'lib/simple_cov/formatter/terminal/result_printer.rb', line 107 def print_info_for_no_executed_specs puts('Not showing test coverage details because no specs were executed successfully.') end |
#print_info_for_nonexistent_application_target ⇒ Object
132 133 134 135 136 137 |
# File 'lib/simple_cov/formatter/terminal/result_printer.rb', line 132 def print_info_for_nonexistent_application_target puts(" Cannot show code coverage. Looked for application file \"\#{targeted_application_file}\",\n but it does not exist.\n LOG\nend\n".squish) |
#print_info_for_undeterminable_application_target ⇒ Object
111 112 113 114 115 116 117 118 119 |
# File 'lib/simple_cov/formatter/terminal/result_printer.rb', line 111 def print_info_for_undeterminable_application_target puts(" Not showing test coverage details because \"\#{executed_spec_file}\" cannot\n be mapped to a single application file.\n LOG\n puts(<<~LOG.squish)\n Tip: you can specify a file manually via a SIMPLECOV_TARGET_FILE environment variable.\n LOG\nend\n".squish) |
#print_info_for_undetermined_application_target ⇒ Object
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/simple_cov/formatter/terminal/result_printer.rb', line 121 def print_info_for_undetermined_application_target puts(" Not showing test coverage details because we could not map \"\#{executed_spec_file}\"\n to an application file.\n LOG\n puts(<<~LOG.squish)\n Tip: You can provide a mapping via\n `SimpleCov::Formatter::Terminal.config.spec_to_app_file_map`.\n LOG\nend\n".squish) |
#print_no_coverage_info_found ⇒ Object
100 101 102 103 104 105 |
# File 'lib/simple_cov/formatter/terminal/result_printer.rb', line 100 def print_no_coverage_info_found puts(" No code coverage info was found for \"\#{targeted_application_file}\". Try stopping and\n disabling `spring`, if you are using it, and then rerun the spec.\n LOG\nend\n".squish) |
#print_skipped_lines(skipped_lines) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/simple_cov/formatter/terminal/result_printer.rb', line 81 def print_skipped_lines(skipped_lines) divider = ' -' * 40 # If we are skipping lines because they aren't in an env var specified # range, they might or might not be covered. If we are skipping them # otherwise, it's because they're covered. skipped_lines_adjective = ENV.fetch('SIMPLECOV_TERMINAL_LINES', nil).present? ? '' : 'covered ' puts(line_printer.numbered_line_output(nil, :white, divider)) puts( line_printer.numbered_line_output( nil, :white, "#{skipped_lines.size} #{skipped_lines_adjective}line(s) omitted".center(80, ' '), ), ) puts(line_printer.numbered_line_output(nil, :white, divider)) end |