simplecov_url 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +39 -0
- data/Rakefile +7 -0
- data/app/controllers/simplecov_url/simplecov_controller.rb +9 -0
- data/config/routes.rb +5 -0
- data/lib/simplecov_url/access_manager.rb +15 -0
- data/lib/simplecov_url/html_processor.rb +142 -0
- data/lib/simplecov_url/version.rb +5 -0
- data/lib/simplecov_url.rb +8 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: feb5bd2e7ed75132e515c37a69f9b26a543a638798486baad001863bb753d283
|
4
|
+
data.tar.gz: 5800d99260b78ee1b76d4f8dd35925808a73538bc91961ceac4bec6cf4601327
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 80567bf947749bc99cdb3b48d03c99f96db0c11ceeafe8db6b5a9802d1b1b5e2e69c5056c2094621910a846c54a2e103db33e43cf342c3358c6002872fd91c95
|
7
|
+
data.tar.gz: a0a5e21b6a3e99b0db8d535ed76239c2ba6e7f765e81b90e40efeb4547e4e7034f12b1d3b316bfabacf8c7f842fce4cd24b2eaebdb33236ff1ada8ec4b707463
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2019 Evgeni Radev
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# SimplecovUrl
|
2
|
+
|
3
|
+
The gem publishes Simplecov's test coverage reports to your_url/simplecov.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```
|
10
|
+
gem 'simplecov_url', '~> 1.0'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
## Dependencies
|
20
|
+
|
21
|
+
```
|
22
|
+
gem 'rails', '~> 5.2.3'
|
23
|
+
```
|
24
|
+
|
25
|
+
```
|
26
|
+
gem 'simplecov', '~> 0.16.1'
|
27
|
+
```
|
28
|
+
|
29
|
+
```
|
30
|
+
gem 'simplecov-html', '~> 0.10.0'
|
31
|
+
```
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at [https://github.com/evgeniradev/simplecov_url](https://github.com/evgeniradev/simplecov_url).
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
SimplecovUrl is released under the MIT License. See MIT-LICENSE for details.
|
data/Rakefile
ADDED
data/config/routes.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SimplecovUrl
|
4
|
+
class AccessManager
|
5
|
+
def self.deny?
|
6
|
+
new.deny?
|
7
|
+
end
|
8
|
+
|
9
|
+
def deny?
|
10
|
+
tmp = ENV['ALLOWED_SIMPLECOV_ENVIRONMENTS']
|
11
|
+
|
12
|
+
tmp.present? ? tmp.split(',').none? { |env| env == Rails.env } : false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'simplecov_url/access_manager'
|
4
|
+
|
5
|
+
module SimplecovUrl
|
6
|
+
class HtmlProcessor
|
7
|
+
HTML_FILE = 'index.html'
|
8
|
+
CSS_FILE = 'application.css'
|
9
|
+
JAVASCRIPT_FILE = 'application.js'
|
10
|
+
|
11
|
+
def self.call
|
12
|
+
new.html
|
13
|
+
end
|
14
|
+
|
15
|
+
def html
|
16
|
+
return no_report_message(' for environment') if AccessManager.deny?
|
17
|
+
|
18
|
+
tmp = read_file(HTML_FILE)
|
19
|
+
|
20
|
+
return no_report_message unless tmp
|
21
|
+
|
22
|
+
tmp = remove_link_and_script_tags(tmp)
|
23
|
+
|
24
|
+
tmp = img_href_tags_to_base64(tmp)
|
25
|
+
|
26
|
+
return frontend_error(CSS_FILE) unless css
|
27
|
+
|
28
|
+
return frontend_error(JAVASCRIPT_FILE) unless javascript
|
29
|
+
|
30
|
+
tmp = insert_css_and_javascript_as_inline(tmp)
|
31
|
+
|
32
|
+
tmp.html_safe
|
33
|
+
rescue StandardError => e
|
34
|
+
general_error(e)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def files
|
40
|
+
@files ||= Dir.glob(File.join(Rails.root, 'coverage', '**', '*'))
|
41
|
+
end
|
42
|
+
|
43
|
+
def read_file(name)
|
44
|
+
file = files.find { |f| f.include?(name) }
|
45
|
+
|
46
|
+
file ? File.read(file) : nil
|
47
|
+
end
|
48
|
+
|
49
|
+
def javascript
|
50
|
+
@javascript ||= begin
|
51
|
+
tmp = read_file(JAVASCRIPT_FILE)
|
52
|
+
|
53
|
+
return nil unless tmp
|
54
|
+
|
55
|
+
"<script>#{tmp}</script>"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def css
|
60
|
+
@css ||= begin
|
61
|
+
tmp = read_file(CSS_FILE)
|
62
|
+
|
63
|
+
return nil unless tmp
|
64
|
+
|
65
|
+
tmp = background_url_attributes_to_base64(tmp)
|
66
|
+
|
67
|
+
"<style>#{tmp}</style>"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def background_url_attributes_to_base64(content)
|
72
|
+
imgs_to_base64(
|
73
|
+
content,
|
74
|
+
attribute_regex: /url\(.*?\)/,
|
75
|
+
paths_regex: /(url\W*)|(\W*$)/,
|
76
|
+
replacement: lambda do |encoded_img, mime_type|
|
77
|
+
"url(data:#{mime_type};base64,#{encoded_img})"
|
78
|
+
end
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
def img_href_tags_to_base64(content)
|
83
|
+
imgs_to_base64(
|
84
|
+
content,
|
85
|
+
attribute_regex: /<img src=['|"].*?['|"]/,
|
86
|
+
paths_regex: /<img.*\.\/|\W*$/,
|
87
|
+
replacement: lambda do |encoded_img, mime_type|
|
88
|
+
"<img src='data:#{mime_type};base64,#{encoded_img}'"
|
89
|
+
end
|
90
|
+
)
|
91
|
+
end
|
92
|
+
|
93
|
+
def imgs_to_base64(content, attribute_regex:, paths_regex:, replacement:)
|
94
|
+
attributes = content.scan(attribute_regex).flatten
|
95
|
+
|
96
|
+
img_paths = attributes.map do |attribute|
|
97
|
+
[attribute, attribute.gsub(paths_regex, '')]
|
98
|
+
end
|
99
|
+
|
100
|
+
base64s = img_paths.map do |attribute, img_path|
|
101
|
+
file = files.find { |f| f.include?(img_path) }
|
102
|
+
|
103
|
+
mime_type = "image/#{File.extname(file).delete('.')}"
|
104
|
+
|
105
|
+
encoded_img = Base64.strict_encode64(File.read(file))
|
106
|
+
|
107
|
+
[attribute, replacement.call(encoded_img, mime_type)]
|
108
|
+
end.to_h
|
109
|
+
|
110
|
+
base64s.each do |attribute, base64|
|
111
|
+
content = content.gsub(attribute, base64)
|
112
|
+
end
|
113
|
+
|
114
|
+
content
|
115
|
+
end
|
116
|
+
|
117
|
+
def insert_css_and_javascript_as_inline(tmp)
|
118
|
+
position = (tmp =~ /<\/head>/)
|
119
|
+
|
120
|
+
tmp.insert(position, css)
|
121
|
+
tmp.insert(position, javascript)
|
122
|
+
end
|
123
|
+
|
124
|
+
def remove_link_and_script_tags(tmp)
|
125
|
+
tmp.gsub(/<link.*>/, '').gsub(/<script.*<\/script>/, '')
|
126
|
+
end
|
127
|
+
|
128
|
+
def no_report_message(extra = '')
|
129
|
+
"No test coverage report available#{extra}."
|
130
|
+
end
|
131
|
+
|
132
|
+
def frontend_error(filename)
|
133
|
+
"Error: '#{filename}' file is missing."
|
134
|
+
end
|
135
|
+
|
136
|
+
def general_error(error)
|
137
|
+
puts(error.message)
|
138
|
+
puts(error.backtrace)
|
139
|
+
'Error: Unable to load test coverage report.'
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simplecov_url
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Evgeni Radev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.2.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.2.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: simplecov
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.16.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.16.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: simplecov-html
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.10.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.10.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- evgeniradev@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- MIT-LICENSE
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- app/controllers/simplecov_url/simplecov_controller.rb
|
94
|
+
- config/routes.rb
|
95
|
+
- lib/simplecov_url.rb
|
96
|
+
- lib/simplecov_url/access_manager.rb
|
97
|
+
- lib/simplecov_url/html_processor.rb
|
98
|
+
- lib/simplecov_url/version.rb
|
99
|
+
homepage: https://github.com/evgeniradev/simplecov_url
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata:
|
103
|
+
allowed_push_host: https://rubygems.org
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 2.7.9
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: The gem publishes Simplecov's test coverage reports to your_url/simplecov.
|
124
|
+
test_files: []
|