Skip to content

Commit

Permalink
add specs for method cov merging
Browse files Browse the repository at this point in the history
  • Loading branch information
tycooon committed Apr 24, 2021
1 parent 15c03b2 commit 9851ba0
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
67 changes: 67 additions & 0 deletions spec/result_merger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,73 @@
expect_resultset_1_and_2_merged(result_hash)
end
end

describe "method coverage" do
before do
SimpleCov.enable_coverage :method
store_result(result3, path: resultset3_path)
end

after do
SimpleCov.clear_coverage_criteria
end

let(:resultset1) do
{
source_fixture("methods.rb") => {
methods: {
["A", :method1, 2, 2, 5, 5] => 1,
["A", :method2, 9, 2, 11, 5] => 0,
["A", :method3, 13, 2, 15, 5] => 0,
}
}
}
end

let(:resultset2) do
{
source_fixture("methods.rb") => {
methods: {
["A", :method1, 2, 2, 5, 5] => 0,
["A", :method2, 9, 2, 11, 5] => 1,
["A", :method3, 13, 2, 15, 5] => 0,
}
}
}
end

let(:resultset3) do
{
source_fixture("methods.rb") => {
methods: {
["B", :method1, 2, 2, 5, 5] => 1,
["B", :method2, 9, 2, 11, 5] => 0,
["B", :method3, 13, 2, 15, 5] => 0,
}
}
}
end

let(:result3) { SimpleCov::Result.new(resultset3, command_name: "result3") }
let(:resultset3_path) { "#{resultset_prefix}3.json" }

it "correctly merges the 3 results" do
result = SimpleCov::ResultMerger.merge_and_store(
resultset1_path, resultset2_path, resultset3_path
)

merged_coverage = result.original_result.fetch(source_fixture("methods.rb"))

expect(merged_coverage.fetch(:methods)).to eq(
["A", :method1, 2, 2, 5, 5] => 1,
["A", :method2, 9, 2, 11, 5] => 1,
["A", :method3, 13, 2, 15, 5] => 0,
["B", :method1, 2, 2, 5, 5] => 1,
["B", :method2, 9, 2, 11, 5] => 0,
["B", :method3, 13, 2, 15, 5] => 0
)
end
end
end

context "pre 0.18 result format" do
Expand Down
4 changes: 2 additions & 2 deletions spec/source_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@
lines: [1, 1, 1, 1, nil, nil, 1, nil, 1, 1, nil, nil, 1, 0, nil, nil, nil, 1],
branches: {},
methods: {
["A", :method3, 13, 2, 15, 5] => 0,
["A", :method1, 2, 2, 5, 5] => 1,
["A", :method2, 9, 2, 11, 5] => 1,
["A", :method1, 2, 2, 5, 5] => 1
["A", :method3, 13, 2, 15, 5] => 0
}
}
end
Expand Down

0 comments on commit 9851ba0

Please sign in to comment.