|
| 1 | +require "helper" |
| 2 | + |
| 3 | +if SimpleCov.usable? |
| 4 | + describe SimpleCov::RawCoverage do |
| 5 | + describe "with two faked coverage resultsets" do |
| 6 | + before do |
| 7 | + @resultset1 = { |
| 8 | + source_fixture("sample.rb") => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil], |
| 9 | + source_fixture("app/models/user.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil], |
| 10 | + source_fixture("app/controllers/sample_controller.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil], |
| 11 | + source_fixture("resultset1.rb") => [1, 1, 1, 1], |
| 12 | + source_fixture("parallel_tests.rb") => [nil, 0, nil, 0], |
| 13 | + source_fixture("conditionally_loaded_1.rb") => [nil, 0, 1], # loaded only in the first resultset |
| 14 | + source_fixture("three.rb") => [nil, 1, 1], |
| 15 | + } |
| 16 | + |
| 17 | + @resultset2 = { |
| 18 | + source_fixture("sample.rb") => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil], |
| 19 | + source_fixture("app/models/user.rb") => [nil, 1, 5, 1, nil, nil, 1, 0, nil, nil], |
| 20 | + source_fixture("app/controllers/sample_controller.rb") => [nil, 3, 1, nil, nil, nil, 1, 0, nil, nil], |
| 21 | + source_fixture("resultset2.rb") => [nil, 1, 1, nil], |
| 22 | + source_fixture("parallel_tests.rb") => [nil, nil, 0, 0], |
| 23 | + source_fixture("conditionally_loaded_2.rb") => [nil, 0, 1], # loaded only in the second resultset |
| 24 | + source_fixture("three.rb") => [nil, 1, 4], |
| 25 | + } |
| 26 | + |
| 27 | + @resultset3 = { |
| 28 | + source_fixture("three.rb") => [nil, 1, 2], |
| 29 | + } |
| 30 | + end |
| 31 | + |
| 32 | + context "a merge" do |
| 33 | + subject do |
| 34 | + SimpleCov::RawCoverage.merge_results(@resultset1, @resultset2, @resultset3) |
| 35 | + end |
| 36 | + |
| 37 | + it "has proper results for sample.rb" do |
| 38 | + expect(subject[source_fixture("sample.rb")]).to eq([1, 1, 2, 2, nil, nil, 2, 2, nil, nil]) |
| 39 | + end |
| 40 | + |
| 41 | + it "has proper results for user.rb" do |
| 42 | + expect(subject[source_fixture("app/models/user.rb")]).to eq([nil, 2, 6, 2, nil, nil, 2, 0, nil, nil]) |
| 43 | + end |
| 44 | + |
| 45 | + it "has proper results for sample_controller.rb" do |
| 46 | + expect(subject[source_fixture("app/controllers/sample_controller.rb")]).to eq([nil, 4, 2, 1, nil, nil, 2, 0, nil, nil]) |
| 47 | + end |
| 48 | + |
| 49 | + it "has proper results for resultset1.rb" do |
| 50 | + expect(subject[source_fixture("resultset1.rb")]).to eq([1, 1, 1, 1]) |
| 51 | + end |
| 52 | + |
| 53 | + it "has proper results for resultset2.rb" do |
| 54 | + expect(subject[source_fixture("resultset2.rb")]).to eq([nil, 1, 1, nil]) |
| 55 | + end |
| 56 | + |
| 57 | + it "has proper results for parallel_tests.rb" do |
| 58 | + expect(subject[source_fixture("parallel_tests.rb")]).to eq([nil, nil, nil, 0]) |
| 59 | + end |
| 60 | + |
| 61 | + it "has proper results for conditionally_loaded_1.rb" do |
| 62 | + expect(subject[source_fixture("conditionally_loaded_1.rb")]).to eq([nil, 0, 1]) |
| 63 | + end |
| 64 | + |
| 65 | + it "has proper results for conditionally_loaded_2.rb" do |
| 66 | + expect(subject[source_fixture("conditionally_loaded_2.rb")]).to eq([nil, 0, 1]) |
| 67 | + end |
| 68 | + |
| 69 | + it "has proper results for three.rb" do |
| 70 | + expect(subject[source_fixture("three.rb")]).to eq([nil, 3, 7]) |
| 71 | + end |
| 72 | + end |
| 73 | + end |
| 74 | + |
| 75 | + it "merges frozen resultsets" do |
| 76 | + resultset1 = { |
| 77 | + source_fixture("sample.rb").freeze => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil].freeze, |
| 78 | + source_fixture("app/models/user.rb").freeze => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil].freeze, |
| 79 | + }.freeze |
| 80 | + |
| 81 | + resultset2 = { |
| 82 | + source_fixture("sample.rb").freeze => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil].freeze, |
| 83 | + }.freeze |
| 84 | + |
| 85 | + merged_result = SimpleCov::RawCoverage.merge_results(resultset1, resultset2) |
| 86 | + expect(merged_result.keys).to eq(resultset1.keys) |
| 87 | + expect(merged_result.values.map(&:frozen?)).to eq([false, false]) |
| 88 | + expect(merged_result[source_fixture("sample.rb")]).to eq([1, 1, 2, 2, nil, nil, 2, 2, nil, nil]) |
| 89 | + expect(merged_result[source_fixture("app/models/user.rb")]).to eq([nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]) |
| 90 | + end |
| 91 | + end |
| 92 | +end |
0 commit comments