Module: SolargraphTestCoverage::ReporterHelpers

Included in:
ExampleStatusReporter, TestCoverageReporter
Defined in:
lib/solargraph_test_coverage/reporter_helpers.rb

Overview

Some helper functions for the diagnostics

Instance Method Summary collapse

Instance Method Details

#branch_warningsObject



17
18
19
20
21
# File 'lib/solargraph_test_coverage/reporter_helpers.rb', line 17

def branch_warnings
  Branch.build_from(@results)
        .reject(&:covered?)
        .map { |branch| branch_coverage_warning(branch.report) }
end

#example_failing_errorsObject



27
28
29
30
# File 'lib/solargraph_test_coverage/reporter_helpers.rb', line 27

def example_failing_errors
  @results.fetch(:failed_examples, [])
          .map { |example| example_failing_error(example) }
end

#line_warningsObject



32
33
34
# File 'lib/solargraph_test_coverage/reporter_helpers.rb', line 32

def line_warnings
  uncovered_lines.map { |line| line_coverage_warning(line) }
end

#run_test(test_file) ⇒ Hash

Returns:

  • (Hash)


7
8
9
10
11
12
13
14
15
# File 'lib/solargraph_test_coverage/reporter_helpers.rb', line 7

def run_test(test_file)
  ForkProcess.call do
    Coverage.start(lines: true, branches: true)
    runner = TestRunner.with(test_file).run!
    extra = { test_status: runner.passed?, failed_examples: runner.failed_examples }

    Coverage.result.fetch(@filename, {}).merge(extra)
  end
end

#test_passing_errorObject



23
24
25
# File 'lib/solargraph_test_coverage/reporter_helpers.rb', line 23

def test_passing_error
  @results[:test_status] ? [] : [test_failing_error]
end

#uncovered_linesObject

Adapted from SingleCov Coverage returns nil for untestable lines (like ‘do’, ‘end’, ‘if’ keywords) otherwise returns int showing how many times a line was called

[nil, 1, 0, 1, 0] -> [3, 5]
Returns array of line numbers with 0 coverage


42
43
44
45
46
47
48
49
# File 'lib/solargraph_test_coverage/reporter_helpers.rb', line 42

def uncovered_lines
  return [] unless @results[:lines]

  @results[:lines].each_with_index
                  .select { |c, _| c&.zero? }
                  .map { |_, i| i }
                  .compact
end