routes_coverage 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,6 +9,7 @@
9
9
  </span>
10
10
  </span> hits/route)
11
11
  </h2>
12
+
12
13
  <a name="<%= title_id %>"></a>
13
14
  <div>
14
15
  <b><%= result.total_count %></b> routes in total.
@@ -16,9 +17,11 @@
16
17
  <span class="green"><b><%= result.hit_routes_count %></b> covered</span> and
17
18
  <span class="red"><b><%= result.pending_routes.size %></b> missed </span>
18
19
  </div>
20
+
19
21
  <table class="route_list">
20
22
  <thead>
21
23
  <tr>
24
+ <%# NB: columns are also referenced from datatables config in js %>
22
25
  <th>Name</th>
23
26
  <th>Verb</th>
24
27
  <th>Path</th>
@@ -1,3 +1,3 @@
1
1
  module RoutesCoverage
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -5,7 +5,7 @@ require "routes_coverage/middleware"
5
5
  require "routes_coverage/formatters/base"
6
6
  require "routes_coverage/formatters/summary_text"
7
7
  require "routes_coverage/formatters/full_text"
8
- require "routes_coverage/formatters/simplecov_html"
8
+ require "routes_coverage/formatters/html"
9
9
 
10
10
  module RoutesCoverage
11
11
  class Railtie < ::Rails::Railtie
@@ -33,7 +33,7 @@ module RoutesCoverage
33
33
  @exclude_namespaces = []
34
34
  @minimum_coverage = 1
35
35
  @round_precision = 1
36
- @format = :summary_text
36
+ @format = :html
37
37
  @groups = {}
38
38
  end
39
39
 
@@ -43,8 +43,8 @@ module RoutesCoverage
43
43
  Formatters::FullText
44
44
  when :summary_text
45
45
  Formatters::SummaryText
46
- when :simplecov_html
47
- Formatters::SimpleCovHtml
46
+ when :html, :simplecov_html
47
+ Formatters::Html
48
48
  when Formatters::Base
49
49
  format
50
50
  else
@@ -97,7 +97,21 @@ module RoutesCoverage
97
97
  ]
98
98
  }]
99
99
 
100
- #TODO: group 'ungroupped'
100
+ if groups.size > 1
101
+ ungroupped_routes = all_routes.reject{|r|
102
+ groups.values.any?{|group_routes|
103
+ group_routes.all_routes.include? r
104
+ }
105
+ }
106
+
107
+ if ungroupped_routes.any?
108
+ groups["Ungroupped"] = Result.new(
109
+ ungroupped_routes,
110
+ Hash[@@route_hit_count.select{|r,_hits| ungroupped_routes.include? r}],
111
+ settings
112
+ )
113
+ end
114
+ end
101
115
 
102
116
  puts
103
117
  puts settings.formatter_class.new(all_result, groups, settings).format
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: routes_coverage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasily Fedoseyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-14 00:00:00.000000000 Z
11
+ date: 2017-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -83,6 +83,8 @@ files:
83
83
  - Rakefile
84
84
  - bin/console
85
85
  - bin/setup
86
+ - compiled_assets/routes.css
87
+ - compiled_assets/routes.js
86
88
  - gemfiles/.bundle/config
87
89
  - gemfiles/rails_40.gemfile
88
90
  - gemfiles/rails_40.gemfile.lock
@@ -102,9 +104,9 @@ files:
102
104
  - lib/routes_coverage/adapters/simplecov.rb
103
105
  - lib/routes_coverage/formatters/base.rb
104
106
  - lib/routes_coverage/formatters/full_text.rb
107
+ - lib/routes_coverage/formatters/html.rb
105
108
  - lib/routes_coverage/formatters/html_views/layout.erb
106
109
  - lib/routes_coverage/formatters/html_views/route_group.erb
107
- - lib/routes_coverage/formatters/simplecov_html.rb
108
110
  - lib/routes_coverage/formatters/summary_text.rb
109
111
  - lib/routes_coverage/middleware.rb
110
112
  - lib/routes_coverage/result.rb
@@ -1,97 +0,0 @@
1
- require "erb"
2
- require "cgi"
3
- require "fileutils"
4
- require "digest/sha1"
5
- require "time"
6
-
7
- module RoutesCoverage
8
- module Formatters
9
- class SimpleCovHtml < Base
10
- def format
11
- #TODO: copy assets, if simplecov does not generate a report along us
12
-
13
- # Dir[File.join(File.dirname(__FILE__), "../public/*")].each do |path|
14
- # FileUtils.cp_r(path, asset_output_path)
15
- # end
16
-
17
- routes_filename = "routes.html"
18
-
19
- File.open(File.join(output_path, routes_filename), "wb") do |file|
20
- file.puts template("layout").result(binding)
21
- end
22
-
23
- "Routes coverage is #{result.coverage}% Report generated to #{output_path}/#{routes_filename}"
24
- end
25
-
26
- private
27
-
28
- def template(name)
29
- ERB.new(File.read(File.join(File.dirname(__FILE__), "html_views", "#{name}.erb")))
30
- end
31
-
32
- def output_path
33
- SimpleCov.coverage_path
34
- end
35
-
36
- def asset_output_path
37
- return @asset_output_path if defined?(@asset_output_path) && @asset_output_path
38
- @asset_output_path = File.join(output_path, "assets", SimpleCov::Formatter::HTMLFormatter::VERSION)
39
- FileUtils.mkdir_p(@asset_output_path)
40
- @asset_output_path
41
- end
42
-
43
- def assets_path(name)
44
- File.join("./assets", SimpleCov::Formatter::HTMLFormatter::VERSION, name)
45
- end
46
-
47
- # Returns the html for the given source_file
48
- def formatted_source_file(source_file)
49
- template("source_file").result(binding)
50
- end
51
-
52
- # Returns a table containing the given source files
53
- def route_group_result(title, result)
54
- title_id = title.gsub(/^[^a-zA-Z]+/, "").gsub(/[^a-zA-Z0-9\-\_]/, "")
55
- # Silence a warning by using the following variable to assign to itself:
56
- # "warning: possibly useless use of a variable in void context"
57
- # The variable is used by ERB via binding.
58
- title_id = title_id
59
- template("route_group").result(binding)
60
- end
61
-
62
- def coverage_css_class(covered_percent)
63
- if covered_percent > 90
64
- "green"
65
- elsif covered_percent > 80
66
- "yellow"
67
- else
68
- "red"
69
- end
70
- end
71
-
72
- def strength_css_class(covered_strength)
73
- if covered_strength > 1
74
- "green"
75
- elsif covered_strength == 1
76
- "yellow"
77
- else
78
- "red"
79
- end
80
- end
81
-
82
- def hits_css_class hits
83
- hits > 0 ? 'green' : 'red'
84
- end
85
-
86
- # Return a (kind of) unique id for the source file given. Uses SHA1 on path for the id
87
- def id(source_file)
88
- Digest::SHA1.hexdigest(source_file.filename)
89
- end
90
-
91
- def timeago(time)
92
- "<abbr class=\"timeago\" title=\"#{time.iso8601}\">#{time.iso8601}</abbr>"
93
- end
94
-
95
- end
96
- end
97
- end