eac_ruby_gem_support 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13a8eb8edc90d11d33090a072aa8e067a55bd53817e3483a4f94d2de692cf12c
4
- data.tar.gz: 9c1eb39f5cc95e5f32fed0bbb2956b36ad9943b8123a45a860af404755930e39
3
+ metadata.gz: 87738e690edee80a927f5a3e2cdba1cfdd5979bebcc1b2e8aba274614f5c26da
4
+ data.tar.gz: 7aecaebeb4fa14060ea250d5a2fbaa7ae5b69936865c3bb3d7df54bd550f6ed6
5
5
  SHA512:
6
- metadata.gz: 41aeb063f73b535aea447bc5a4553928555363fd800139da1d048984995c88de4be053ad6acc0394e0c1086048495d6cb2d9b733ed1f61cd04a051d08376b64e
7
- data.tar.gz: dcbaafbe599e411976a472a065cad33bbec9c4599641a021fd1e75500c798f1a01724cdece6fdfef2e513e0631f47054bf7c0f58539a621810f5a7cafe0554d6
6
+ metadata.gz: b8d0bf332ff3c8e0cdf1ceeb5d568c7f44be00d2a48fffd43c7d60be7a3b0a566639d4961edf62434c4d8c506ac2e36eef38656c934b51c3ddab66c2905dc162
7
+ data.tar.gz: cc0cb4d2a85554411e80274b5b8d0f83c83ccced39646a8df7e0f6a89fd8fefc794712c804c19b6f0faa397418447e4e93a79c7cbdf0b897b1884c11585cb7ef
data/.rubocop.yml CHANGED
@@ -29,6 +29,10 @@ Rails/SkipsModelValidations:
29
29
  Enabled: false
30
30
  Rails/TimeZone:
31
31
  Enabled: false
32
+ RSpec/MultipleMemoizedHelpers:
33
+ Enabled: false
34
+ RSpec/NestedGroups:
35
+ Enabled: false
32
36
  Style/AsciiComments:
33
37
  Enabled: false
34
38
  Style/Documentation:
@@ -12,10 +12,10 @@ module EacRubyGemSupport
12
12
  extend ::ActiveSupport::Concern
13
13
  include ::EacRubyGemSupport::Rspec::Specs::Rubocop
14
14
 
15
+ SETUPS = %w[load_path example_persistence filesystem_helper shared_examples].freeze
16
+
15
17
  def self.extended(setup_obj)
16
- setup_obj.setup_load_path
17
- setup_obj.setup_example_persistence
18
- setup_obj.setup_filesystem_helper
18
+ SETUPS.each { |s| setup_obj.send("setup_#{s}") }
19
19
  end
20
20
 
21
21
  def setup_filesystem_helper
@@ -32,6 +32,10 @@ module EacRubyGemSupport
32
32
  rspec_config.example_status_persistence_file_path = example_persistence_path.to_path
33
33
  end
34
34
 
35
+ def setup_shared_examples
36
+ require 'eac_ruby_gem_support/rspec/shared_examples/source_target_fixtures'
37
+ end
38
+
35
39
  # @return [Pathname]
36
40
  def example_persistence_path
