Class: RuboCop::RSpecParity::CoverageReporter
- Inherits:
-
Object
- Object
- RuboCop::RSpecParity::CoverageReporter
- Defined in:
- lib/rubocop/rspec_parity/coverage_reporter.rb
Overview
Lists the branches a method still needs covered and renders ready-to-paste ‘context ’…‘ do # rspec_parity:covers <branch>` stubs. Backs the `rspec-parity-cover` executable, reusing SufficientContexts’ branch analysis.
When the spec file exists, only branches without a covering annotation are listed (and only for methods that aren’t already fully covered). When it is missing, every branch is listed so a new spec can be bootstrapped.
Defined Under Namespace
Classes: Entry
Instance Method Summary collapse
- #entries ⇒ Object
-
#initialize(source_path, spec_path: nil, line: nil) ⇒ CoverageReporter
constructor
linenarrows the report to the single method enclosing that source line, so ‘rspec-parity-cover file.rb:20` targets one method. - #render ⇒ Object
Constructor Details
#initialize(source_path, spec_path: nil, line: nil) ⇒ CoverageReporter
line narrows the report to the single method enclosing that source line, so ‘rspec-parity-cover file.rb:20` targets one method.
19 20 21 22 23 24 |
# File 'lib/rubocop/rspec_parity/coverage_reporter.rb', line 19 def initialize(source_path, spec_path: nil, line: nil) @source_path = source_path @spec_path = spec_path || derive_spec_path(source_path) @line = line @cop = RuboCop::Cop::RSpecParity::SufficientContexts.new end |
Instance Method Details
#entries ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/rubocop/rspec_parity/coverage_reporter.rb', line 26 def entries ast = parse return [] unless ast spec_content = File.read(@spec_path) if File.exist?(@spec_path) method_nodes(ast).filter_map { |node| entry_for(node, spec_content) } end |
#render ⇒ Object
34 35 36 |
# File 'lib/rubocop/rspec_parity/coverage_reporter.rb', line 34 def render entries.map { |entry| render_entry(entry) }.join("\n\n") end |