Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created January 14, 2018 20:23
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 tenderlove/eefcce7dcadb0ed48968f575698e3f04 to your computer and use it in GitHub Desktop.
Save tenderlove/eefcce7dcadb0ed48968f575698e3f04 to your computer and use it in GitHub Desktop.
diff --git a/example.rb b/example.rb
index 088e788..8616fa6 100644
--- a/example.rb
+++ b/example.rb
@@ -1,3 +1,31 @@
require 'coverage'
+module Coverage
+ module Extension
+ def pause; end
+ def reset; end
+
+ def resume
+ @baseline = peek_result
+ end
+
+ def subtract old, new
+ new.each_pair.with_object({}) do |(k, v), hash|
+ if old.key? k
+ prev_cov = old[k]
+ hash[k] = v.map.with_index { |info, i| info ? info - prev_cov[i] : info }
+ else
+ hash[k] = v.dup
+ end
+ end
+ end
+
+ def result
+ return super unless @baseline
+ subtract @baseline, peek_result
+ end
+ end
+
+ class << self; self; end.prepend Extension
+end
Coverage.start
require './covercheck'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment