Class: MissCleo::CoverageFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/miss_cleo/coverage_filter.rb

Constant Summary collapse

GEM_PATHS =
ENV["GEM_PATH"].split(":")
RUBY_PATH =
`which ruby`.chomp.gsub("/bin/ruby","")

Class Method Summary collapse

Class Method Details

.filter_and_trim(result_hash) ⇒ Object



24
25
26
27
# File 'lib/miss_cleo/coverage_filter.rb', line 24

def self.filter_and_trim(result_hash)
  filtered = filter_core(result_hash)
  normalize_paths(filtered)
end

.filter_core(result_hash) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/miss_cleo/coverage_filter.rb', line 6

def self.filter_core(result_hash)

  # Don't include gems in coverage map
  result_hash.reject do |file, line|
    ([RUBY_PATH] + GEM_PATHS).any? { |path| file.include?(path) }
  end
end

.normalize_paths(result_hash) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/miss_cleo/coverage_filter.rb', line 14

def self.normalize_paths(result_hash)
  normalized_hash = Hash.new
  result_hash.each do |key, value|
    trimmed_key = key.gsub(/#{Regexp.quote(`pwd`.chomp)}/, "")
    normalized_hash[trimmed_key] = value
  end

  normalized_hash
end