Skip to content

Commit

Permalink
Add a refuse_coverage_drop configuration option
Browse files Browse the repository at this point in the history
[Fixes #11]
  • Loading branch information
infertux committed Sep 7, 2012
1 parent 9c17355 commit 40d3593
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
35 changes: 35 additions & 0 deletions features/refuse_coverage_drop.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@test_unit @config
Feature:

Exit code should be non-zero if the overall coverage decreases.

Scenario:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_filter 'test.rb'
refuse_coverage_drop
end
"""

When I run `bundle exec rake test`
Then the exit status should be 0
And a file named "coverage/.last_run.json" should exist

Given a file named "lib/faked_project/missed.rb" with:
"""
class UncoveredSourceCode
def foo
never_reached
rescue => err
but no one cares about invalid ruby here
end
end
"""

When I run `bundle exec rake test`
Then the exit status should not be 0
And the output should contain "Coverage has dropped by 3.31% since the last time (maximum allowed: 0.00%)."
And a file named "coverage/.last_run.json" should exist

8 changes: 8 additions & 0 deletions lib/simplecov/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ def maximum_coverage_drop(coverage_drop=nil)
@maximum_coverage_drop ||= 100
end

#
# Refuses any coverage drop. That is, coverage is only allowed to increase.
# SimpleCov will return non-zero if the coverage decreases.
#
def refuse_coverage_drop
maximum_coverage_drop 0
end

#
# Add a filter to the processing chain.
# There are three ways to define a filter:
Expand Down

0 comments on commit 40d3593

Please sign in to comment.