Skip to content

Commit

Permalink
Merge pull request #207 from lizhangyuh/fix-one-line-block-coverage
Browse files Browse the repository at this point in the history
Fix: Update of one-line block is ignored
  • Loading branch information
grodowski authored Jan 8, 2024
2 parents a5a26c1 + f327569 commit 1320022
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/undercover/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions spec/fixtures/one_line_block.lcov
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions spec/fixtures/one_line_block.rb
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions spec/result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1320022

Please sign in to comment.