1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 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)
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 are 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
|