Created
September 20, 2015 21:48
-
-
Save gtd/13115fc484b082c4bd67 to your computer and use it in GitHub Desktop.
This class returns a set of *.rb files which are not present in a SimpleCov resultset
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 class returns a set of *.rb files which are not present in a SimpleCov resultset | |
# | |
require 'json' | |
require 'set' | |
class CoverageChecker | |
def missed_files(dir = 'app') | |
uncovered_files(dir) | |
end | |
private | |
def covered_files | |
@covered_files ||= resultset.inject(Set.new) do |files, (key, val)| | |
files += val['coverage'].keys.map{ |file| file.gsub(Dir.pwd + '/', '') } | |
files | |
end | |
end | |
def uncovered_files(path) | |
if File.file?(path) && | |
File.extname(path) == '.rb' && | |
!covered_files.include?(path) | |
[path] | |
elsif File.directory?(path) | |
Dir["#{path}/*"].map do |subpath| | |
uncovered_files(subpath) | |
end.flatten.compact | |
end | |
end | |
def resultset | |
JSON.parse File.read(simplecov_resultset_path) | |
end | |
def simplecov_resultset_path | |
'coverage/.resultset.json' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gem released at https://github.com/gtd/simplecov_checker