eac_ruby_gem_support 0.8.2 → 0.10.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: 604189d5f2c83ce11eb9e52435b54de3883861fcaf742a0023eed4bd171654d5
4
+ data.tar.gz: b5613db689320ecda2285e19236068df36e1c95c4c14e95a012c99c6d54b1330
5
5
  SHA512:
6
- metadata.gz: 41aeb063f73b535aea447bc5a4553928555363fd800139da1d048984995c88de4be053ad6acc0394e0c1086048495d6cb2d9b733ed1f61cd04a051d08376b64e
7
- data.tar.gz: dcbaafbe599e411976a472a065cad33bbec9c4599641a021fd1e75500c798f1a01724cdece6fdfef2e513e0631f47054bf7c0f58539a621810f5a7cafe0554d6
6
+ metadata.gz: 2fa46da053d9c5c5b97839c8372cf6097cc73e541d8c4e825cc40969ab81cd45c7a18eedef98510fcdee408a932a56625bb57020c55423aea5d491b6c06a2255
7
+ data.tar.gz: 75dbfb0333063516002e019f9114d04a5bb1e7a89283258fd4010d62584c4477b0b07ebdf50c8f16308495db4982df217c7b40db5b526e9d4af03700641212ac
data/.rubocop.yml CHANGED
@@ -23,12 +23,18 @@ Rails/DynamicFindBy:
23
23
  Enabled: false
24
24
  Rails/Exit:
25
25
  Enabled: false
26
+ Rails/FindEach:
27
+ Enabled: false
26
28
  Rails/Output:
27
29
  Enabled: false
28
30
  Rails/SkipsModelValidations:
29
31
  Enabled: false
30
32
  Rails/TimeZone:
31
33
  Enabled: false
34
+ RSpec/MultipleMemoizedHelpers:
35
+ Enabled: false
36
+ RSpec/NestedGroups:
37
+ Enabled: false
32
38
  Style/AsciiComments:
33
39
  Enabled: false
34
40
  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,11 @@ 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/spec_paths'
37
+ require 'eac_ruby_gem_support/rspec/shared_examples/source_target_fixtures'
38
+ end
39
+
35
40
  # @return [Pathname]
36
41
  def example_persistence_path
