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

Warn the user if the minimum coverage is set greater than 100 #737

Merged
merged 2 commits into from
Jul 28, 2019
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Unrealeased
===================

## Enhancements

* If the minimum coverage is set to be greater than 100, a warning will be shown. See [#737](https://github.com/colszowka/simplecov/pull/737)

0.17.0 (2019-07-02)
===================

Expand Down
6 changes: 6 additions & 0 deletions lib/simplecov/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ def merge_timeout(seconds = nil)
# Default is 0% (disabled)
#
def minimum_coverage(coverage = nil)
minimum_possible_coverage_exceeded("minimum_coverage") if coverage && coverage > 100
@minimum_coverage ||= (coverage || 0).to_f.round(2)
end

Expand All @@ -245,6 +246,7 @@ def maximum_coverage_drop(coverage_drop = nil)
# Default is 0% (disabled)
#
def minimum_coverage_by_file(coverage = nil)
minimum_possible_coverage_exceeded("minimum_coverage_by_file") if coverage && coverage > 100
@minimum_coverage_by_file ||= (coverage || 0).to_f.round(2)
end

Expand Down Expand Up @@ -288,6 +290,10 @@ def add_group(group_name, filter_argument = nil, &filter_proc)

private

def minimum_possible_coverage_exceeded(coverage_option)
warn "The coverage you set for #{coverage_option} is greater than 100%"
end

#
# The actual filter processor. Not meant for direct use
#
Expand Down
24 changes: 24 additions & 0 deletions spec/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,29 @@
expect(config.tracked_files).to be_nil
end
end

describe "#minimum_coverage" do
it "does not warn you about your usage" do
expect(config).not_to receive(:warn)
config.minimum_coverage(100.00)
end

it "warns you about your usage" do
expect(config).to receive(:warn).with("The coverage you set for minimum_coverage is greater than 100%")
config.minimum_coverage(100.01)
end
end

describe "minimum_coverage_by_file" do
it "does not warn you about your usage" do
expect(config).not_to receive(:warn)
config.minimum_coverage_by_file(100.00)
end

it "warns you about your usage" do
expect(config).to receive(:warn).with("The coverage you set for minimum_coverage_by_file is greater than 100%")
config.minimum_coverage_by_file(100.01)
end
end
end
end