Module: DeepCover::CoverageReplacement
- Defined in:
- lib/deep_cover/core_ext/coverage_replacement.rb
Constant Summary collapse
- OLD_COVERAGE_SENTINEL =
Object.new
- ALL_COVERAGES =
{lines: true, branches: true, methods: true}.freeze
Class Method Summary collapse
- .peek_result ⇒ Object
- .result ⇒ Object
- .running? ⇒ Boolean
- .start(targets = OLD_COVERAGE_SENTINEL) ⇒ Object
Class Method Details
.peek_result ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/deep_cover/core_ext/coverage_replacement.rb', line 43 def peek_result raise 'coverage measurement is not enabled' unless running? if @started_args == OLD_COVERAGE_SENTINEL DeepCover.coverage.covered_codes.map do |covered_code| [covered_code.path.to_s, covered_code.line_coverage(allow_partial: false)] end.to_h else DeepCover.coverage.covered_codes.map do |covered_code| cov = {} cov[:branches] = DeepCover::Analyser::Ruby25LikeBranch.new(covered_code).results if @started_args[:branches] cov[:lines] = covered_code.line_coverage(allow_partial: false) if @started_args[:lines] cov[:methods] = {} if @started_args[:methods] [covered_code.path.to_s, cov] end.to_h end end |
.result ⇒ Object
37 38 39 40 41 |
# File 'lib/deep_cover/core_ext/coverage_replacement.rb', line 37 def result r = peek_result DeepCover.stop r end |
.running? ⇒ Boolean
11 12 13 |
# File 'lib/deep_cover/core_ext/coverage_replacement.rb', line 11 def running? DeepCover.running? end |
.start(targets = OLD_COVERAGE_SENTINEL) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/deep_cover/core_ext/coverage_replacement.rb', line 15 def start(targets = OLD_COVERAGE_SENTINEL) if targets == OLD_COVERAGE_SENTINEL # Do nothing elsif targets == :all targets = ALL_COVERAGES else targets = targets.to_hash.slice(*ALL_COVERAGES.keys).select { |_, v| v } targets = targets.map { |k, v| [k, !!v] }.to_h raise 'no measuring target is specified' if targets.empty? end if DeepCover.running? raise 'cannot change the measuring target during coverage measurement' if @started_args != targets return end @started_args = targets DeepCover.start nil end |