Skip to content

Commit

Permalink
Add an HTML generator for SimpleCov
Browse files Browse the repository at this point in the history
It adds a new section to the HTML report: Coverage.

In that section RubyCritic will now list all the application files along with its test coverage information.

This change will be necessary to display the results calculated by Analyser::Coverage and it will help improve the situation for this issue: #245
  • Loading branch information
etagwerker authored and nunosilva800 committed Oct 21, 2019
1 parent 760c281 commit 3efbaa7
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ $(function() {
else if(/smells_index/.test(loc)) {
$('.smells-index-nav').addClass('active');
}
else if(/simple_cov_index/.test(loc)) {
$('.coverage-index-nav').addClass('active');
}
});

var turbulenceData = turbulenceData || [];
Expand Down
17 changes: 8 additions & 9 deletions lib/rubycritic/generators/html/simple_cov_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ class SimpleCovIndex < Base
TEMPLATE = erb_template('simple_cov_index.html.erb')

def initialize(analysed_modules)
@smells = analysed_modules.flat_map(&:smells).uniq
@analysed_module_names = analysed_module_names(analysed_modules)
@show_status = (Config.mode == :default)
@analysed_modules = sorted(filtered(analysed_modules))
set_header_links if Config.compare_branches_mode?
end

Expand All @@ -30,14 +28,15 @@ def render
LAYOUT_TEMPLATE.result(base_binding { index_body })
end

private
def sorted(mods)
mods.sort_by(&:coverage)
end

def analysed_module_names(analysed_modules)
names = {}
analysed_modules.each do |analysed_module|
names[analysed_module.pathname] = analysed_module.name
def filtered(mods)
mods.reject do |a_module|
path = a_module.pathname.to_s
path.start_with?('spec', 'test')
end
names
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<a href="<%= file_path('smells_index.html') %>" class="project-nav-item smells-index-nav"><i class="fa fa-warning"></i>Smells</a>
</li>
<li class="sidebar-item">
<a href="<%= file_path('simple_cov_index.html') %>" class="project-nav-item coverage-index-nav"><i class="fa fa-warning"></i>Coverage</a>
<a href="<%= file_path('simple_cov_index.html') %>" class="project-nav-item coverage-index-nav"><i class="fa fa-umbrella"></i>Coverage</a>
</li>
</ul>
</aside>
Expand Down
37 changes: 17 additions & 20 deletions lib/rubycritic/generators/html/templates/simple_cov_index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,29 @@
<table id="js-index-table" class="table coverage-index-table index-table sortable-table">
<thead>
<tr>
<th width="30%" class="table-header">Smell<span class="sort-type"></span></th>
<th width="65%" class="table-header">Locations<span class="sort-type"></span></th>
<th width="5%" class="table-header">Status<span class="sort-type"></span></th>
<% unless Config.suppress_ratings %>
<th width="10%" class="table-header">Rating<span class="sort-type"></span></th>
<% end %>
<th width="80%" class="table-header">Name<span class="sort-type"></span></th>
<th width="10%" class="table-header">Coverage<span class="sort-type"></span></th>
</tr>
</thead>
<% @smells.each do |smell| %>
<% @analysed_modules.each do |analysed_module| %>
<tr>
<td><%= smell.type %></td>
<td>
<ul class="nav nav-pills">
<% smell.locations.each do |location| %>
<li role="presentation">
<a href="<%= smell_location_path(location) %>"><%= @analysed_module_names[location.pathname] %></a>
</li>
<% end %>
</ul>
</td>
<td>
<% if @show_status %>
<tr>
<% unless Config.suppress_ratings %>
<td>
<div class="rating <%= analysed_module.rating.to_s.downcase %>"><%= analysed_module.coverage_rating %></div>
</td>
<% end %>
<td>
<ul class="nav nav-pills">
<li role="presentation">
<td class="centered-cell"><span class="status-<%= smell.status %> circled-text circle"><%= smell.status %></span></td>
<li role="presentation" >
<a href="<%= file_path(analysed_module.pathname.sub_ext('.html')) %>"><%= analysed_module.name %></a>
</li>
</ul>
<% end %>
</td>
</td>
<td><%= '%g' % analysed_module.coverage %>%</td>
</tr>
<% end %>
</table>
Expand Down
7 changes: 7 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# frozen_string_literal: true

if ENV['COVERAGE'] == 'true'
require 'simplecov'
SimpleCov.start do
track_files '/lib/'
end
end

require 'minitest/autorun'
require 'minitest/around/spec'
require 'minitest/pride'
Expand Down

0 comments on commit 3efbaa7

Please sign in to comment.