37
41
  root_tmp.join('example_status_persistence')
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_gem_support/rspec/source_target_fixtures_controller'
4
+ require 'eac_ruby_gem_support/source_target_fixtures'
5
+ require 'yaml'
6
+
7
+ RSpec.shared_examples 'source_target_fixtures' do |spec_file| # rubocop:disable Metrics/BlockLength
8
+ fixtures_controller = EacRubyGemSupport::Rspec::SourceTargetFixturesController
9
+ .new(self, spec_file)
10
+
11
+ let(:fixtures_controller) { fixtures_controller }
12
+ let(:spec_file) { spec_file }
13
+
14
+ it 'fixtures directory should exist' do
15
+ expect(File.directory?(fixtures_controller.fixtures_dir)).to be true
16
+ end
17
+
18
+ context 'with fixtures directory' do
19
+ it 'has at least one file' do
20
+ expect(source_target_fixtures.source_target_files.count).to be > 0 # rubocop:disable Style/NumericPredicate
21
+ end
22
+
23
+ fixtures_controller.source_target_fixtures.source_target_files.each do |st|
24
+ context "when source file is \"#{File.basename(st.source)}\"" do
25
+ if fixtures_controller.write_target_fixtures?
26
+ it 'writes target data' do
27
+ sd = sort_results(source_data(st.source))
28
+ basename = EacRubyGemSupport::SourceTargetFixtures.source_target_basename(st.source)
29
+ target_file = File.expand_path("../#{basename}.target#{target_file_extname}", st.source)
30
+ File.write(target_file, target_content(sd))
31
+ end
32
+ else
33
+ it 'parses data' do
34
+ assert_source_target_complete(st)
35
+ sd = source_data(st.source)
36
+ td = target_data(st.target)
37
+ expect(sort_results(sd)).to eq(sort_results(td))
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ delegate :source_target_fixtures, to: :fixtures_controller
45
+
46
+ def assert_source_target_complete(source_target)
47
+ expect(source_target.source).to(be_truthy, "Source not found (Target: #{source_target.target})")
48
+ expect(source_target.target).to(be_truthy, "Target not found (Source: #{source_target.source})")
49
+ end
50
+
51
+ def source_data(source_file)
52
+ instance = described_class.new(source_file)
53
+ return instance.data if instance.respond_to?(:data)
54
+
55
+ raise "#{instance} has no \"data\" method. You need to implement \"#{instance}.data\" or " \
56
+ "\"#{self}.source_data(source_file)\""
57
+ end
58
+
59
+ def sort_results(results)
60
+ results
61
+ end
62
+
63
+ def target_data(target_file)
64
+ YAML.load_file(target_file)
65
+ end
66
+
67
+ def target_content(data)
68
+ data.to_yaml
69
+ end
70
+
71
+ def target_file_extname
72
+ '.yaml'
73
+ end
74
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_gem_support/source_target_fixtures'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EacRubyGemSupport
7
+ module Rspec
8
+ class SourceTargetFixturesController
9
+ enable_simple_cache
10
+ common_constructor :example, :spec_file
11
+
12
+ def default_fixtures_dir
13
+ ::File.join(
14
+ ::File.dirname(spec_file),
15
+ "#{::File.basename(spec_file, '.*')}_files"
16
+ )
17
+ end
18
+
19
+ def fixtures_dir
20
+ if example.respond_to?(:fixtures_dir)
21
+ example.fixtures_dir
22
+ else
23
+ default_fixtures_dir
24
+ end
25
+ end
26
+
27
+ def write_target_fixtures?
28
+ ENV['WRITE_TARGET_FIXTURES'].to_bool
29
+ end
30
+
31
+ private
32
+
33
+ def source_target_fixtures_uncached
34
+ ::EacRubyGemSupport::SourceTargetFixtures.new(fixtures_dir)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacRubyGemSupport
6
+ class SourceTargetFixtures
7
+ class SourceTargetFile
8
+ common_constructor :owner, :basename
9
+
10
+ def source
11
+ owner.source_file(basename)
12
+ end
13
+
14
+ def target
15
+ owner.target_file(basename)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacRubyGemSupport
6
+ # Lists pairs of source/target files in a directory.
7
+ class SourceTargetFixtures
8
+ require_sub __FILE__
9
+
10
+ class << self
11
+ def source_target_basename(file)
12
+ m = /^(.+)\.(?:source|target)(?:\..+)?$/.match(File.basename(file))
13
+ m ? m[1] : nil
14
+ end
15
+ end
16
+
17
+ attr_reader :fixtures_directory
18
+
19
+ def initialize(fixtures_directory)
20
+ @fixtures_directory = fixtures_directory
21
+ end
22
+
23
+ def source_target_files
24
+ sources_targets_basenames.map do |basename|
25
+ ::EacRubyGemSupport::SourceTargetFixtures::SourceTargetFile.new(self, basename)
26
+ end
27
+ end
28
+
29
+ def source_files
30
+ r = []
31
+ source_target_files.each do |st|
32
+ r << st.source if st.source
33
+ end
34
+ r
35
+ end
36
+
37
+ def target_files
38
+ r = []
39
+ source_target_files.each do |st|
40
+ r << st.target if st.target
41
+ end
42
+ r
43
+ end
44
+
45
+ def target_file(basename)
46
+ fixture_file(basename, 'target')
47
+ end
48
+
49
+ def source_file(basename)
50
+ fixture_file(basename, 'source')
51
+ end
52
+
53
+ private
54
+
55
+ def fixture_file(basename, suffix)
56
+ prefix = "#{basename}.#{suffix}"
57
+ Dir.foreach(fixtures_directory) do |item|
58
+ next if %w[. ..].include?(item)
59
+ return File.expand_path(item, fixtures_directory) if item.starts_with?(prefix)
60
+ end
61
+ nil
62
+ end
63
+
64
+ def sources_targets_basenames
65
+ basenames = Set.new
66
+ Dir.foreach(fixtures_directory) do |item|
67
+ next if %w[. ..].include?(item)
68
+
69
+ b = self.class.source_target_basename(item)
70
+ basenames << b if b.present?
71
+ end
72
+ basenames
73
+ end
74
+ end
75
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyGemSupport
4
- VERSION = '0.8.2'
4
+ VERSION = '0.9.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_ruby_gem_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-27 00:00:00.000000000 Z
11
+ date: 2023-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_ruby_utils
@@ -53,7 +53,7 @@ dependencies:
53
53
  version: '1.57'
