Skip to content

Commit 9588772

Browse files
coorassesferik
authored andcommitted
Drop warning and ruby 1.9 support.
1 parent 51ad2bd commit 9588772

3 files changed

Lines changed: 26 additions & 13 deletions

File tree

lib/simplecov/source_file.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,6 @@ def lines_strength
272272
lines.sum { |line| line.coverage.to_i }
273273
end
274274

275-
# Warning to identify condition from Issue #56
276-
def coverage_exceeding_source_warn
277-
warn "Warning: coverage data provided by Coverage [#{coverage_data['lines'].size}] exceeds number of lines in #{filename} [#{src.size}]"
278-
end
279-
280275
#
281276
# Build full branches report
282277
# Root branches represent the wrapper of all condition state that

spec/fixtures/issue_1057.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<%= 1 %>
2+
<%= 2 %>
3+
<%= 3 %>

spec/source_file_spec.rb

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,22 +356,37 @@
356356
end
357357
end
358358

359-
context "simulating potential Ruby 1.9 defect -- see Issue #56" do
359+
context "when coverage data contains more entries than the source has lines" do
360360
subject do
361361
SimpleCov::SourceFile.new(source_fixture("sample.rb"), COVERAGE_FOR_SAMPLE_RB_WITH_MORE_LINES)
362362
end
363363

364364
it "has 16 source lines regardless of extra data in coverage array" do
365-
# Do not litter test output with known warning
366-
capture_stderr { expect(subject.lines.count).to eq(16) }
365+
expect(subject.lines.count).to eq(16)
367366
end
368367

369-
it "prints a warning to stderr if coverage array contains more data than lines in the file" do
370-
captured_output = capture_stderr do
371-
subject.lines
372-
end
368+
it "does not emit a warning now that excess entries are trimmed" do
369+
expect(capture_stderr { subject.lines }).to eq("")
370+
end
371+
end
373372

374-
expect(captured_output).to match(/^Warning: coverage data provided/)
373+
# Reproduces https://github.com/simplecov-ruby/simplecov/issues/1057
374+
# ERB compiles a template into Ruby with a trailing `_erbout` line, so when
375+
# `enable_coverage_for_eval` is on (common for Rails view specs), Ruby's
376+
# Coverage reports more lines than the .erb file has.
377+
context "a source file tracked via enable_coverage_for_eval on an ERB template" do
378+
require "erb"
379+
let(:lines) { ERB.new(File.read(erb_file), trim_mode: "<>").src.lines }
380+
let(:erb_file) { source_fixture("issue_1057.erb") }
381+
let(:compiled_line_count) { lines.size }
382+
let(:coverage_data) { {"lines" => Array.new(compiled_line_count, 1), "branches" => {}} }
383+
384+
subject { SimpleCov::SourceFile.new(erb_file, coverage_data) }
385+
386+
it "does not emit a warning about coverage exceeding source" do
387+
puts lines
388+
expect(compiled_line_count).to be > File.readlines(erb_file).size
389+
expect(capture_stderr { subject.lines }).to eq("")
375390
end
376391
end
377392

0 commit comments

Comments
 (0)