From 40d3593ce8d4524d69485eae8ef1494a78473860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20F=C3=A9lizard?= Date: Sat, 8 Sep 2012 00:17:35 +0200 Subject: [PATCH] Add a refuse_coverage_drop configuration option [Fixes #11] --- features/refuse_coverage_drop.feature | 35 +++++++++++++++++++++++++++ lib/simplecov/configuration.rb | 8 ++++++ 2 files changed, 43 insertions(+) create mode 100644 features/refuse_coverage_drop.feature diff --git a/features/refuse_coverage_drop.feature b/features/refuse_coverage_drop.feature new file mode 100644 index 00000000..9f35aae9 --- /dev/null +++ b/features/refuse_coverage_drop.feature @@ -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 + diff --git a/lib/simplecov/configuration.rb b/lib/simplecov/configuration.rb index 56eac789..8b07f904 100644 --- a/lib/simplecov/configuration.rb +++ b/lib/simplecov/configuration.rb @@ -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: