Class: SimpleCov::Formatter::HTMLFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/simplecov-html.rb,
lib/simplecov-html/version.rb

Constant Summary collapse

VERSION =
"0.12.3"

Instance Method Summary collapse

Constructor Details

#initializeHTMLFormatter

Returns a new instance of HTMLFormatter.



19
20
21
# File 'lib/simplecov-html.rb', line 19

def initialize
  @branchable_result = SimpleCov.branch_coverage?
end

Instance Method Details

#branchable_result?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
# File 'lib/simplecov-html.rb', line 38

def branchable_result?
  # cached in initialize because we truly look it up a whole bunch of times
  # and it's easier to cache here then in SimpleCov because there we might
  # still enable/disable branch coverage criterion
  @branchable_result
end

#format(result) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/simplecov-html.rb', line 23

def format(result)
  Dir[File.join(File.dirname(__FILE__), "../public/*")].each do |path|
    FileUtils.cp_r(path, asset_output_path)
  end

  File.open(File.join(output_path, "index.html"), "wb") do |file|
    file.puts template("layout").result(binding)
  end
  puts output_message(result)
end

#line_status?(source_file, line) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
51
# File 'lib/simplecov-html.rb', line 45

def line_status?(source_file, line)
  if branchable_result? && source_file.line_with_missed_branch?(line.number)
    "missed-branch"
  else
    line.status
  end
end

#output_message(result) ⇒ Object



34
35
36
# File 'lib/simplecov-html.rb', line 34

def output_message(result)
  "Coverage report generated for #{result.command_name} to #{output_path}. #{result.covered_lines} / #{result.total_lines} LOC (#{result.covered_percent.round(2)}%) covered."
end