Skip to content

Commit

Permalink
Fixes #624 Only write last run result on successes
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas07vt committed Oct 5, 2017
1 parent 96b7247 commit 66ffa82
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
50 changes: 50 additions & 0 deletions features/maximum_coverage_drop.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
"""

7 changes: 3 additions & 4 deletions lib/simplecov/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,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

Expand Down

0 comments on commit 66ffa82

Please sign in to comment.