Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a38d973
commit a328d00
Showing
7 changed files
with
93 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# See rails_helpers.rb and coverage_checker.rb | ||
# This is our own file, which we use to fail the build if specific files fall do not have 100% test coverage. | ||
check_test_coverage_for_files: | ||
- app/controllers/educators/sessions_controller.rb | ||
- lib/authorizer.rb | ||
- lib/ldap_authenticatable_tiny/model.rb | ||
- lib/ldap_authenticatable_tiny/strategy.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
class CoverageChecker | ||
ERROR_STATUS_CODE = 172 | ||
|
||
# By default, only run this on full test runs (eg, in Travis) or when explicitly asked. | ||
# In the common development case where you only run a subset of tests, this will have | ||
# frequent false positive failures (since only some of the tests were run). | ||
def setup! | ||
return unless EnvironmentVariable.is_true('ENABLE_RSPEC_COVERAGE_CHECKER') | ||
SimpleCov.at_exit do | ||
SimpleCov.result.format! | ||
fail_if_uncovered!(SimpleCov.result.files) | ||
end | ||
end | ||
|
||
private | ||
def fail_if_uncovered!(files) | ||
files_to_check = filtered_files(files) | ||
uncovered_files = files_to_check.select {|file| file.covered_percent < 100 } | ||
|
||
if files_to_check.size == 0 | ||
puts "CoverageChecker: On this run, found no files to check for full coverage, skipping..." | ||
elsif uncovered_files.size == 0 | ||
puts "CoverageChecker: On this run, checked #{files_to_check.size} files for full coverage, all passed!" | ||
else | ||
puts "CoverageChecker: On this run, checked #{files_to_check.size} files for full coverage." | ||
puts "CoverageChecker: Found #{uncovered_files.size} #{uncovered_files.size == 1 ? 'file that was not' : 'files that were not'} fully covered." | ||
file_lines = uncovered_files.map do |file| | ||
"#{file.filename} - #{file.covered_percent.round}%" | ||
end | ||
puts " - " + file_lines.join("\n - ") | ||
puts "CoverageChecked: Exiting with error status #{ERROR_STATUS_CODE}" | ||
Kernel.exit ERROR_STATUS_CODE | ||
end | ||
end | ||
|
||
def filtered_files(files) | ||
config_file = File.open(File.join(Rails.root, 'spec', 'coverage_bot.yml')) | ||
files_to_check = YAML.load(config_file)['check_test_coverage_for_files'] | ||
files.select do |file| | ||
files_to_check.any? {|file_to_check| file.filename.ends_with?(file_to_check)} | ||
end | ||
end | ||
end |