Skip to content

Commit

Permalink
Resultset is updated when coverage drops if no drop rule specified
Browse files Browse the repository at this point in the history
* Create Features that check the resultset.json is updated when
  no maximum_coverage_drop is configured
* Fix the implementation to not accidentally enable to coverage
  drop feature and then override the resultset.json
  • Loading branch information
PragTob committed Feb 4, 2017
1 parent b6e7c92 commit 15ba769
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 4 deletions.
55 changes: 54 additions & 1 deletion features/maximum_coverage_drop.feature
Expand Up @@ -4,7 +4,7 @@ Feature:
Exit code should be non-zero if the overall coverage decreases by more than
the maximum_coverage_drop threshold.

Scenario:
Scenario: maximum_coverage_drop configured cam cause spec failure
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
Expand Down Expand Up @@ -33,4 +33,57 @@ Feature:
Then the exit status should not be 0
And the output should contain "Coverage has dropped by 3.32% since the last time (maximum allowed: 3.14%)."
And a file named "coverage/.last_run.json" should exist
And the file "coverage/.last_run.json" should contain:
"""
{
"result": {
"covered_percent": 88.1
}
}
"""

Scenario: maximum_coverage_drop not configured updates resultset
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_filter 'test.rb'
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
And the file "coverage/.last_run.json" should contain:
"""
{
"result": {
"covered_percent": 88.1
}
}
"""

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 be 0
And a file named "coverage/.last_run.json" should exist
And the file "coverage/.last_run.json" should contain:
"""
{
"result": {
"covered_percent": 84.78
}
}
"""


45 changes: 44 additions & 1 deletion features/refuse_coverage_drop.feature
Expand Up @@ -4,7 +4,7 @@ Feature:
Exit code should be non-zero if the overall coverage decreases.
And last_run file should not be overwritten with new coverage value.

Scenario:
Scenario: refuse_coverage_drop configured
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
Expand Down Expand Up @@ -50,3 +50,46 @@ Feature:
}
"""

Scenario: refuse_coverage_drop not configured updates resultset
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_filter 'test.rb'
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
And the file "coverage/.last_run.json" should contain:
"""
{
"result": {
"covered_percent": 88.1
}
}
"""

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 be 0
And a file named "coverage/.last_run.json" should exist
And the file "coverage/.last_run.json" should contain:
"""
{
"result": {
"covered_percent": 84.78
}
}
"""
3 changes: 1 addition & 2 deletions lib/simplecov/defaults.rb
Expand Up @@ -70,7 +70,6 @@
if SimpleCov.result? # Result has been computed
covered_percent = SimpleCov.result.covered_percent.round(2)
covered_percentages = SimpleCov.result.covered_percentages.map { |p| p.round(2) }
coverage_diff = 0

if @exit_status == SimpleCov::ExitCodes::SUCCESS # No other errors
if covered_percent < SimpleCov.minimum_coverage # rubocop:disable Metrics/BlockNesting
Expand All @@ -89,7 +88,7 @@
end

# Don't overwrite last_run file if refuse_coverage_drop option is enabled and the coverage has dropped
unless SimpleCov.refuse_coverage_drop && coverage_diff > 0
unless @exit_status == SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP
SimpleCov::LastRun.write(:result => {:covered_percent => covered_percent})
end
end
Expand Down

0 comments on commit 15ba769

Please sign in to comment.