Skip to content

Commit

Permalink
Warn the user if the minimum coverage is set greater than 100 (#737)
Browse files Browse the repository at this point in the history
* Warn the user if the minimum coverage that is being set is greater than 100
  • Loading branch information
belfazt authored and PragTob committed Jul 28, 2019
1 parent fcad271 commit 175fbb8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
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

0 comments on commit 175fbb8

Please sign in to comment.