37
42
  root_tmp.join('example_status_persistence')
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_gem_support/rspec/shared_examples/spec_paths'
4
+ require 'eac_ruby_gem_support/rspec/source_target_fixtures_controller'
5
+ require 'eac_ruby_gem_support/source_target_fixtures'
6
+ require 'yaml'
7
+
8
+ RSpec.shared_examples 'source_target_fixtures' do |spec_file| # rubocop:disable Metrics/BlockLength
9
+ include_examples 'spec_paths', spec_file
10
+ fixtures_controller = EacRubyGemSupport::Rspec::SourceTargetFixturesController
11
+ .new(spec_paths_controller)
12
+
13
+ let(:fixtures_controller) { fixtures_controller }
14
+ let(:spec_file) { spec_file }
15
+
16
+ it 'fixtures directory should exist' do
17
+ expect(File.directory?(fixtures_controller.fixtures_dir)).to be true
18
+ end
19
+
20
+ context 'with fixtures directory' do
21
+ it 'has at least one file' do
22
+ expect(source_target_fixtures.source_target_files.count).to be > 0 # rubocop:disable Style/NumericPredicate
23
+ end
24
+
25
+ fixtures_controller.source_target_fixtures.source_target_files.each do |st|
26
+ context "when source file is \"#{File.basename(st.source)}\"" do
27
+ if fixtures_controller.write_target_fixtures?
28
+ it 'writes target data' do
29
+ sd = sort_results(source_data(st.source))
30
+ basename = EacRubyGemSupport::SourceTargetFixtures.source_target_basename(st.source)
31
+ target_file = File.expand_path("../#{basename}.target#{target_file_extname}", st.source)
32
+ File.write(target_file, target_content(sd))
33
+ end
34
+ else
35
+ it 'parses data' do
36
+ assert_source_target_complete(st)
37
+ sd = source_data(st.source)
38
+ td = target_data(st.target)
39
+ expect(sort_results(sd)).to eq(sort_results(td))
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ delegate :source_target_fixtures, to: :fixtures_controller
47
+
48
+ def assert_source_target_complete(source_target)
49
+ expect(source_target.source).to(be_truthy, "Source not found (Target: #{source_target.target})")
50
+ expect(source_target.target).to(be_truthy, "Target not found (Source: #{source_target.source})")
51
+ end
52
+
53
+ def source_data(source_file)
54
+ instance = described_class.new(source_file)
55
+ return instance.data if instance.respond_to?(:data)
56
+
57
+ raise "#{instance} has no \"data\" method. You need to implement \"#{instance}.data\" or " \
58
+ "\"#{self}.source_data(source_file)\""
59
+ end
60
+
61
+ def sort_results(results)
62
+ results
63
+ end
64
+
65
+ def target_data(target_file)
66
+ YAML.load_file(target_file)
67
+ end
68
+
69
+ def target_content(data)
70
+ data.to_yaml
71
+ end
72
+
73
+ def target_file_extname
74
+ '.yaml'
75
+ end
76
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_gem_support/rspec/spec_paths_controller'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ RSpec.shared_context 'spec_paths' do |the_spec_file|
7
+ cattr_accessor :spec_paths_controller
8
+ self.spec_paths_controller = EacRubyGemSupport::Rspec::SpecPathsController.new(self,
9
+ the_spec_file)
10
+
11
+ %i[fixtures_directory spec_directory spec_file].each do |m|
12
+ let(m) { self.class.spec_paths_controller.send(m) }
13
+ end
14
+ end
@@ -0,0 +1,32 @@
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 :spec_paths_controller
11
+ delegate :example, to: :spec_paths_controller
12
+
13
+ def fixtures_dir
14
+ if example.respond_to?(:fixtures_dir)
15
+ example.fixtures_dir
16
+ else
17
+ spec_paths_controller.fixtures_directory
18
+ end
19
+ end
20
+
21
+ def write_target_fixtures?
22
+ ENV['WRITE_TARGET_FIXTURES'].to_bool
23
+ end
24
+
25
+ private
26
+
27
+ def source_target_fixtures_uncached
28
+ ::EacRubyGemSupport::SourceTargetFixtures.new(fixtures_dir)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacRubyGemSupport
6
+ module Rspec
7
+ class SpecPathsController
8
+ # @!attribute [r] spec_file
9
+ # @return [Pathname]
10
+
11
+ # @!method initialize(example, spec_file)
12
+ # @param example [RSpec::Core::ExampleGroup]
13
+ # @param spec_file [Pathname]
14
+ common_constructor :example, :spec_file do
15
+ self.spec_file = spec_file.to_pathname
16
+ end
17
+
18
+ # @return [Pathname]
19
+ def fixtures_directory
20
+ spec_directory.join(spec_file.basename('.*')).basename_sub { |b| "#{b}_files" }
21
+ end
22
+
23
+ # @return [Pathname]
24
+ def spec_directory
25
+ spec_file.parent
26
+ end
27
+ end
28
+ end
29
+ 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,76 @@
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
+ # @!attribute [r] fixtures_directory
18
+ # @return [String]
19
+
20
+ # @!method initialize(fixtures_directory)
21
+ # @param fixtures_directory [Pathname]
22
+ common_constructor :fixtures_directory
23
+
24
+ def source_target_files
25
+ sources_targets_basenames.map do |basename|
26
+ ::EacRubyGemSupport::SourceTargetFixtures::SourceTargetFile.new(self, basename)
27
+ end
28
+ end
29
+
30
+ def source_files
31
+ r = []
32
+ source_target_files.each do |st|
33
+ r << st.source if st.source
34
+ end
35
+ r
36
+ end
37
+
38
+ def target_files
39
+ r = []
40
+ source_target_files.each do |st|
41
+ r << st.target if st.target
42
+ end
43
+ r
44
+ end
45
+
46
+ def target_file(basename)
47
+ fixture_file(basename, 'target')
48
+ end
49
+
50
+ def source_file(basename)
51
+ fixture_file(basename, 'source')
52
+ end
53
+
54
+ private
55
+
56
+ def fixture_file(basename, suffix)
57
+ prefix = "#{basename}.#{suffix}"
58
+ Dir.foreach(fixtures_directory) do |item|
59
+ next if %w[. ..].include?(item)
60
+ return File.expand_path(item, fixtures_directory) if item.starts_with?(prefix)
61
+ end
62
+ nil
63
+ end
64
+
65
+ def sources_targets_basenames
66
+ basenames = Set.new
67
+ Dir.foreach(fixtures_directory) do |item|
68
+ next if %w[. ..].include?(item)
69
+
70
+ b = self.class.source_target_basename(item)
71
+ basenames << b if b.present?
72
+ end
73
+ basenames
74
+ end
75
+ end
76
+ 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.10.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.10.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: 2024-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_ruby_utils
@@ -16,20 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.119'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 0.119.2
19
+ version: '0.120'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '0.119'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 0.119.2
26
+ version: '0.120'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: rspec
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -50,60 +44,60 @@ dependencies:
50
44
  requirements:
