Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coverage.rb: Fix handling of 0 total resources #805

Merged
merged 2 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/rspec-puppet/coverage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ def results
report[:total] = @collection.size
report[:touched] = @collection.count { |_, resource| resource.touched? }
report[:untouched] = report[:total] - report[:touched]
report[:coverage] = "%5.2f" % ((report[:touched].to_f / report[:total].to_f) * 100)

coverage = report[:total].to_f > 0 ? ((report[:touched].to_f / report[:total].to_f) * 100) : 100.0
report[:coverage] = "%5.2f" % coverage

report[:resources] = Hash[*@collection.map do |name, wrapper|
[name, wrapper.to_hash]
Expand Down
9 changes: 9 additions & 0 deletions spec/unit/coverage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,14 @@
expect(resources["Notify[#{name}]"]).to eq(:touched => false)
end
end

context "when there are no resources" do
let(:touched) { [] }
let(:untouched) { [] }

it "reports 100% coverage" do
expect(report[:coverage]).to eq "100.00"
end
end
end
end