Skip to content

Commit

Permalink
Merge pull request #625 from thomas07vt/issues/624/refuse_coverage_dr…
Browse files Browse the repository at this point in the history
…op_on_failed_test

Fixes #624 Checks max_coverage_drop on failed tests
  • Loading branch information
PragTob authored Oct 6, 2017
2 parents 0eda901 + 66ffa82 commit a51ea16
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 @@ -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

Expand Down

0 comments on commit a51ea16

Please sign in to comment.