-
Notifications
You must be signed in to change notification settings - Fork 551
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename CoverageData to CoverageStatistics
*Data was an unfortunate name, as in SourceFile that's what the attribute holding the well... actual coverage data emitted from the coverage library. All in all it's statistics for display and that should be helpful and neat, and not clash with other names.
- Loading branch information
Showing
6 changed files
with
87 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# frozen_string_literal: true | ||
|
||
require "helper" | ||
|
||
RSpec.describe SimpleCov::CoverageStatistics do | ||
describe ".new" do | ||
it "retains statistics and computes new ones" do | ||
statistics = described_class.new(covered: 4, missed: 6, total_strength: 14) | ||
|
||
expect(statistics.covered).to eq 4 | ||
expect(statistics.missed).to eq 6 | ||
|
||
expect(statistics.total).to eq 10 | ||
expect(statistics.percent).to eq 40.0 | ||
expect(statistics.strength).to eq 1.4 | ||
end | ||
|
||
it "can omit the total strength defaulting to 0.0" do | ||
statistics = described_class.new(covered: 4, missed: 6, total_strength: 0.0) | ||
|
||
expect(statistics.strength).to eq 0.0 | ||
end | ||
|
||
it "can deal with it if everything is 0" do | ||
statistics = described_class.new(covered: 0, missed: 0, total_strength: 0.0) | ||
|
||
expect_all_empty(statistics) | ||
end | ||
end | ||
|
||
describe ".from" do | ||
it "returns an all 0s coverage statistics if there is no statistics" do | ||
statistics = described_class.from([]) | ||
|
||
expect_all_empty(statistics) | ||
end | ||
|
||
it "returns all empty statistics when initialized with a couple of empty results" do | ||
statistics = described_class.from([empty_statistics, empty_statistics]) | ||
|
||
expect_all_empty(statistics) | ||
end | ||
|
||
it "produces sensible total results" do | ||
statistics = described_class.from( | ||
[ | ||
described_class.new(covered: 3, missed: 4, total_strength: 54), | ||
described_class.new(covered: 0, missed: 13, total_strength: 0), | ||
described_class.new(covered: 37, missed: 0, total_strength: 682) | ||
] | ||
) | ||
|
||
expect(statistics.covered).to eq 40 | ||
expect(statistics.missed).to eq 17 | ||
expect(statistics.total).to eq 57 | ||
expect(statistics.percent).to be_within(0.01).of(70.18) | ||
expect(statistics.strength).to be_within(0.01).of(12.91) | ||
end | ||
end | ||
|
||
def empty_statistics | ||
described_class.new(covered: 0, missed: 0, total_strength: 0.0) | ||
end | ||
|
||
def expect_all_empty(statistics) | ||
expect(statistics.covered).to eq 0 | ||
expect(statistics.missed).to eq 0 | ||
|
||
expect(statistics.total).to eq 0 | ||
# might be counter intuitive but think of it as "we covered everything we could" | ||
expect(statistics.percent).to eq 100.0 | ||
expect(statistics.strength).to eq 0.0 | ||
end | ||
end |