usps-support 0.2.13 → 0.2.15

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e225f56b0f2b17cbce8ea9137659b586d8ff4c796a083ec5db20d35f8c26cfb4
4
- data.tar.gz: 590d80b46235f48e09d6d3fc7e6cae11bb54067ee044e4b9b4d58d9e22fc1d86
3
+ metadata.gz: 06f5b7ef7a2a7b3899721c10fe6a0bdf0d75f3dd04b21cb31c6acdb47908b314
4
+ data.tar.gz: 2557beb4fe11739cbd23aeb977fde8637f821c1e41613a1c8bf2a9ed45d56249
5
5
  SHA512:
6
- metadata.gz: 79cea6dfcd0103ce0216a46dbe63a17e52703a7cf98bf583c6badc189c528d73d090f4fdc9d4caeda2e59837a5967f596939c9fe2b697bd2c80124592cb12866
7
- data.tar.gz: 55b2469eaf39c0dd8cd300fe6c24503bb16746854a038cac55cd13c5e63e47726f3360f4a59e669b570bcb61c65a331520b8f45c55ff44bc2878a85b762324f2
6
+ metadata.gz: a67296ed9f3f3e85bfc4e01ec8d7bdf6fb1a5b347ba32e64273f9c8ae9445a4d0d8b223600eea5c14e400e0da75030cdad94fdd6a9e7db8e52dde74de82b1932
7
+ data.tar.gz: 25b0c7077bc8ada1775b16bb8bcf8dfe71ac3acd29f37c7899294305ec4aa58ddd1f8b690a99b4f22ef6a177f1e6962b7c07fe015f208a05d5016164ab53d67c
@@ -0,0 +1,84 @@
1
+ module Usps::Support::Lib::SimpleCov
2
+ # Parser for converting hash filter definition into individual coverage filters
3
+ #
4
+ # Example config:
5
+ #
6
+ # {
7
+ # ignored_category_header: {
8
+ # spec: '*',
9
+ # app: {
10
+ # controllers: %w[example_1],
11
+ # helpers: 'example_2',
12
+ # models: {
13
+ # members: %w[example_3],
14
+ # _: %w[example_4]
15
+ # }
16
+ # }
17
+ # }
18
+ # }
19
+ #
20
+ # This config would generate the following coverage filters:
21
+ #
22
+ # - `/spec`
23
+ # - `/app/controllers/example_1.rb`
24
+ # - `/app/helpers/example_2.rb`
25
+ # - `/app/models/members/example_3.rb`
26
+ # - `/app/models/example_4.rb`
27
+ #
28
+ class FiltersParser
29
+ attr_reader :filters_config
30
+
31
+ def self.paths(...) = new(...).paths
32
+
33
+ def initialize(filters_config)
34
+ @filters_config = filters_config
35
+ @dir = []
36
+ @paths = []
37
+ end
38
+
39
+ def paths
40
+ return @paths if @paths.any?
41
+
42
+ filters_config.each_value { parse_data(it) }
43
+
44
+ @paths
45
+ end
46
+
47
+ private
48
+
49
+ def parse_data(data)
50
+ case data
51
+ when '*' then filter_dir
52
+ when String then filter_file(data)
53
+ when Array then data.each { filter_file(it) }
54
+ when Hash then walk(data)
55
+ else
56
+ raise "Unrecognized filter format: #{data.inspect}"
57
+ end
58
+ end
59
+
60
+ def walk(hash)
61
+ hash.each do |dir, sub_data|
62
+ with(dir) { parse_data(sub_data) }
63
+ end
64
+ end
65
+
66
+ def with(dir)
67
+ @dir << dir.to_s
68
+ yield
69
+ @dir.pop
70
+ end
71
+
72
+ def filter_dir
73
+ @paths << dir_path
74
+ end
75
+
76
+ def filter_file(filename)
77
+ @paths << File.join(dir_path, "#{filename}.rb")
78
+ end
79
+
80
+ def dir_path
81
+ "/#{File.join(@dir)}".sub(%r{/_}, '') if @dir.any?
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,49 @@
1
+ module Usps::Support::Lib::SimpleCov
2
+ # Simple coverage formatter to display paths of any uncovered lines
3
+ #
4
+ # Intended to make it quicker to know what was uncovered, especially when
5
+ # running in GitHub Actions
6
+ #
7
+ # rubocop:disable Rails/Output
8
+ class UncoveredLinesFormatter
9
+ attr_reader :uncovered_files
10
+
11
+ def format(result)
12
+ @uncovered_files = result.files.reject { it.missed_lines.empty? }
13
+ return unless uncovered_files.any?
14
+
15
+ puts 'Uncovered lines:'
16
+ uncovered_files.each { report(it) }
17
+ end
18
+
19
+ private
20
+
21
+ def report(file)
22
+ missed = pad(file.missed_lines.size)
23
+ total = pad(file.lines_of_code)
24
+ percent = file.covered_percent.round(2).to_s.rjust(5, ' ')
25
+
26
+ puts " [#{missed} / #{total} : #{percent}%] #{file.filename}"
27
+ puts " Lines: #{line_number_ranges(file).join(', ')}"
28
+ end
29
+
30
+ def pad(number) = number.to_s.rjust(max_line_count_length, ' ')
31
+
32
+ def max_line_count_length
33
+ @max_line_count_length ||= uncovered_files.map(&:lines_of_code).max.to_s.length
34
+ end
35
+
36
+ def line_number_ranges(file)
37
+ file
38
+ .missed_lines
39
+ .map(&:line_number)
40
+ .chunk
41
+ .with_index { |number, index| number - index }
42
+ .map do |_diff, group|
43
+ first, *, last = group
44
+ last.nil? ? first : "#{first}-#{last}"
45
+ end
46
+ end
47
+ end
48
+ # rubocop:enable Rails/Output
49
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Usps::Support::Lib
4
+ # SimpleCov extensions
5
+ #
6
+ module SimpleCov; end
7
+ end
8
+
9
+ require_relative 'simple_cov/filters_parser'
10
+ require_relative 'simple_cov/uncovered_lines_formatter'
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Shared Rails libraries
4
+ #
5
+ module Usps::Support::Lib; end
6
+
7
+ require_relative 'lib/simple_cov'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Support
5
- VERSION = '0.2.13'
5
+ VERSION = '0.2.15'
6
6
  end
7
7
  end
data/lib/usps/support.rb CHANGED
@@ -12,6 +12,7 @@ end
12
12
 
13
13
  require_relative 'support/helpers'
14
14
  require_relative 'support/models'
15
+ require_relative 'support/lib'
15
16
 
16
17
  # :nocov:
17
18
  require 'usps/support/railtie' if defined?(Rails)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usps-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.13
4
+ version: 0.2.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
@@ -69,6 +69,10 @@ files:
69
69
  - lib/usps/support/helpers/git_helper.rb
70
70
  - lib/usps/support/helpers/react_helper.rb
71
71
  - lib/usps/support/helpers/scss_helper.rb
72
+ - lib/usps/support/lib.rb
73
+ - lib/usps/support/lib/simple_cov.rb
74
+ - lib/usps/support/lib/simple_cov/filters_parser.rb
75
+ - lib/usps/support/lib/simple_cov/uncovered_lines_formatter.rb
72
76
  - lib/usps/support/models.rb
73
77
  - lib/usps/support/models/dynamo_db.rb
74
78
  - lib/usps/support/models/git_hub.rb