diff --git a/features/maximum_coverage_drop.feature b/features/maximum_coverage_drop.feature index afa586a8..89012b4a 100644 --- a/features/maximum_coverage_drop.feature +++ b/features/maximum_coverage_drop.feature @@ -85,5 +85,55 @@ Feature: } } """ + Scenario: test failures do not update the resultset + Given SimpleCov for RSpec is configured with: + """ + require 'simplecov' + SimpleCov.start do + add_group 'Libs', 'lib/faked_project/' + add_filter '/spec/' + maximum_coverage_drop 0 + end + """ + + And 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 + """ + + And a file named "spec/failing_spec.rb" with: + """ + require "spec_helper" + describe FakedProject do + it "fails" do + expect(false).to eq(true) + end + end + """ + And the file named "coverage/.last_run.json" with: + """ + { + "result": { + "covered_percent": 100.0 + } + } + """ + When I run `bundle exec rspec spec` + Then the exit status should be 1 + And a file named "coverage/.last_run.json" should exist + And the file "coverage/.last_run.json" should contain: + """ + { + "result": { + "covered_percent": 100.0 + } + } + """ diff --git a/lib/simplecov/defaults.rb b/lib/simplecov/defaults.rb index b128243e..b1797a86 100644 --- a/lib/simplecov/defaults.rb +++ b/lib/simplecov/defaults.rb @@ -87,11 +87,10 @@ @exit_status = SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP end end - end - # Don't overwrite last_run file if refuse_coverage_drop option is enabled and the coverage has dropped - unless @exit_status == SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP - SimpleCov::LastRun.write(:result => {:covered_percent => covered_percent}) + if @exit_status == SimpleCov::ExitCodes::SUCCESS # rubocop:disable Metrics/BlockNesting + SimpleCov::LastRun.write(:result => {:covered_percent => covered_percent}) + end end end