|
356 | 356 | end |
357 | 357 | end |
358 | 358 |
|
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 |
360 | 360 | subject do |
361 | 361 | SimpleCov::SourceFile.new(source_fixture("sample.rb"), COVERAGE_FOR_SAMPLE_RB_WITH_MORE_LINES) |
362 | 362 | end |
363 | 363 |
|
364 | 364 | 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) |
367 | 366 | end |
368 | 367 |
|
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 |
373 | 372 |
|
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("") |
375 | 390 | end |
376 | 391 | end |
377 | 392 |
|
|
0 commit comments