51
45
  - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: '1.57'
47
+ version: '1.60'
54
48
  - - ">="
55
49
  - !ruby/object:Gem::Version
56
- version: 1.57.1
50
+ version: 1.60.1
57
51
  type: :runtime
58
52
  prerelease: false
59
53
  version_requirements: !ruby/object:Gem::Requirement
60
54
  requirements:
61
55
  - - "~>"
62
56
  - !ruby/object:Gem::Version
63
- version: '1.57'
57
+ version: '1.60'
64
58
  - - ">="
65
59
  - !ruby/object:Gem::Version
66
- version: 1.57.1
60
+ version: 1.60.1
67
61
  - !ruby/object:Gem::Dependency
68
62
  name: rubocop-rails
69
63
  requirement: !ruby/object:Gem::Requirement
70
64
  requirements:
71
65
  - - "~>"
72
66
  - !ruby/object:Gem::Version
73
- version: '2.21'
67
+ version: '2.23'
74
68
  - - ">="
75
69
  - !ruby/object:Gem::Version
76
- version: 2.21.2
70
+ version: 2.23.1
77
71
  type: :runtime
78
72
  prerelease: false
79
73
  version_requirements: !ruby/object:Gem::Requirement
80
74
  requirements:
81
75
  - - "~>"
82
76
  - !ruby/object:Gem::Version
83
- version: '2.21'
77
+ version: '2.23'
84
78
  - - ">="
85
79
  - !ruby/object:Gem::Version
86
- version: 2.21.2
80
+ version: 2.23.1
87
81
  - !ruby/object:Gem::Dependency
88
82
  name: rubocop-rspec
89
83
  requirement: !ruby/object:Gem::Requirement
90
84
  requirements:
91
85
  - - "~>"
92
86
  - !ruby/object:Gem::Version
93
- version: '2.24'
87
+ version: '2.26'
94
88
  - - ">="
95
89
  - !ruby/object:Gem::Version
96
- version: 2.24.1
90
+ version: 2.26.1
97
91
  type: :runtime
98
92
  prerelease: false
99
93
  version_requirements: !ruby/object:Gem::Requirement
100
94
  requirements:
101
95
  - - "~>"
102
96
  - !ruby/object:Gem::Version
103
- version: '2.24'
97
+ version: '2.26'
104
98
  - - ">="
105
99
  - !ruby/object:Gem::Version
106
- version: 2.24.1
100
+ version: 2.26.1
107
101
  description:
108
102
  email:
109
103
  executables: []
@@ -116,7 +110,13 @@ 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/shared_examples/spec_paths.rb
115
+ - lib/eac_ruby_gem_support/rspec/source_target_fixtures_controller.rb
116
+ - lib/eac_ruby_gem_support/rspec/spec_paths_controller.rb
119
117
  - lib/eac_ruby_gem_support/rspec/specs/rubocop.rb
118
+ - lib/eac_ruby_gem_support/source_target_fixtures.rb
119
+ - lib/eac_ruby_gem_support/source_target_fixtures/source_target_file.rb
120
120
  - lib/eac_ruby_gem_support/version.rb
121
121
  homepage: https://github.com/esquilo-azul/eac_ruby_gem_support
122
122
  licenses: []