Skip to content

Commit

Permalink
Merge pull request #79 from infertux/rspec-aggregate-errors
Browse files Browse the repository at this point in the history
feat: better diagnostics for runner result specs
  • Loading branch information
infertux authored Aug 2, 2023
2 parents 3e9a86b + a9a4a1a commit c160eaf
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions spec/bashcov/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,32 @@
runner.run
result = runner.result

expect(result.count).to eq(expected_coverage.count), "expected coverage for #{expected_coverage.count} files, got #{result.count}"
aggregate_failures "expected coverage" do
# Summary view of mismatches when this fails
expect(result).to eq(expected_coverage)

expected_coverage.each do |file, expected_hits|
expect(result).to include(file), "#{file} expected coverage stats but got none"
expect(result.count).to eq(expected_coverage.count), "expected coverage for #{expected_coverage.count} files, got #{result.count}"

actual_hits = result[file]
expected_coverage.each do |file, expected_hits|
expect(result).to(include(file), "#{file} expected coverage stats but got none")

expect(actual_hits.count).to eq(expected_hits.count), "#{file} expected coverage for #{expected_hits.count} line(s), got #{actual_hits.count}"
next unless result.include? file

actual_hits.each_with_index do |actual_hit, lineno|
expected = expected_hits.fetch(lineno)
expect(actual_hit).to eq(expected), "#{file}:#{lineno.succ} expected #{expected.inspect}, got #{actual_hit.inspect}"
actual_hits = result[file]

expect({ file => actual_hits }).to eq({ file => expected_hits })

expect(actual_hits.count).to eq(expected_hits.count), "#{file} expected coverage for #{expected_hits.count} line(s), got #{actual_hits.count}"

actual_hits.each_with_index do |actual_hit, lineno|
expected = expected_hits.fetch(lineno)
expect(actual_hit).to eq(expected), "#{file}:#{lineno.succ} expected #{expected.inspect}, got #{actual_hit.inspect}"
end
end
end

expected_missing.each do |file|
expect(result).not_to include(file), "#{file} should be absent from coverage stats but was not"
expected_missing.each do |file|
expect(result).not_to include(file), "#{file} should be absent from coverage stats but was not"
end
end
end

Expand Down

0 comments on commit c160eaf

Please sign in to comment.