Module: Coverage
- Defined in:
- lib/tracepoint/coverage.rb
Overview
This is backport of Ruby 1.9’s Coverage library that can be used with Ruby 1.8 or older. It is not a 100% perfect drop-in, but in comes close.
This biggest issue with it at this point is that it cannot exclude coverage of irrelevant files b/c $LOADED_FEATURES in Ruby 1.8 does not use absolute paths. Not sure how to work around this yet.
Class Method Summary collapse
Class Method Details
.reset ⇒ Object
40 41 42 43 |
# File 'lib/tracepoint/coverage.rb', line 40 def self.reset @ignore = $LOADED_FEATURES.dup @result = Hash.new{ |h,k| h[k]=[] } end |
.result ⇒ Object
35 36 37 |
# File 'lib/tracepoint/coverage.rb', line 35 def self.result @result end |
.start ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/tracepoint/coverage.rb', line 14 def self.start reset ignore = @ignore result = @result TracePoint.trace do |tp| case tp.event when 'line', 'class', 'end' unless ignore.include?(tp.file) file = File.(tp.file) result[file][tp.line-1] ||= 0 result[file][tp.line-1] += 1 end end end TracePoint.activate end |
.stop ⇒ Object
46 47 48 |
# File 'lib/tracepoint/coverage.rb', line 46 def self.stop TracePoint.deactivate end |