views_coverage 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +59 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +12 -0
- data/LICENSE +21 -0
- data/README.md +55 -0
- data/lib/minitest/views_coverage_plugin.rb +94 -0
- data/lib/views_coverage.rb +2 -0
- data/views_coverage.gemspec +15 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 45aac1ef2be75a4ae2b9ed458ae8d32aa33de4d323d2c81c2a4e4693417f627e
|
4
|
+
data.tar.gz: 0ae68763a28f4ea77ddab63810292fcc78ed12bd7f43468dbbdb03a7a129bf16
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1a54185cd78ef104c6aa76989247fbc5dcd2fa7786fe1ba5b0165ad04a41734e545b579f516a5eb5d7a141b2b68217f9b30ec62f2c1a35dd004ef6cec15a01bc
|
7
|
+
data.tar.gz: 2a0e86ac8fd7ed55ce3e863515917c46546458526dbf231d7b26c568cadc77f61fa0626fa67da7b6fe06b3cbc777e41c9e8ae699dd5acaefcdb14a3f1f2f704b
|
data/.gitignore
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
56
|
+
# .rubocop-https?--*
|
57
|
+
|
58
|
+
# Rubymine
|
59
|
+
.idea
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at macku@jchsoft.cz. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 JchSoft s.r.o.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# views_coverage
|
2
|
+
ViewsCoverage is Minitest plugin for showing which views or partials was generated during tests. Plugin listening for [render notification from Rails framework](https://guides.rubyonrails.org/active_support_instrumentation.html#action-view) and save data from this event (path to view and how many times it was generated).
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```
|
8
|
+
gem 'views_coverage'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
```
|
14
|
+
$ bundle
|
15
|
+
```
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
__Warning: Plugin dont support parallel tests. If you want to use this plugin, set `parallelize(workers: 1)` or comment `parallelize` line in your `test_helper.rb`.__
|
19
|
+
|
20
|
+
Basic usage is run tests with `--views-coverage` flag:
|
21
|
+
|
22
|
+
```
|
23
|
+
rails test --views-coverage
|
24
|
+
```
|
25
|
+
|
26
|
+
or if you run system tests, this flag must be passed in TESTOPS:
|
27
|
+
|
28
|
+
```
|
29
|
+
rails test:system TESTOPTS="--views-coverage"
|
30
|
+
```
|
31
|
+
|
32
|
+
This command will generate following files:
|
33
|
+
* for unit tests - `views_coverage_result_unit_pretty.txt` and `views_coverage_result_unit.yml`
|
34
|
+
* for system tests - `views_coverage_result_system_pretty.txt` and `views_coverage_result_system.yml`
|
35
|
+
|
36
|
+
`*.txt` files are containing pretty printed coverage output.
|
37
|
+
`*.yml` files are containing coverage for "merge" mode (viz next paragraph).
|
38
|
+
|
39
|
+
### Merge results from multiple test runs
|
40
|
+
If you want to merge results from multiple test runs (for example from unit tests and system tests), you should pass `--views-coverage-mode=merge` when running tests:
|
41
|
+
|
42
|
+
```
|
43
|
+
rails test:system TESTOPTS="--views-coverage --views-coverage-mode=merge"
|
44
|
+
```
|
45
|
+
|
46
|
+
This mode load content of YML files and merge their results into `views_coverage_result_merged_pretty.txt` and `views_coverage_result_merged_pretty.yml` files.
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jchsoft/views_coverage. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
|
50
|
+
|
51
|
+
## License
|
52
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
53
|
+
|
54
|
+
## Code of Conduct
|
55
|
+
Everyone interacting in the ViewsCoverage project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jchsoft/views_coverage/blob/master/CODE_OF_CONDUCT.md).
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Minitest
|
2
|
+
class ViewsCoverage < AbstractReporter
|
3
|
+
NO_TEMPLATE_IDENTIFIERS = ['html template', 'text template'].freeze
|
4
|
+
RESULT_FILENAME_PREFIX = 'views_coverage_result_'.freeze
|
5
|
+
MERGE_MODE_FLAG = 'merge'.freeze
|
6
|
+
|
7
|
+
def initialize(options)
|
8
|
+
super()
|
9
|
+
@mode = options.delete(:mode) || 'clean'
|
10
|
+
@coverage_result = {}
|
11
|
+
subscribe_to_notifications
|
12
|
+
end
|
13
|
+
|
14
|
+
def prerecord(klass, _name)
|
15
|
+
@test_type = klass < ActionDispatch::SystemTestCase ? :system : :unit
|
16
|
+
end
|
17
|
+
|
18
|
+
def report
|
19
|
+
write_result(@coverage_result[:unit], :unit) if @coverage_result[:unit].present?
|
20
|
+
write_result(@coverage_result[:system], :system) if @coverage_result[:system].present?
|
21
|
+
write_merged_result if @mode == MERGE_MODE_FLAG
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def subscribe_to_notifications
|
27
|
+
%w[render_template.action_view render_partial.action_view render_collection.action_view].each do |event_name|
|
28
|
+
ActiveSupport::Notifications.subscribe event_name do |_name, _start, _finish, _id, payload|
|
29
|
+
@coverage_result[@test_type] ||= prepare_result_hash
|
30
|
+
@coverage_result[@test_type][payload[:identifier].delete_prefix("#{::Rails.root.to_s}/")] += 1
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def write_merged_result
|
36
|
+
if @coverage_result[:system].present?
|
37
|
+
result = merge_results(current_result: @coverage_result[:system], previous_test_type: :unit)
|
38
|
+
else
|
39
|
+
result = merge_results(current_result: @coverage_result[:unit], previous_test_type: :system)
|
40
|
+
end
|
41
|
+
write_result(result, :merged)
|
42
|
+
end
|
43
|
+
|
44
|
+
def merge_results(current_result:, previous_test_type:)
|
45
|
+
previous_result = YAML.load_file("#{RESULT_FILENAME_PREFIX}#{previous_test_type}.yml")
|
46
|
+
current_result.merge(previous_result) { |_path, previous_count, current_count| previous_count + current_count }
|
47
|
+
end
|
48
|
+
|
49
|
+
def prepare_result_hash
|
50
|
+
{}.tap do |hash|
|
51
|
+
NO_TEMPLATE_IDENTIFIERS.each { |identifier| hash[identifier] = 0 }
|
52
|
+
Dir.glob('app/views/**/*.*').each { |file_path| hash[file_path] = 0 }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def write_result(result, type)
|
57
|
+
File.open("#{RESULT_FILENAME_PREFIX}#{type}.yml", 'w') do |file|
|
58
|
+
file.write(YAML.dump(result))
|
59
|
+
end
|
60
|
+
|
61
|
+
called_views = result.select { |_, count| count.positive? }
|
62
|
+
not_called_views = result.select { |_, count| count.zero? }
|
63
|
+
|
64
|
+
file = File.new("#{RESULT_FILENAME_PREFIX}#{type}_pretty.txt", 'w')
|
65
|
+
file.write("=============== Not called ===============\n")
|
66
|
+
not_called_views.keys.sort.each { |path| file.write("#{path}\n") }
|
67
|
+
|
68
|
+
file.write("\n\n\n")
|
69
|
+
file.write("=============== Called ===============\n")
|
70
|
+
called_views.each_pair { |path, call_counter| file.write("#{call_counter}:\t\t#{path}\n") }
|
71
|
+
|
72
|
+
file.write("\n\n\n")
|
73
|
+
file.write("=============== Summary ===============\n")
|
74
|
+
file.write("Uncalled: #{not_called_views.length}\n")
|
75
|
+
file.write("Called: #{called_views.length}\n")
|
76
|
+
file.write("Coverage %: #{((called_views.length.to_d / result.length) * 100).to_s}")
|
77
|
+
file.close
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.plugin_views_coverage_options(opts, options)
|
82
|
+
opts.on "--views-coverage", "Generate coverage for views" do
|
83
|
+
options[:views_coverage] = true
|
84
|
+
end
|
85
|
+
|
86
|
+
opts.on '--views-coverage-mode MODE', String do |mode|
|
87
|
+
options[:mode] = mode
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.plugin_views_coverage_init(options)
|
92
|
+
self.reporter << ViewsCoverage.new(options) if options[:views_coverage]
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'views_coverage'
|
3
|
+
s.version = '0.0.2'
|
4
|
+
s.summary = 'Minitest plugin providing test coverage for views (which templates and partials were and werent generated during tests).'
|
5
|
+
s.authors = ['mmacku']
|
6
|
+
s.email = 'macku@jchsoft.cz'
|
7
|
+
# Specify which files should be added to the gem when it is released.
|
8
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
9
|
+
s.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
10
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
11
|
+
end
|
12
|
+
s.homepage = 'https://github.com/jchsoft/views_coverage'
|
13
|
+
s.license = 'MIT'
|
14
|
+
s.add_dependency 'activesupport'
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: views_coverage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mmacku
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-09-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description:
|
28
|
+
email: macku@jchsoft.cz
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- ".gitignore"
|
34
|
+
- CODE_OF_CONDUCT.md
|
35
|
+
- Gemfile
|
36
|
+
- LICENSE
|
37
|
+
- README.md
|
38
|
+
- lib/minitest/views_coverage_plugin.rb
|
39
|
+
- lib/views_coverage.rb
|
40
|
+
- views_coverage.gemspec
|
41
|
+
homepage: https://github.com/jchsoft/views_coverage
|
42
|
+
licenses:
|
43
|
+
- MIT
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubygems_version: 3.0.3
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: Minitest plugin providing test coverage for views (which templates and partials
|
64
|
+
were and werent generated during tests).
|
65
|
+
test_files: []
|