Skip to content

Instantly share code, notes, and snippets.

@gtd
Created September 20, 2015 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gtd/13115fc484b082c4bd67 to your computer and use it in GitHub Desktop.
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 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
@gtd
Copy link
Author

gtd commented Sep 21, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment