Class: SimpleCov::Formatter::ERBFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/simplecov-erb.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.erb_file=(filename) ⇒ Object



17
18
19
# File 'lib/simplecov-erb.rb', line 17

def self.erb_file=(filename)
  @erb_file = filename
end

.output_filename=(filename) ⇒ Object

These come as class methods when configured via a spec_helper or similar.



13
14
15
# File 'lib/simplecov-erb.rb', line 13

def self.output_filename=(filename)
  @output_filename = filename
end

Instance Method Details

#format(result) ⇒ Object

This is the entry point.



7
8
9
10
# File 'lib/simplecov-erb.rb', line 7

def format(result)
  File.open(output_filepath, "wb") { |file| file.puts template.result(binding) }
  puts output_message(result)
end

#missed_lines(source_file) ⇒ Object

This may be called from within an ERB template to get the line numbers with missed coverage.

source_file - A source file object from SimpleCov

Returns an Array of line numbers whose test coverage is "missed".



27
28
29
30
31
32
33
# File 'lib/simplecov-erb.rb', line 27

def missed_lines(source_file)
  result = []
  source_file.lines.each_with_index do |line, index|
    result << (index+1) if line.missed?
  end
  result
end

#shortened_filename(filename) ⇒ Object

This may be called from within an ERB template to get the file name relative to the SimpleCov root.

filename - A String with the full path to the file.

Returns a String with the filename relative to the SimpleCov root.



41
42
43
44
45
46
47
# File 'lib/simplecov-erb.rb', line 41

def shortened_filename(filename)
  if filename.start_with?(SimpleCov.root)
    filename[SimpleCov.root.length..-1]
  else
    filename
  end
end