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 @@ -
+

<%= title %> ( @@ -13,7 +13,7 @@ )

- +
<%= source_files.length %> files in total. @@ -26,7 +26,7 @@ (<%= covered_percent(source_files.covered_percent) %>)
- <% if branchable_result? %> + <% if branch_coverage? %>
<%= source_files.total_branches %> total branches, <%= source_files.covered_branches %> branches covered and @@ -35,6 +35,15 @@
<% end %> + <% if method_coverage? %> +
+ <%= source_files.total_methods %> total methods, + <%= source_files.covered_methods %> methods covered and + <%= source_files.missed_methods %> methods missed. + (<%= covered_percent(source_files.method_covered_percent) %>) +
+ <% end %> +
@@ -46,12 +55,18 @@ - <% if branchable_result? %> + <% if branch_coverage? %> <% end %> + <% if method_coverage? %> + + + + + <% end %> @@ -64,12 +79,18 @@ - <% if branchable_result? %> + <% if branch_coverage? %> <% end %> + <% if method_coverage? %> + + + + + <% end %> <% end %> diff --git a/views/layout.erb b/views/layout.erb index 72c60af..2c77744 100644 --- a/views/layout.erb +++ b/views/layout.erb @@ -8,7 +8,7 @@ " /> - > + >
loading
diff --git a/views/source_file.erb b/views/source_file.erb index a8f753b..ab288d5 100644 --- a/views/source_file.erb +++ b/views/source_file.erb @@ -6,20 +6,28 @@ lines covered - <% if branchable_result? %> + <% if branch_coverage? %>

<%= covered_percent(source_file.branches_coverage_percent) %> branches covered

<% end %> + <% if method_coverage? %> +

+ <%= covered_percent(source_file.methods_coverage_percent) %> + methods covered +

+ <% end %> + +
<%= source_file.lines_of_code %> relevant lines. <%= source_file.covered_lines.count %> lines covered and <%= source_file.missed_lines.count %> lines missed.
- <% if branchable_result? %> + <% if branch_coverage? %>
<%= source_file.total_branches.count %> total branches, <%= source_file.covered_branches.count %> branches covered and @@ -27,6 +35,25 @@
<% end %> + <% if method_coverage? %> +
+ <%= source_file.total_methods.count %> total methods, + <%= source_file.covered_methods.count %> methods covered and + <%= source_file.missed_methods.count %> methods missed. +
+ <% end %> + + <% if method_coverage? && source_file.missed_methods.any? %> +
+ Missed methods: +
    + <% source_file.missed_methods.each do |missed_method| %> +
  • <%= CGI.escapeHTML(missed_method.to_s) %>
  • + <% end %> +
+
+ <% end %> +
@@ -40,7 +67,7 @@
               skipped
             <% end %>
 
-            <% if branchable_result? %>
+            <% if branch_coverage? %>
               <% source_file.branches_for_line(line.number).each do |branch_type, hit_count| %>
                 
                   <%= branch_type %>: <%= hit_count %>
Lines covered Lines missed Avg. Hits / LineBranch Coverage Branches Covered branches Missed branches Method CoverageMethodsCovered methodsMissed methods
<%= source_file.covered_lines.count %> <%= source_file.missed_lines.count %> <%= sprintf("%.2f", source_file.covered_strength.round(2)) %><%= sprintf("%.2f", source_file.branches_coverage_percent.round(2)) %> % <%= source_file.total_branches.count %> <%= source_file.covered_branches.count %> <%= source_file.missed_branches.count %><%= sprintf("%.2f", source_file.methods_coverage_percent.round(2)) %> %<%= source_file.total_methods.count %><%= source_file.covered_methods.count %><%= source_file.missed_methods.count %>