diff --git a/assets/stylesheets/application.css b/assets/stylesheets/application.css
index 0858ab1..4f33644 100644
--- a/assets/stylesheets/application.css
+++ b/assets/stylesheets/application.css
@@ -1,3 +1,3 @@
//= require ./reset.css
//= require_directory ./plugins/
-//= require ./screen.css
\ No newline at end of file
+//= require ./screen.css
diff --git a/assets/stylesheets/screen.css b/assets/stylesheets/screen.css
index 0fa22bd..917075c 100644
--- a/assets/stylesheets/screen.css
+++ b/assets/stylesheets/screen.css
@@ -341,3 +341,8 @@ thead th {
.source_table .missed-branch:nth-child(even) {
background-color: #cc6e6e;
}
+
+.t-missed-method-summary ul {
+ margin: 0;
+ padding-left: 2em;
+}
diff --git a/lib/simplecov-html.rb b/lib/simplecov-html.rb
index cd07425..18bebdd 100644
--- a/lib/simplecov-html.rb
+++ b/lib/simplecov-html.rb
@@ -24,7 +24,8 @@ class HTMLFormatter
}.freeze
def initialize
- @branchable_result = SimpleCov.branch_coverage?
+ @branch_coverage = SimpleCov.branch_coverage?
+ @method_coverage = SimpleCov.method_coverage?
@templates = {}
@inline_assets = !ENV["SIMPLECOV_INLINE_ASSETS"].nil?
@public_assets_dir = File.join(File.dirname(__FILE__), "../public/")
@@ -45,15 +46,22 @@ def format(result)
private
- def branchable_result?
+ def branch_coverage?
# 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
+ @branch_coverage
+ end
+
+ def method_coverage?
+ # 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
+ @method_coverage
end
def line_status?(source_file, line)
- if branchable_result? && source_file.line_with_missed_branch?(line.number)
+ if branch_coverage? && source_file.line_with_missed_branch?(line.number)
"missed-branch"
else
line.status
@@ -61,10 +69,13 @@ def line_status?(source_file, line)
end
def output_message(result)
- output = "Coverage report generated for #{result.command_name} to #{output_path}."
- output += "\nLine Coverage: #{result.covered_percent.round(2)}% (#{result.covered_lines} / #{result.total_lines})"
- output += "\nBranch Coverage: #{result.coverage_statistics[:branch].percent.round(2)}% (#{result.covered_branches} / #{result.total_branches})" if branchable_result?
- output
+ parts = []
+ parts << "Coverage report generated for #{result.command_name} to #{output_path}"
+ parts << "Line coverage: #{render_stats(result, :line)}"
+ parts << "Branch coverage: #{render_stats(result, :branch)}" if branch_coverage?
+ parts << "Method coverage: #{render_stats(result, :method)}" if method_coverage?
+
+ parts.join("\n")
end
# Returns the an erb instance for the template of given name
@@ -90,6 +101,10 @@ def assets_path(name)
File.join("./assets", SimpleCov::Formatter::HTMLFormatter::VERSION, name)
end
+ def to_id(value)
+ value.gsub(/^[^a-zA-Z]+/, "").gsub(/[^a-zA-Z0-9\-_]/, "")
+ end
+
def asset_inline(name)
path = File.join(@public_assets_dir, name)
# Equivalent to `Base64.strict_encode64(File.read(path))` but without depending on Base64
@@ -109,11 +124,6 @@ def formatted_source_file(source_file)
# Returns a table containing the given source files
def formatted_file_list(title, source_files)
- title_id = title.gsub(/^[^a-zA-Z]+/, "").gsub(/[^a-zA-Z0-9\-_]/, "")
- # Silence a warning by using the following variable to assign to itself:
- # "warning: possibly useless use of a variable in void context"
- # The variable is used by ERB via binding.
- title_id = title_id # rubocop:disable Lint/SelfAssignment
template("file_list").result(binding)
end
@@ -157,6 +167,17 @@ def shortened_filename(source_file)
def link_to_source_file(source_file)
%(#{shortened_filename source_file})
end
+
+ def render_stats(result, criterion)
+ stats = result.coverage_statistics.fetch(criterion)
+
+ Kernel.format(
+ "%d / %d (%.2f%%)",
+ covered: stats.covered,
+ total: stats.total,
+ percent: stats.percent
+ )
+ end
end
end
end
diff --git a/views/file_list.erb b/views/file_list.erb
index 0cd97b6..e8f362f 100644
--- a/views/file_list.erb
+++ b/views/file_list.erb
@@ -1,4 +1,4 @@
-