Last active
October 7, 2016 23:51
-
-
Save tenderlove/9d8fb0a5a37c559236237b6e00b0d3a9 to your computer and use it in GitHub Desktop.
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
require 'coverage' | |
module Coverage | |
class << self | |
alias :old_result :result | |
alias :old_peek_result :peek_result | |
attr_writer :result | |
def result | |
if @result | |
diff_results @result, old_result | |
else | |
old_result | |
end | |
end | |
def peek_result | |
if @result | |
diff_results @result, old_peek_result | |
else | |
old_peek_result | |
end | |
end | |
def diff_results old, new | |
(new.keys | old.keys).each_with_object({}) do |file, hash| | |
old_cov = old.fetch(file, []) | |
new_cov = new[file] | |
hash[file] = new_cov.zip(old_cov).map { |n, o| n && o ? n - o : n } | |
end | |
end | |
end | |
end | |
Coverage.start | |
require 'a' | |
p Coverage.peek_result | |
Coverage.result = Coverage.peek_result | |
require 'b' | |
p Coverage.peek_result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment