Class: SimpleCov::Formatter::MaterialFormatter

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

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

VERSION =
"1.0.0"

Instance Method Summary collapse

Constructor Details

#initializeMaterialFormatter

Returns a new instance of MaterialFormatter.



18
19
20
# File 'lib/simplecov-material.rb', line 18

def initialize
  @branchable_result = SimpleCov.branch_coverage?
end

Instance Method Details

#branchable_result?Boolean

Returns:

  • (Boolean)


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

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

rubocop:disable Metrics/AbcSize



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

def format(result) # rubocop:disable Metrics/AbcSize
  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("main").result(binding)
  end
  puts output_message(result)
end

#line_status?(source_file, line) ⇒ Boolean

Returns:

  • (Boolean)


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

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



33
34
35
36
37
# File 'lib/simplecov-material.rb', line 33

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