54
54
  - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: 1.57.1
56
+ version: 1.57.2
57
57
  type: :runtime
58
58
  prerelease: false
59
59
  version_requirements: !ruby/object:Gem::Requirement
@@ -63,47 +63,41 @@ dependencies:
63
63
  version: '1.57'
64
64
  - - ">="
65
65
  - !ruby/object:Gem::Version
66
- version: 1.57.1
66
+ version: 1.57.2
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: rubocop-rails
69
69
  requirement: !ruby/object:Gem::Requirement
70
70
  requirements:
71
71
  - - "~>"
72
72
  - !ruby/object:Gem::Version
73
- version: '2.21'
73
+ version: '2.22'
74
74
  - - ">="
75
75
  - !ruby/object:Gem::Version
76
- version: 2.21.2
76
+ version: 2.22.1
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: '2.21'
83
+ version: '2.22'
84
84
  - - ">="
85
85
  - !ruby/object:Gem::Version
86
- version: 2.21.2
86
+ version: 2.22.1
87
87
  - !ruby/object:Gem::Dependency
88
88
  name: rubocop-rspec
89
89
  requirement: !ruby/object:Gem::Requirement
90
90
  requirements:
91
91
  - - "~>"
92
92
  - !ruby/object:Gem::Version
93
- version: '2.24'
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: 2.24.1
93
+ version: '2.25'
97
94
  type: :runtime
98
95
  prerelease: false
99
96
  version_requirements: !ruby/object:Gem::Requirement
100
97
  requirements:
101
98
  - - "~>"
102
99
  - !ruby/object:Gem::Version
103
- version: '2.24'
104
- - - ">="
105
- - !ruby/object:Gem::Version
106
- version: 2.24.1
100
+ version: '2.25'
107
101
  description:
108
102
  email:
109
103
  executables: []
@@ -116,7 +110,11 @@ files:
116
110
  - lib/eac_ruby_gem_support/rspec/helpers/filesystem.rb
117
111
  - lib/eac_ruby_gem_support/rspec/helpers/utils.rb
118
112
  - lib/eac_ruby_gem_support/rspec/setup.rb
113
+ - lib/eac_ruby_gem_support/rspec/shared_examples/source_target_fixtures.rb
114
+ - lib/eac_ruby_gem_support/rspec/source_target_fixtures_controller.rb
119
115
  - lib/eac_ruby_gem_support/rspec/specs/rubocop.rb
116
+ - lib/eac_ruby_gem_support/source_target_fixtures.rb
117
+ - lib/eac_ruby_gem_support/source_target_fixtures/source_target_file.rb
120
118
  - lib/eac_ruby_gem_support/version.rb
121
119
  homepage: https://github.com/esquilo-azul/eac_ruby_gem_support
122
120
  licenses: []