class SimpleCov::Formatter::ERBFormatter

Public Class Methods

erb_file=(filename) click to toggle source
# File lib/simplecov-erb.rb, line 17
def self.erb_file=(filename)
  @erb_file = filename
end
output_filename=(filename) click to toggle source

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

# File lib/simplecov-erb.rb, line 13
def self.output_filename=(filename)
  @output_filename = filename
end

Private Class Methods

erb_file() click to toggle source

erb_file is a class variable when set via the configuration, but an instance variable when retrieved. Define it both ways here, so the instance variable defers to the class.

# File lib/simplecov-erb.rb, line 62
def self.erb_file
  @erb_file
end
output_filename() click to toggle source

output_filename is a class variable when set via the configuration, but an instance variable when retrieved. Define it both ways here, so the instance variable defers to the class.

# File lib/simplecov-erb.rb, line 72
def self.output_filename
  @output_filename
end

Public Instance Methods

format(result) click to toggle source

This is the entry point.

# 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) click to toggle source

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”.

# 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) click to toggle source

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.

# 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

Private Instance Methods

erb_file() click to toggle source
# File lib/simplecov-erb.rb, line 66
def erb_file
  self.class.erb_file || File.expand_path("../views/simplecov.erb", File.dirname(__FILE__))
end
output_filename() click to toggle source
# File lib/simplecov-erb.rb, line 76
def output_filename
  self.class.output_filename ? File.basename(self.class.output_filename) : "coverage.txt"
end
output_filepath() click to toggle source

Misc. helper methods.

# File lib/simplecov-erb.rb, line 81
def output_filepath
  File.join(output_path, output_filename)
end
output_message(result) click to toggle source
# File lib/simplecov-erb.rb, line 56
def output_message(result)
  "Coverage report generated for #{result.command_name} to #{output_filepath}. #{result.covered_lines} / #{result.total_lines} LOC (#{result.covered_percent.round(2)}%) covered."
end
output_path() click to toggle source
# File lib/simplecov-erb.rb, line 85
def output_path
  SimpleCov.coverage_path
end
template() click to toggle source
# File lib/simplecov-erb.rb, line 51
def template
  # Path, safe_mode, trim_mode
  ERB.new(File.read(erb_file), nil, "-")
end