Module: Coverage
Relationships & Source Files | |
Defined in: | ext/coverage/coverage.c |
Overview
Coverage
provides coverage measurement feature for Ruby. This feature is experimental, so these APIs may be changed in future.
Usage
-
require “coverage”
-
do .start
-
require or load Ruby source file
-
.result will return a hash that contains filename as key and coverage array as value. A coverage array gives, for each line, the number of line execution by the interpreter. A
nil
value means coverage is disabled for this line (lines likeelse
andend
).
Example
[foo.rb]
s = 0
10.times do |x|
s += x
end
if s == 45
p :ok
else
p :ng
end
[EOF]
require "coverage"
Coverage.start
require "foo.rb"
p Coverage.result #=> {"foo.rb"=>[1, 1, 10, nil, nil, 1, 1, nil, 0, nil]}
Class Method Summary
-
.peek_result ⇒ Hash
mod_func
Returns a hash that contains filename as key and coverage array as value.
-
.result ⇒ Hash
mod_func
Returns a hash that contains filename as key and coverage array as value and disables coverage measurement.
-
.start ⇒ nil
mod_func
Enables coverage measurement.
Class Method Details
.peek_result ⇒ Hash
(mod_func)
Returns a hash that contains filename as key and coverage array as value.
.result ⇒ Hash
(mod_func)
Returns a hash that contains filename as key and coverage array as value and disables coverage measurement.
.start ⇒ nil
(mod_func)
Enables coverage measurement.