diff --git a/lib/undercover/result.rb b/lib/undercover/result.rb index 5a6b902..3f59bb8 100644 --- a/lib/undercover/result.rb +++ b/lib/undercover/result.rb @@ -13,7 +13,7 @@ class Result def initialize(node, file_cov, file_path) @node = node @coverage = file_cov.select do |ln, _| - ln > first_line && ln < last_line + first_line == last_line ? ln == first_line : ln > first_line && ln < last_line end @file_path = file_path @flagged = false diff --git a/spec/fixtures/one_line_block.lcov b/spec/fixtures/one_line_block.lcov new file mode 100644 index 0000000..773fd38 --- /dev/null +++ b/spec/fixtures/one_line_block.lcov @@ -0,0 +1,7 @@ +SF:./one_line_block.rb +DA:2,1 +DA:3,1 +DA:4,1 +DA:6,1 +DA:7,0 +end_of_record diff --git a/spec/fixtures/one_line_block.rb b/spec/fixtures/one_line_block.rb new file mode 100644 index 0000000..e4e8ac4 --- /dev/null +++ b/spec/fixtures/one_line_block.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true +class BaconClass + # types of bacon + BACON_TYPES = %w[peameal back bacon].freeze + + def favorite + BACON_TYPES.select{ |type| type == 'back bacon'} + end +end diff --git a/spec/result_spec.rb b/spec/result_spec.rb index 74bb44b..3de2ff3 100644 --- a/spec/result_spec.rb +++ b/spec/result_spec.rb @@ -60,4 +60,19 @@ expect(result.uncovered?(27)).to be_falsy end end + + context 'for oneline block uncovered' do + let(:ast) { Imagen.from_local('spec/fixtures/one_line_block.rb') } + let(:lcov) do + Undercover::LcovParser.parse('spec/fixtures/one_line_block.lcov') + end + let(:coverage) { lcov.source_files['one_line_block.rb'] } + + it 'uncovered gives true' do + node = ast.children[0].find_all(->(_) { true }).last + result = described_class.new(node, coverage, 'one_line_block.rb') + + expect(result.uncovered?(7)).to be_truthy + end + end end