Class: Covered::Capture
Overview
Captures Ruby coverage data and forwards it to another coverage output.
Constant Summary collapse
- EVAL_PATHS =
{ "(eval)" => true, "(irb)" => true, "eval" => true }
Instance Attribute Summary
Attributes inherited from Wrapper
Instance Method Summary collapse
-
#clear ⇒ Object
Clear any collected coverage data without stopping coverage.
-
#execute(source, binding: TOPLEVEL_BINDING) ⇒ Object
Execute the given source while capturing coverage for it.
-
#finish ⇒ Object
Stop coverage collection and add the collected results to the output.
-
#start ⇒ Object
Start Ruby coverage collection.
Methods inherited from Wrapper
#accept?, #add, #each, #expand_path, #initialize, #mark, #relative_path, #to_h
Methods inherited from Base
#accept?, #add, #each, #expand_path, #mark, #relative_path
Constructor Details
This class inherits a constructor from Covered::Wrapper
Instance Method Details
#clear ⇒ Object
Clear any collected coverage data without stopping coverage.
21 22 23 24 25 |
# File 'lib/covered/capture.rb', line 21 def clear super ::Coverage.result(stop: false, clear: true) end |
#execute(source, binding: TOPLEVEL_BINDING) ⇒ Object
Execute the given source while capturing coverage for it.
59 60 61 62 63 64 65 |
# File 'lib/covered/capture.rb', line 59 def execute(source, binding: TOPLEVEL_BINDING) start eval(source.code!, binding, source.path, source.line_offset) ensure finish end |
#finish ⇒ Object
Stop coverage collection and add the collected results to the output. Ignores Ruby’s anonymous eval paths and files that no longer exist.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/covered/capture.rb', line 35 def finish results = ::Coverage.result results.each do |path, result| next if EVAL_PATHS.include?(path) path = self.(path) # Skip files which don't exist. This can happen if `eval` is used with an invalid/incorrect path: if File.exist?(path) @output.mark(path, 1, result[:lines]) else # warn "Skipping coverage for #{path.inspect} because it doesn't exist!" # Ignore. end end super end |
#start ⇒ Object
Start Ruby coverage collection.
14 15 16 17 18 |
# File 'lib/covered/capture.rb', line 14 def start super ::Coverage.start(lines: true, eval: true) end |