i18n-coverage 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +25 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.md +12 -1
- data/Gemfile +2 -2
- data/Gemfile.lock +32 -6
- data/README.md +22 -11
- data/Rakefile +5 -3
- data/bin/console +3 -3
- data/i18n-coverage.gemspec +22 -22
- data/lib/i18n/backend/key_logger.rb +3 -2
- data/lib/i18n/coverage.rb +22 -5
- data/lib/i18n/coverage/config.rb +17 -0
- data/lib/i18n/coverage/key_lister.rb +23 -15
- data/lib/i18n/coverage/key_logger.rb +3 -15
- data/lib/i18n/coverage/printers/basic_printer.rb +26 -0
- data/lib/i18n/coverage/printers/file_printer.rb +33 -0
- data/lib/i18n/coverage/reporter.rb +21 -19
- data/lib/i18n/coverage/version.rb +1 -1
- metadata +47 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee3cd49315df6b7d72cd6df8815581f74f5172966d2aedd6e009287c2946d8b3
|
4
|
+
data.tar.gz: fe61ba0db852812b755a90ef1dd9ecb42afa27b54d27217e3cdb73858fd1221a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9cb4285645101f11777919b6397ad50e2d5de87d478b68b0e1520ee3fa402bcc4fb7a625a220b489e4b5f4526b39060a2aa682884d9b968c183483fbbd47c5d
|
7
|
+
data.tar.gz: 94337fce2b4552b5f26c1dc1dbe3ef1ac32c6b828f639f69052a7bdc0b5ac377acc26812e31d7692c69bd29771b4fbf8cbc1156989a0acf29d65c19767cce7fd
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
AllCops:
|
2
|
+
# Wait until the community has decided
|
3
|
+
NewCops: disable
|
4
|
+
|
5
|
+
# These files naturally have long blocks
|
6
|
+
Metrics/BlockLength:
|
7
|
+
Exclude:
|
8
|
+
- 'spec/**/*.rb'
|
9
|
+
- '*.gemspec'
|
10
|
+
|
11
|
+
# Avoid Cops with arbitrary settings
|
12
|
+
Metrics/MethodLength:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
# This is no longer upcoming for Ruby
|
16
|
+
Style/FrozenStringLiteralComment:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
# Avoid Cops with arbitrary settings
|
20
|
+
Layout/LineLength:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
# Avoid comments unless they add value
|
24
|
+
Style/Documentation:
|
25
|
+
Enabled: false
|
data/.travis.yml
CHANGED
@@ -4,4 +4,13 @@ language: ruby
|
|
4
4
|
cache: bundler
|
5
5
|
rvm:
|
6
6
|
- 2.6.2
|
7
|
+
|
7
8
|
before_install: gem install bundler -v 1.17.2
|
9
|
+
before_script:
|
10
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
11
|
+
- chmod +x ./cc-test-reporter
|
12
|
+
- ./cc-test-reporter before-build
|
13
|
+
script:
|
14
|
+
- bundle exec rake
|
15
|
+
after_script:
|
16
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
I18N coverage Changelog
|
2
2
|
=======================
|
3
3
|
|
4
|
+
0.2.0
|
5
|
+
-----
|
6
|
+
|
7
|
+
- Relax coverage criteria [PR#5](https://github.com/hiptest/i18n-coverage/pull/5) (by [benthorner](https://github.com/benthorner))
|
8
|
+
|
9
|
+
- From [PR#4](https://github.com/hiptest/i18n-coverage/pull/4) (by [benthorner](https://github.com/benthorner))
|
10
|
+
- Multiple YAML files (when a repo has lots of translations)
|
11
|
+
- Partial matching (to cope with advanced usages of I18n)
|
12
|
+
- Configurable output (so we can enforce coverage in CI)
|
13
|
+
- Adds RuboCop (so it's easier to be consistent in future)
|
14
|
+
|
4
15
|
0.1.1
|
5
16
|
-----
|
6
17
|
|
@@ -9,4 +20,4 @@ I18N coverage Changelog
|
|
9
20
|
0.1.0
|
10
21
|
-----
|
11
22
|
|
12
|
-
- Initial release
|
23
|
+
- Initial release
|
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
3
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in i18n-coverage.gemspec
|
6
6
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
i18n-coverage (0.
|
4
|
+
i18n-coverage (0.2.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
addressable (2.6.0)
|
10
10
|
public_suffix (>= 2.0.2, < 4.0)
|
11
|
+
ast (2.4.0)
|
11
12
|
builder (3.2.3)
|
12
13
|
concurrent-ruby (1.1.5)
|
13
14
|
descendants_tracker (0.0.4)
|
14
15
|
thread_safe (~> 0.3, >= 0.3.1)
|
15
16
|
diff-lcs (1.3)
|
17
|
+
docile (1.3.1)
|
16
18
|
faraday (0.15.4)
|
17
19
|
multipart-post (>= 1.2, < 3)
|
18
20
|
git (1.5.0)
|
@@ -26,6 +28,8 @@ GEM
|
|
26
28
|
highline (2.0.2)
|
27
29
|
i18n (0.9.5)
|
28
30
|
concurrent-ruby (~> 1.0)
|
31
|
+
jaro_winkler (1.5.4)
|
32
|
+
json (2.2.0)
|
29
33
|
juwelier (2.4.9)
|
30
34
|
builder
|
31
35
|
bundler
|
@@ -45,7 +49,7 @@ GEM
|
|
45
49
|
multi_json (1.13.1)
|
46
50
|
multi_xml (0.6.0)
|
47
51
|
multipart-post (2.1.1)
|
48
|
-
nokogiri (1.10.
|
52
|
+
nokogiri (1.10.8)
|
49
53
|
mini_portile2 (~> 2.4.0)
|
50
54
|
oauth2 (1.4.1)
|
51
55
|
faraday (>= 0.8, < 0.16.0)
|
@@ -53,11 +57,16 @@ GEM
|
|
53
57
|
multi_json (~> 1.3)
|
54
58
|
multi_xml (~> 0.5)
|
55
59
|
rack (>= 1.2, < 3)
|
60
|
+
parallel (1.19.1)
|
61
|
+
parser (2.7.1.2)
|
62
|
+
ast (~> 2.4.0)
|
56
63
|
psych (3.1.0)
|
57
64
|
public_suffix (3.1.0)
|
58
|
-
rack (2.
|
59
|
-
|
65
|
+
rack (2.2.3)
|
66
|
+
rainbow (3.0.0)
|
67
|
+
rake (13.0.1)
|
60
68
|
rdoc (6.1.1)
|
69
|
+
rexml (3.2.4)
|
61
70
|
rspec (3.8.0)
|
62
71
|
rspec-core (~> 3.8.0)
|
63
72
|
rspec-expectations (~> 3.8.0)
|
@@ -71,8 +80,23 @@ GEM
|
|
71
80
|
diff-lcs (>= 1.2.0, < 2.0)
|
72
81
|
rspec-support (~> 3.8.0)
|
73
82
|
rspec-support (3.8.0)
|
83
|
+
rubocop (0.82.0)
|
84
|
+
jaro_winkler (~> 1.5.1)
|
85
|
+
parallel (~> 1.10)
|
86
|
+
parser (>= 2.7.0.1)
|
87
|
+
rainbow (>= 2.2.2, < 4.0)
|
88
|
+
rexml
|
89
|
+
ruby-progressbar (~> 1.7)
|
90
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
91
|
+
ruby-progressbar (1.10.1)
|
74
92
|
semver2 (3.4.2)
|
93
|
+
simplecov (0.16.1)
|
94
|
+
docile (~> 1.1)
|
95
|
+
json (>= 1.8, < 3)
|
96
|
+
simplecov-html (~> 0.10.0)
|
97
|
+
simplecov-html (0.10.2)
|
75
98
|
thread_safe (0.3.6)
|
99
|
+
unicode-display_width (1.7.0)
|
76
100
|
|
77
101
|
PLATFORMS
|
78
102
|
ruby
|
@@ -82,8 +106,10 @@ DEPENDENCIES
|
|
82
106
|
i18n (~> 0.7)
|
83
107
|
i18n-coverage!
|
84
108
|
juwelier (~> 2.4)
|
85
|
-
rake (~>
|
109
|
+
rake (~> 13.0)
|
86
110
|
rspec (~> 3.0)
|
111
|
+
rubocop (~> 0.82)
|
112
|
+
simplecov
|
87
113
|
|
88
114
|
BUNDLED WITH
|
89
|
-
1.17.
|
115
|
+
1.17.3
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# I18n-coverage
|
2
2
|
[![Build Status](https://travis-ci.org/hiptest/i18n-coverage.svg?branch=master)](https://travis-ci.org/hiptest/i18n-coverage)
|
3
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/30a359b5ad82800c5d35/maintainability)](https://codeclimate.com/github/hiptest/i18n-coverage/maintainability)
|
4
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/30a359b5ad82800c5d35/test_coverage)](https://codeclimate.com/github/hiptest/i18n-coverage/test_coverage)
|
3
5
|
|
4
6
|
Simple gem to see how much of your i18n keys are used during tests. It requires that the translations are handled by the [i18n](https://rubygems.org/gems/i18n/) gem.
|
5
7
|
|
@@ -15,33 +17,42 @@ gem 'i18n-coverage'
|
|
15
17
|
|
16
18
|
## Usage
|
17
19
|
|
18
|
-
|
20
|
+
Add the following lines somewhere to your test setup. For RSpec, this will be at the top of `spec_helper.rb`.
|
19
21
|
|
20
22
|
```ruby
|
21
|
-
# file spec_helper.rb
|
22
23
|
require 'i18n/coverage'
|
24
|
+
I18n::Coverage.start
|
23
25
|
```
|
24
26
|
|
25
|
-
|
27
|
+
If you don't want to check I18n Coverage in every test run, you could enable it with an environment variable.
|
26
28
|
|
27
29
|
```ruby
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
30
|
+
# file spec_helper.rb
|
31
|
+
require 'i18n/coverage'
|
32
|
+
I18n::Coverage.start if ENV['I18N_COVERAGE']
|
33
33
|
```
|
34
34
|
|
35
|
-
Then, when running the tests, you need to enable coverage by setting the environment variable `I18N_COVERAGE`. For example with rspec:
|
36
|
-
|
37
35
|
```shell
|
38
36
|
I18N_COVERAGE=1 bundle exec rspec
|
39
37
|
```
|
40
38
|
|
39
|
+
## Configuration
|
40
|
+
|
41
|
+
The default config is [here](lib/i18n/coverage/config.rb).
|
42
|
+
|
43
|
+
### Printer
|
44
|
+
|
45
|
+
By default the coverage is output to the console. You can also select a different printer, or write your own!
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
require 'i18n/coverage/printers/file_printer'
|
49
|
+
I18n::Coverage.config.printer = I18n::Coverage::Printer::FilePrinter
|
50
|
+
I18n::Coverage.start
|
51
|
+
```
|
41
52
|
|
42
53
|
## Development
|
43
54
|
|
44
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
55
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests, or just `rake` to run all tasks, such as linting. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
45
56
|
|
46
57
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
47
58
|
|
data/Rakefile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'rubocop/rake_task'
|
3
4
|
|
4
5
|
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
RuboCop::RakeTask.new
|
5
7
|
|
6
|
-
task :
|
8
|
+
task default: %i[spec rubocop]
|
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'i18n/coverage'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "i18n/coverage"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start(__FILE__)
|
data/i18n-coverage.gemspec
CHANGED
@@ -1,41 +1,41 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
3
|
+
require 'i18n/coverage/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
6
|
+
spec.name = 'i18n-coverage'
|
8
7
|
spec.version = I18n::Coverage::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
8
|
+
spec.authors = ['Hiptest']
|
9
|
+
spec.email = ['contact@hiptest.com']
|
11
10
|
|
12
|
-
spec.summary =
|
13
|
-
spec.homepage =
|
11
|
+
spec.summary = 'Provides a coverage of I18n keys used during test suite'
|
12
|
+
spec.homepage = 'https://github.com/hiptest/i18n-coverage'
|
14
13
|
|
15
14
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
16
15
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
17
16
|
if spec.respond_to?(:metadata)
|
18
|
-
spec.metadata[
|
19
|
-
spec.metadata[
|
20
|
-
spec.metadata[
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/hiptest/i18n-coverage'
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/hiptest/i18n-coverage/blob/master/CHANGELOG.md'
|
21
20
|
else
|
22
|
-
raise
|
23
|
-
|
21
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
22
|
+
'public gem pushes.'
|
24
23
|
end
|
25
24
|
|
26
25
|
# Specify which files should be added to the gem when it is released.
|
27
26
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
28
|
-
spec.files
|
27
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
29
28
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
30
29
|
end
|
31
|
-
spec.bindir =
|
30
|
+
spec.bindir = 'exe'
|
32
31
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
|
-
spec.require_paths = [
|
34
|
-
|
35
|
-
spec.add_development_dependency "i18n", "~> 0.7"
|
36
|
-
spec.add_development_dependency "bundler", "~> 1.17"
|
37
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
38
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
39
|
-
spec.add_development_dependency "juwelier", "~> 2.4"
|
32
|
+
spec.require_paths = ['lib']
|
40
33
|
|
34
|
+
spec.add_development_dependency 'bundler', '~> 1.17'
|
35
|
+
spec.add_development_dependency 'i18n', '~> 0.7'
|
36
|
+
spec.add_development_dependency 'juwelier', '~> 2.4'
|
37
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
38
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
39
|
+
spec.add_development_dependency 'rubocop', '~> 0.82'
|
40
|
+
spec.add_development_dependency 'simplecov'
|
41
41
|
end
|
@@ -3,8 +3,9 @@ require 'i18n/coverage/key_logger'
|
|
3
3
|
module I18n
|
4
4
|
module Backend
|
5
5
|
module KeyLogger
|
6
|
-
def
|
7
|
-
|
6
|
+
def lookup(locale, key, scope = [], options = {})
|
7
|
+
key = (Array(scope || []) + [key]).compact.join('.')
|
8
|
+
I18n::Coverage::KeyLogger.store_key(key)
|
8
9
|
super
|
9
10
|
end
|
10
11
|
end
|
data/lib/i18n/coverage.rb
CHANGED
@@ -1,11 +1,28 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require 'i18n'
|
2
|
+
require 'i18n/coverage/version'
|
3
|
+
require 'i18n/coverage/reporter'
|
4
|
+
require 'i18n/backend/key_logger'
|
5
|
+
require 'i18n/coverage/config'
|
5
6
|
|
6
7
|
module I18n
|
7
8
|
module Coverage
|
9
|
+
def self.start
|
10
|
+
I18n::Backend::Simple.include I18n::Backend::KeyLogger
|
11
|
+
at_exit { I18n::Coverage::Reporter.report }
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.config
|
15
|
+
@config ||= Config.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.configure
|
19
|
+
@config = Config.new
|
20
|
+
yield @config if block_given?
|
21
|
+
end
|
8
22
|
end
|
9
23
|
end
|
10
24
|
|
11
|
-
|
25
|
+
if ENV['I18N_COVERAGE']
|
26
|
+
warn 'DEPRECATED: use I18n::Coverage.start instead'
|
27
|
+
I18n::Backend::Simple.include I18n::Backend::KeyLogger
|
28
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'i18n/coverage/printers/basic_printer'
|
2
|
+
|
3
|
+
module I18n
|
4
|
+
module Coverage
|
5
|
+
class Config
|
6
|
+
attr_accessor :locale,
|
7
|
+
:locale_dir_path,
|
8
|
+
:printer
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
self.locale = 'en'
|
12
|
+
self.locale_dir_path = 'config/locales'
|
13
|
+
self.printer = I18n::Coverage::Printers::BasicPrinter
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -3,40 +3,48 @@ require 'yaml'
|
|
3
3
|
module I18n
|
4
4
|
module Coverage
|
5
5
|
class KeyLister
|
6
|
-
def self.list_keys
|
7
|
-
KeyLister.new
|
6
|
+
def self.list_keys
|
7
|
+
KeyLister.new.list_keys
|
8
8
|
end
|
9
|
-
|
10
|
-
def initialize
|
11
|
-
|
12
|
-
@
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
locale_dir_path = I18n::Coverage.config.locale_dir_path
|
12
|
+
@locale_files = Dir.glob("#{locale_dir_path}/**/*.yml")
|
13
13
|
@keys = Set[]
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def list_keys
|
17
|
-
|
17
|
+
@locale_files
|
18
|
+
.map(&YAML.method(:load_file))
|
19
|
+
.flat_map { |hash| visit_childs(source: hash, path: []) }
|
20
|
+
|
18
21
|
@keys
|
19
22
|
end
|
20
|
-
|
23
|
+
|
21
24
|
private
|
22
|
-
|
23
|
-
def visit_childs(path:
|
24
|
-
node =
|
25
|
+
|
26
|
+
def visit_childs(source:, path:)
|
27
|
+
node = source.dig(locale, *path)
|
28
|
+
|
25
29
|
if node.respond_to? :keys
|
26
30
|
keys = node.keys
|
27
31
|
|
28
32
|
if pluralization_keys?(keys)
|
29
33
|
@keys.add(path.join('.'))
|
30
34
|
else
|
31
|
-
keys.map {|key| visit_childs(path:
|
35
|
+
keys.map { |key| visit_childs(source: source, path: path + [key]) }
|
32
36
|
end
|
33
|
-
|
37
|
+
elsif path.count.positive?
|
34
38
|
@keys.add(path.join('.'))
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
38
42
|
def pluralization_keys?(keys)
|
39
|
-
|
43
|
+
(keys - %w[zero one other]).empty?
|
44
|
+
end
|
45
|
+
|
46
|
+
def locale
|
47
|
+
I18n::Coverage.config.locale
|
40
48
|
end
|
41
49
|
end
|
42
50
|
end
|
@@ -2,27 +2,15 @@ module I18n
|
|
2
2
|
module Coverage
|
3
3
|
class KeyLogger
|
4
4
|
def self.store_key(key)
|
5
|
-
|
5
|
+
stored_keys.add(key)
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.stored_keys
|
9
|
-
|
9
|
+
@stored_keys ||= Set[]
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.clear_keys
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
def store_key(key)
|
17
|
-
stored_keys.add(key)
|
18
|
-
end
|
19
|
-
|
20
|
-
def clear_keys
|
21
|
-
stored_keys.clear
|
22
|
-
end
|
23
|
-
|
24
|
-
def stored_keys
|
25
|
-
@@stored_keys ||= Set[]
|
13
|
+
stored_keys.clear
|
26
14
|
end
|
27
15
|
end
|
28
16
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module I18n
|
2
|
+
module Coverage
|
3
|
+
module Printers
|
4
|
+
class BasicPrinter
|
5
|
+
def self.print(report)
|
6
|
+
new(report).print
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(report)
|
10
|
+
@report = report
|
11
|
+
end
|
12
|
+
|
13
|
+
def print
|
14
|
+
puts ''
|
15
|
+
puts "I18n Coverage: #{@report[:percentage_used].round(2)}% of the keys used"
|
16
|
+
puts "#{@report[:key_count]} keys found in yml files, #{@report[:used_key_count]} keys used during the tests"
|
17
|
+
|
18
|
+
return unless @report[:unused_keys]
|
19
|
+
|
20
|
+
puts 'Unused keys:'
|
21
|
+
@report[:unused_keys].map { |k| puts " #{k}" }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module I18n
|
2
|
+
module Coverage
|
3
|
+
module Printers
|
4
|
+
class FilePrinter
|
5
|
+
REPORT_PATH = 'coverage/i18n.json'.freeze
|
6
|
+
|
7
|
+
def self.print(report)
|
8
|
+
new(report).print
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(report)
|
12
|
+
@report = report
|
13
|
+
end
|
14
|
+
|
15
|
+
def print
|
16
|
+
write_report
|
17
|
+
print_message
|
18
|
+
end
|
19
|
+
|
20
|
+
def write_report
|
21
|
+
FileUtils.mkdir_p(File.dirname(REPORT_PATH))
|
22
|
+
File.write(REPORT_PATH, JSON.pretty_generate(@report))
|
23
|
+
end
|
24
|
+
|
25
|
+
def print_message
|
26
|
+
puts "Coverage report generated for I18n to #{REPORT_PATH}. " \
|
27
|
+
"#{@report[:used_key_count]} / #{@report[:key_count]} keys " \
|
28
|
+
"(#{@report[:percentage_used].round(2)}%) covered."
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -4,36 +4,38 @@ require 'i18n/coverage/key_logger'
|
|
4
4
|
module I18n
|
5
5
|
module Coverage
|
6
6
|
class Reporter
|
7
|
-
def self.report
|
8
|
-
Reporter.new
|
7
|
+
def self.report
|
8
|
+
Reporter.new.report
|
9
9
|
end
|
10
10
|
|
11
|
-
def initialize
|
12
|
-
@existing_keys = KeyLister.list_keys
|
13
|
-
@
|
14
|
-
@percentage_used = (@used_keys.count.to_f / @existing_keys.count.to_f) * 100
|
15
|
-
@unused_keys = @existing_keys - @used_keys
|
11
|
+
def initialize
|
12
|
+
@existing_keys = KeyLister.list_keys
|
13
|
+
@stored_keys = KeyLogger.stored_keys
|
16
14
|
end
|
17
15
|
|
18
16
|
def report
|
19
|
-
|
20
|
-
puts "I18n Coverage: #{@percentage_used.round(2)}% of the keys used"
|
21
|
-
puts "#{@existing_keys.count} keys found in yml file, #{@used_keys.count} keys used during the tests"
|
22
|
-
|
23
|
-
if @unused_keys
|
24
|
-
puts "Unused keys:"
|
25
|
-
@unused_keys.map {|k| puts " #{k}"}
|
26
|
-
end
|
17
|
+
I18n::Coverage.config.printer.print(hash_report)
|
27
18
|
end
|
28
19
|
|
29
20
|
def hash_report
|
21
|
+
used_keys = @existing_keys - unused_keys
|
22
|
+
percentage_used = (used_keys.count.to_f / @existing_keys.count) * 100
|
23
|
+
|
30
24
|
{
|
31
25
|
key_count: @existing_keys.count,
|
32
|
-
used_key_count:
|
33
|
-
percentage_used:
|
34
|
-
unused_keys:
|
26
|
+
used_key_count: used_keys.count,
|
27
|
+
percentage_used: percentage_used,
|
28
|
+
unused_keys: unused_keys.to_a
|
35
29
|
}
|
36
30
|
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def unused_keys
|
35
|
+
@unused_keys ||= @existing_keys.reject do |key|
|
36
|
+
@stored_keys.any? { |stored_key| key.start_with?(stored_key.to_s) }
|
37
|
+
end
|
38
|
+
end
|
37
39
|
end
|
38
40
|
end
|
39
|
-
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n-coverage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiptest
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: i18n
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -25,33 +39,33 @@ dependencies:
|
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '0.7'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
42
|
+
name: juwelier
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
47
|
+
version: '2.4'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '2.4'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
61
|
+
version: '13.0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
68
|
+
version: '13.0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rspec
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,20 +81,34 @@ dependencies:
|
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '3.0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
84
|
+
name: rubocop
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
89
|
+
version: '0.82'
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
94
|
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
83
|
-
|
96
|
+
version: '0.82'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
84
112
|
email:
|
85
113
|
- contact@hiptest.com
|
86
114
|
executables: []
|
@@ -89,6 +117,7 @@ extra_rdoc_files: []
|
|
89
117
|
files:
|
90
118
|
- ".gitignore"
|
91
119
|
- ".rspec"
|
120
|
+
- ".rubocop.yml"
|
92
121
|
- ".travis.yml"
|
93
122
|
- CHANGELOG.md
|
94
123
|
- Gemfile
|
@@ -100,8 +129,11 @@ files:
|
|
100
129
|
- i18n-coverage.gemspec
|
101
130
|
- lib/i18n/backend/key_logger.rb
|
102
131
|
- lib/i18n/coverage.rb
|
132
|
+
- lib/i18n/coverage/config.rb
|
103
133
|
- lib/i18n/coverage/key_lister.rb
|
104
134
|
- lib/i18n/coverage/key_logger.rb
|
135
|
+
- lib/i18n/coverage/printers/basic_printer.rb
|
136
|
+
- lib/i18n/coverage/printers/file_printer.rb
|
105
137
|
- lib/i18n/coverage/reporter.rb
|
106
138
|
- lib/i18n/coverage/version.rb
|
107
139
|
homepage: https://github.com/hiptest/i18n-coverage
|
@@ -110,7 +142,7 @@ metadata:
|
|
110
142
|
homepage_uri: https://github.com/hiptest/i18n-coverage
|
111
143
|
source_code_uri: https://github.com/hiptest/i18n-coverage
|
112
144
|
changelog_uri: https://github.com/hiptest/i18n-coverage/blob/master/CHANGELOG.md
|
113
|
-
post_install_message:
|
145
|
+
post_install_message:
|
114
146
|
rdoc_options: []
|
115
147
|
require_paths:
|
116
148
|
- lib
|
@@ -125,8 +157,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
157
|
- !ruby/object:Gem::Version
|
126
158
|
version: '0'
|
127
159
|
requirements: []
|
128
|
-
rubygems_version: 3.0.
|
129
|
-
signing_key:
|
160
|
+
rubygems_version: 3.0.6
|
161
|
+
signing_key:
|
130
162
|
specification_version: 4
|
131
163
|
summary: Provides a coverage of I18n keys used during test suite
|
132
164
|
test_files: []
|