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.
@@ -3,5 +3,8 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~>4.0.0"
6
+ gem "simplecov", :require => false
7
+ gem "sprockets"
8
+ gem "sass"
6
9
 
7
- gemspec path: "../"
10
+ gemspec :path => "../"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- routes_coverage (0.0.3)
4
+ routes_coverage (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -37,8 +37,10 @@ GEM
37
37
  arel (4.0.2)
38
38
  builder (3.1.4)
39
39
  concurrent-ruby (1.0.5)
40
+ docile (1.1.5)
40
41
  erubis (2.7.0)
41
42
  i18n (0.8.1)
43
+ json (2.0.2)
42
44
  mail (2.6.5)
43
45
  mime-types (>= 1.16, < 4)
44
46
  mime-types (3.1)
@@ -63,6 +65,12 @@ GEM
63
65
  rake (>= 0.8.7)
64
66
  thor (>= 0.18.1, < 2.0)
65
67
  rake (10.5.0)
68
+ sass (3.4.22)
69
+ simplecov (0.14.1)
70
+ docile (~> 1.1.0)
71
+ json (>= 1.8, < 3)
72
+ simplecov-html (~> 0.10.0)
73
+ simplecov-html (0.10.0)
66
74
  sprockets (3.7.1)
67
75
  concurrent-ruby (~> 1.0)
68
76
  rack (> 1, < 3)
@@ -84,6 +92,9 @@ DEPENDENCIES
84
92
  rails (~> 4.0.0)
85
93
  rake (~> 10.0)
86
94
  routes_coverage!
95
+ sass
96
+ simplecov
97
+ sprockets
87
98
 
88
99
  BUNDLED WITH
89
100
  1.14.6
@@ -3,6 +3,9 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~>4.0.0"
6
+ gem "simplecov", :require => false
7
+ gem "sprockets"
8
+ gem "sass"
6
9
  gem "rspec-rails"
7
10
 
8
- gemspec path: "../"
11
+ gemspec :path => "../"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- routes_coverage (0.0.3)
4
+ routes_coverage (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -38,8 +38,10 @@ GEM
38
38
  builder (3.1.4)
39
39
  concurrent-ruby (1.0.5)
40
40
  diff-lcs (1.2.5)
41
+ docile (1.1.5)
41
42
  erubis (2.7.0)
42
43
  i18n (0.8.1)
44
+ json (2.0.2)
43
45
  mail (2.6.5)
44
46
  mime-types (>= 1.16, < 4)
45
47
  mime-types (3.1)
@@ -81,6 +83,12 @@ GEM
81
83
  rspec-mocks (~> 3.5.0)
82
84
  rspec-support (~> 3.5.0)
83
85
  rspec-support (3.5.0)
86
+ sass (3.4.22)
87
+ simplecov (0.14.1)
88
+ docile (~> 1.1.0)
89
+ json (>= 1.8, < 3)
90
+ simplecov-html (~> 0.10.0)
91
+ simplecov-html (0.10.0)
84
92
  sprockets (3.7.1)
85
93
  concurrent-ruby (~> 1.0)
86
94
  rack (> 1, < 3)
@@ -103,6 +111,9 @@ DEPENDENCIES
103
111
  rake (~> 10.0)
104
112
  routes_coverage!
105
113
  rspec-rails
114
+ sass
115
+ simplecov
116
+ sprockets
106
117
 
107
118
  BUNDLED WITH
108
119
  1.14.6
@@ -4,5 +4,7 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~>4.0.0"
6
6
  gem "simplecov"
7
+ gem "sprockets"
8
+ gem "sass"
7
9
 
8
- gemspec path: "../"
10
+ gemspec :path => "../"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- routes_coverage (0.0.3)
4
+ routes_coverage (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -65,6 +65,7 @@ GEM
65
65
  rake (>= 0.8.7)
66
66
  thor (>= 0.18.1, < 2.0)
67
67
  rake (10.5.0)
68
+ sass (3.4.22)
68
69
  simplecov (0.14.1)
69
70
  docile (~> 1.1.0)
70
71
  json (>= 1.8, < 3)
@@ -91,7 +92,9 @@ DEPENDENCIES
91
92
  rails (~> 4.0.0)
92
93
  rake (~> 10.0)
93
94
  routes_coverage!
95
+ sass
94
96
  simplecov
97
+ sprockets
95
98
 
96
99
  BUNDLED WITH
97
100
  1.14.6
@@ -3,5 +3,8 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~>4.2.0"
6
+ gem "simplecov", :require => false
7
+ gem "sprockets"
8
+ gem "sass"
6
9
 
7
- gemspec path: "../"
10
+ gemspec :path => "../"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- routes_coverage (0.0.3)
4
+ routes_coverage (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -48,6 +48,7 @@ GEM
48
48
  arel (6.0.3)
49
49
  builder (3.2.3)
50
50
  concurrent-ruby (1.0.5)
51
+ docile (1.1.5)
51
52
  erubis (2.7.0)
52
53
  globalid (0.3.7)
53
54
  activesupport (>= 4.1.0)
@@ -92,6 +93,12 @@ GEM
92
93
  rake (>= 0.8.7)
93
94
  thor (>= 0.18.1, < 2.0)
94
95
  rake (10.5.0)
96
+ sass (3.4.22)
97
+ simplecov (0.14.1)
98
+ docile (~> 1.1.0)
99
+ json (>= 1.8, < 3)
100
+ simplecov-html (~> 0.10.0)
101
+ simplecov-html (0.10.0)
95
102
  sprockets (3.7.1)
96
103
  concurrent-ruby (~> 1.0)
97
104
  rack (> 1, < 3)
@@ -114,6 +121,9 @@ DEPENDENCIES
114
121
  rails (~> 4.2.0)
115
122
  rake (~> 10.0)
116
123
  routes_coverage!
124
+ sass
125
+ simplecov
126
+ sprockets
117
127
 
118
128
  BUNDLED WITH
119
129
  1.14.6
@@ -3,5 +3,8 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~>5.0.0"
6
+ gem "simplecov", :require => false
7
+ gem "sprockets"
8
+ gem "sass"
6
9
 
7
- gemspec path: "../"
10
+ gemspec :path => "../"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- routes_coverage (0.0.3)
4
+ routes_coverage (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -50,10 +50,12 @@ GEM
50
50
  arel (7.1.4)
51
51
  builder (3.2.3)
52
52
  concurrent-ruby (1.0.5)
53
+ docile (1.1.5)
53
54
  erubis (2.7.0)
54
55
  globalid (0.4.0)
55
56
  activesupport (>= 4.2.0)
56
57
  i18n (0.8.1)
58
+ json (2.0.2)
57
59
  loofah (2.0.3)
58
60
  nokogiri (>= 1.5.9)
59
61
  mail (2.6.5)
@@ -94,6 +96,12 @@ GEM
94
96
  rake (>= 0.8.7)
95
97
  thor (>= 0.18.1, < 2.0)
96
98
  rake (10.5.0)
99
+ sass (3.4.22)
100
+ simplecov (0.14.1)
101
+ docile (~> 1.1.0)
102
+ json (>= 1.8, < 3)
103
+ simplecov-html (~> 0.10.0)
104
+ simplecov-html (0.10.0)
97
105
  sprockets (3.7.1)
98
106
  concurrent-ruby (~> 1.0)
99
107
  rack (> 1, < 3)
@@ -119,6 +127,9 @@ DEPENDENCIES
119
127
  rails (~> 5.0.0)
120
128
  rake (~> 10.0)
121
129
  routes_coverage!
130
+ sass
131
+ simplecov
132
+ sprockets
122
133
 
123
134
  BUNDLED WITH
124
135
  1.14.6
@@ -3,5 +3,8 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~>5.1.0"
6
+ gem "simplecov", :require => false
7
+ gem "sprockets"
8
+ gem "sass"
6
9
 
7
- gemspec path: "../"
10
+ gemspec :path => "../"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- routes_coverage (0.0.3)
4
+ routes_coverage (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -50,10 +50,12 @@ GEM
50
50
  arel (8.0.0)
51
51
  builder (3.2.3)
52
52
  concurrent-ruby (1.0.5)
53
+ docile (1.1.5)
53
54
  erubi (1.6.0)
54
55
  globalid (0.4.0)
55
56
  activesupport (>= 4.2.0)
56
57
  i18n (0.8.1)
58
+ json (2.0.2)
57
59
  loofah (2.0.3)
58
60
  nokogiri (>= 1.5.9)
59
61
  mail (2.6.5)
@@ -94,6 +96,12 @@ GEM
94
96
  rake (>= 0.8.7)
95
97
  thor (>= 0.18.1, < 2.0)
96
98
  rake (10.5.0)
99
+ sass (3.4.22)
100
+ simplecov (0.14.1)
101
+ docile (~> 1.1.0)
102
+ json (>= 1.8, < 3)
103
+ simplecov-html (~> 0.10.0)
104
+ simplecov-html (0.10.0)
97
105
  sprockets (3.7.1)
98
106
  concurrent-ruby (~> 1.0)
99
107
  rack (> 1, < 3)
@@ -119,6 +127,9 @@ DEPENDENCIES
119
127
  rails (~> 5.1.0)
120
128
  rake (~> 10.0)
121
129
  routes_coverage!
130
+ sass
131
+ simplecov
132
+ sprockets
122
133
 
123
134
  BUNDLED WITH
124
135
  1.14.6
@@ -3,9 +3,7 @@ module RoutesCoverage
3
3
  class AtExit
4
4
  def self.use coverer=nil
5
5
  #NB: at_exit order is important, for example minitest uses it to run, need to install our handler before it
6
- # also this may interfere with simplecov, need to use SimpleCov.at_exit do...end if defined
7
6
 
8
- # puts "Using at_exit, note this may be interfered by simplecov etc."
9
7
  RoutesCoverage.reset!
10
8
  at_exit do
11
9
  next if RoutesCoverage.pid != Process.pid
@@ -0,0 +1,116 @@
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 Html < Base
10
+ def format
11
+ routes_filename = "routes.html"
12
+
13
+ File.open(File.join(output_path, routes_filename), "wb") do |file|
14
+ file.puts template("layout").result(binding)
15
+ end
16
+
17
+ "Routes coverage is #{result.coverage}% Report generated to #{output_path}/#{routes_filename}"
18
+ end
19
+
20
+ private
21
+
22
+ def template(name)
23
+ ERB.new(File.read(File.join(File.dirname(__FILE__), "html_views", "#{name}.erb")))
24
+ end
25
+
26
+
27
+ def root(root = nil)
28
+ #TODO: config for this
29
+ return SimpleCov.root if defined? SimpleCov
30
+ return @root if defined?(@root) && root.nil?
31
+ @root = File.expand_path(root || Dir.getwd)
32
+ end
33
+
34
+ def coverage_dir(dir = nil)
35
+ #TODO: config for this
36
+ return SimpleCov.coverage_dir if defined? SimpleCov
37
+ return @coverage_dir if defined?(@coverage_dir) && dir.nil?
38
+ @coverage_path = nil # invalidate cache
39
+ @coverage_dir = (dir || "coverage")
40
+ end
41
+
42
+ def output_path
43
+ @coverage_path ||= File.expand_path(coverage_dir, root).tap do |path|
44
+ FileUtils.mkdir_p path
45
+ end
46
+ end
47
+
48
+ def project_name
49
+ return SimpleCov.project_name if defined? SimpleCov
50
+
51
+ @project_name ||= File.basename(root.split("/").last).capitalize.tr("_", " ")
52
+ end
53
+
54
+ def asset_content name
55
+ File.read(File.expand_path("../../../compiled_assets/#{name}", File.dirname(__FILE__)))
56
+ end
57
+
58
+ def style_asset_link
59
+ "<style>\n#{asset_content 'routes.css'}</style>"
60
+ end
61
+
62
+ def route_group_result(title_id, title, result)
63
+ template("route_group").result(binding)
64
+ end
65
+
66
+ def coverage_css_class(covered_percent)
67
+ if covered_percent > 90
68
+ "green"
69
+ elsif covered_percent > 80
70
+ "yellow"
71
+ else
72
+ "red"
73
+ end
74
+ end
75
+
76
+ def strength_css_class(covered_strength)
77
+ if covered_strength > 1
78
+ "green"
79
+ elsif covered_strength == 1
80
+ "yellow"
81
+ else
82
+ "red"
83
+ end
84
+ end
85
+
86
+ def hits_css_class hits
87
+ hits > 0 ? 'green' : 'red'
88
+ end
89
+
90
+ def timeago(time)
91
+ "<abbr class=\"timeago\" title=\"#{time.iso8601}\">#{time.iso8601}</abbr>"
92
+ end
93
+
94
+
95
+ def all_result_groups
96
+ return @all_result_groups if @all_result_groups
97
+ @all_result_groups = [
98
+ {
99
+ id: 'all_routes',
100
+ name: 'All Routes',
101
+ result: result,
102
+ }
103
+ ]
104
+ @all_result_groups += groups.map do |group_name, group_result|
105
+ {
106
+ id: group_name.gsub(/^[^a-zA-Z]+/, "").gsub(/[^a-zA-Z0-9\-\_]/, ""),
107
+ name: group_name,
108
+ result: group_result,
109
+ }
110
+ end
111
+
112
+ @all_result_groups
113
+ end
114
+ end
115
+ end
116
+ end
@@ -1,30 +1,9 @@
1
1
  <!DOCTYPE html>
2
2
  <html xmlns='http://www.w3.org/1999/xhtml'>
3
3
  <head>
4
- <title>Code coverage for <%= SimpleCov.project_name %></title>
4
+ <title>Routes coverage for <%= project_name %></title>
5
5
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
6
- <script src='<%= assets_path('application.js') %>' type='text/javascript'></script>
7
- <link href='<%= assets_path('application.css') %>' media='screen, projection, print' rel='stylesheet' type='text/css'>
8
- <link rel="shortcut icon" type="image/png" href="<%= assets_path("favicon_#{coverage_css_class(result.coverage)}.png") %>" />
9
- <link rel="icon" type="image/png" href="<%= assets_path('favicon.png') %>" />
10
-
11
- <script>
12
- $(document).ready(function() {
13
- $('.route_list').dataTable({
14
- "aaSorting": [], //[[ 1, "asc" ]],
15
- "bPaginate": false,
16
- "bJQueryUI": true,
17
- "aoColumns": [
18
- null, //name
19
- null, //verb
20
- null, //path
21
- null, //action
22
- null, //covered yes/no
23
- null, //hits count
24
- ]
25
- });
26
- });
27
- </script>
6
+ <%= style_asset_link %>
28
7
  </head>
29
8
 
30
9
  <body>
@@ -33,21 +12,31 @@
33
12
  </div>
34
13
  <div id="wrapper" style="display:none;">
35
14
  <div class="timestamp">Generated <%= timeago(Time.now) %></div>
36
- <ul class="group_tabs"></ul>
15
+ <ul class="group_tabs">
16
+ <% all_result_groups.each do |grp| %>
17
+ <li>
18
+ <a href="#<%= grp[:id] %>" class="<%= grp[:id] %>">
19
+ <%= grp[:name] %>
20
+ (<span class="<%= coverage_css_class(grp[:result].coverage.to_f) %>"><%= result.coverage %>%</span>)
21
+ </a>
22
+ </li>
23
+ <% end %>
24
+ </ul>
37
25
 
38
26
  <div id="content">
39
- <%= route_group_result("All Routes", result) %>
40
-
41
- <% groups.each do |name, group_result| %>
42
- <%= route_group_result(name, group_result) %>
27
+ <% all_result_groups.each do |grp| %>
28
+ <%= route_group_result(grp[:id], grp[:name], grp[:result]) %>
43
29
  <% end %>
44
30
  </div>
45
31
 
46
32
  <div id="footer">
47
33
  Generated by <a href="http://github.com/Vasfed/routes_coverage">routes_coverage</a> v<%= RoutesCoverage::VERSION %>
48
- and simplecov-html v<%= SimpleCov::Formatter::HTMLFormatter::VERSION %><br/>
49
34
  </div>
50
35
 
51
36
  </div>
52
37
  </body>
38
+
39
+ <script>
40
+ <%= asset_content 'routes.js' %>
41
+ </script>
53
42
  </html>