eac_ruby_gems_utils 0.7.0 → 0.9.0

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: ba6901f2b81816e02333d51f9c1e4eb8d5a705a500f8d5485b20897925d1e0a2
4
- data.tar.gz: b84a7c9aa771b08b204860e6c1961c259d847c044ab26d00b1db16e7fe2fbfc9
3
+ metadata.gz: f10dcfe737d3c84df10c25a0fa82bcb7b49828b0470e83781863dbcd51ea07b2
4
+ data.tar.gz: '01930655004cdc2b58fe3691a9f781d40ef3261cbbfce8569eb58962c8e4a5e6'
5
5
  SHA512:
6
- metadata.gz: 3dc046a756ad593ab46288d1882488ecd1e2c10116698036923f24d694b4c60daf025f798a7184b0b26705154588529a6ade87ea5261d64e81b7b3e2a79222d6
7
- data.tar.gz: e70343b18f054bc8c402336b0150aed0c33a9638e815c40e9c75a13ff49835ea46498b1d686f91065edd401f834de1302e1d5ff3bd51ca80c2d25192e4441f28
6
+ metadata.gz: aea3df2c2992bcaf24684910e043eda8ce4fefd6b25ee3f9111ab7d7388df010c2dc1c0923a9f4e79ff699472e76f09737d7327108c53924c8d201844a1d865d
7
+ data.tar.gz: d04bb3e97d4a7c9d66a513fce6c63573f61f0b896f2edfcfc50a7bff3231a861bc34d5c86e9f502db1637a8244c433922fbd748e54c2f1c6550681f0408c3187
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
4
  require 'eac_ruby_utils/envs'
5
+ require 'rubygems'
5
6
 
6
7
  module EacRubyGemsUtils
7
8
  class Gem
@@ -10,8 +11,9 @@ module EacRubyGemsUtils
10
11
 
11
12
  GEMSPEC_EXTNAME = '.gemspec'
12
13
 
13
- common_constructor :root do
14
+ common_constructor :root, :host_env, default: [nil] do
14
15
  @root = ::Pathname.new(root).expand_path
16
+ self.host_env ||= ::EacRubyUtils::Envs.local
15
17
  end
16
18
 
17
19
  def to_s
@@ -22,6 +24,11 @@ module EacRubyGemsUtils
22
24
  ::EacRubyGemsUtils::Gem::Command.new(self, %w[bundle] + args).envvar_gemfile
23
25
  end
24
26
 
27
+ # @return A [Pathname] array with relative paths from root listed in gemspec's .file directive.
28
+ def files
29
+ gemspec.files.map(&:to_pathname)
30
+ end
31
+
25
32
  def gemfile_lock_gem_version(gem_name)
26
33
  gemfile_lock_content.specs.find { |gem| gem.name == gem_name }.if_present(&:version)
27
34
  end
@@ -67,6 +74,10 @@ module EacRubyGemsUtils
67
74
  gemfile_path.basename_sub { |b| "#{b}.lock" }
68
75
  end
69
76
 
77
+ def gemspec_uncached
78
+ ::Gem::Specification.load(gemspec_path.to_path)
79
+ end
80
+
70
81
  def gemspec_path_uncached
71
82
  ::Pathname.glob("#{root.to_path}/*#{GEMSPEC_EXTNAME}").first
72
83
  end
@@ -11,7 +11,7 @@ module EacRubyGemsUtils
11
11
 
12
12
  def initialize(gem, command_args, extra_options = {})
13
13
  @gem = gem
14
- super(command_args, extra_options)
14
+ super(command_args, extra_options.merge(host_env: gem.host_env))
15
15
  end
16
16
 
17
17
  # Changes current directory to the gem's directory.
@@ -10,11 +10,7 @@ module EacRubyGemsUtils
10
10
  VERSION_LINE_PATTERN = /\A(\s*)VERSION\s*=\s*[\'\"]([^\'\"]+)[\'\"](\s*)\z/.freeze
11
11
 
12
12
  def value
13
- path.read.each_line do |line|
14
- VERSION_LINE_PATTERN.if_match(line.rstrip, false) do |m|
15
- ::Gem::Version.new(m[2])
16
- end
17
- end
13
+ path.read.each_line.lazy.map { |line| line_value(line) }.find { |v| v }
18
14
  end
19
15
 
20
16
  def value=(new_value)
@@ -23,6 +19,11 @@ module EacRubyGemsUtils
23
19
 
24
20
  private
25
21
 
22
+ # @return Version found in line, nil otherwise.
23
+ def line_value(line)
24
+ VERSION_LINE_PATTERN.if_match(line.rstrip, false) { |m| ::Gem::Version.new(m[2]) }
25
+ end
26
+
26
27
  def new_value_content(new_value)
27
28
  path.read.each_line
28
29
  .map { |line| new_value_line(line, new_value) }
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/fs/logs'
4
5
  require 'eac_ruby_utils/fs_cache'
5
6
  require 'eac_ruby_utils/listable'
6
7
  require 'eac_ruby_utils/on_clean_ruby_environment'
@@ -27,20 +28,16 @@ module EacRubyGemsUtils
27
28
  self.class.name.demodulize.gsub(/Test\z/, '')
28
29
  end
29
30
 
30
- def stdout_cache
31
- root_cache.child('stdout')
32
- end
33
-
34
- def stderr_cache
35
- root_cache.child('stderr')
36
- end
37
-
38
31
  def to_s
39
32
  "#{gem}[#{name}]"
40
33
  end
41
34
 
42
35
  private
43
36
 
37
+ def logs_uncached
38
+ ::EacRubyUtils::Fs::Logs.new.add(:stdout).add(:stderr)
39
+ end
40
+
44
41
  def result_uncached
45
42
  return RESULT_NONEXISTENT unless elegible?
46
43
 
@@ -53,8 +50,8 @@ module EacRubyGemsUtils
53
50
 
54
51
  def exec_run_with_log
55
52
  r = exec_run
56
- stdout_cache.write(r[:stdout])
57
- stderr_cache.write(r[:stderr])
53
+ logs[:stdout].write(r[:stdout])
54
+ logs[:stderr].write(r[:stderr])
58
55
  r[:exit_code].zero?
59
56
  end
60
57
 
@@ -7,6 +7,7 @@ require 'eac_ruby_utils/core_ext'
7
7
  module EacRubyGemsUtils
8
8
  module Tests
9
9
  class Multiple
10
+ require_sub __FILE__
10
11
  enable_console_speaker
11
12
  enable_simple_cache
12
13
  common_constructor :gems, :options, default: [{}]
@@ -26,16 +27,17 @@ module EacRubyGemsUtils
26
27
  decorated_gems.flat_map(&:tests)
27
28
  end
28
29
 
29
- def bundle_all_gems
30
- infom 'Bundling all gems...'
31
- decorated_gems.each do |gem|
32
- next unless gem.gemfile_path.exist?
33
-
34
- infov 'Bundle install', gem
35
- gem.bundle.execute!
30
+ def clear_logs
31
+ all_tests.each do |test|
32
+ test.logs.remove_all
36
33
  end
37
34
  end
38
35
 
36
+ def prepare_all_gems
37
+ infom 'Preparing all gems...'
38
+ decorated_gems.each(&:prepare)
39
+ end
40
+
39
41
  def decorated_gems_uncached
40
42
  r = gems
41
43
  r = r.select { |gem| only.include?(gem.name) } if only.present?
@@ -51,8 +53,7 @@ module EacRubyGemsUtils
51
53
  warn 'Some test did not pass:'
52
54
  failed_tests.each do |test|
53
55
  infov ' * Test', test
54
- infov ' * STDOUT', test.stdout_cache.content_path
55
- infov ' * STDERR', test.stderr_cache.content_path
56
+ info test.logs.truncate_all
56
57
  end
57
58
  else
58
59
  success 'All tests passed'
@@ -61,9 +62,11 @@ module EacRubyGemsUtils
61
62
 
62
63
  def run
63
64
  start_banner
64
- bundle_all_gems
65
+ prepare_all_gems
65
66
  test_all_gems
66
67
  final_results_banner
68
+ ensure
69
+ clear_logs
67
70
  end
68
71
 
69
72
  def start_banner
@@ -76,31 +79,6 @@ module EacRubyGemsUtils
76
79
  infov test, Result.new(test.result).tag
77
80
  end
78
81
  end
79
-
80
- class DecoratedGem < ::SimpleDelegator
81
- def tests
82
- [::EacRubyGemsUtils::Tests::Minitest.new(__getobj__),
83
- ::EacRubyGemsUtils::Tests::Rspec.new(__getobj__)]
84
- end
85
- end
86
-
87
- class Result
88
- common_constructor :result
89
-
90
- COLORS = {
91
- ::EacRubyGemsUtils::Tests::Base::RESULT_FAILED => :red,
92
- ::EacRubyGemsUtils::Tests::Base::RESULT_NONEXISTENT => :white,
93
- ::EacRubyGemsUtils::Tests::Base::RESULT_SUCCESSFUL => :green
94
- }.freeze
95
-
96
- def tag
97
- result.to_s.send(color)
98
- end
99
-
100
- def color
101
- COLORS.fetch(result)
102
- end
103
- end
104
82
  end
105
83
  end
106
84
  end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyGemsUtils
4
+ module Tests
5
+ class Multiple
6
+ class DecoratedGem < ::SimpleDelegator
7
+ enable_console_speaker
8
+
9
+ def prepare
10
+ return unless gemfile_path.exist?
11
+
12
+ log('running "bundle install"...')
13
+ return if bundle('install').execute.fetch(:exit_code).zero?
14
+
15
+ unless can_remove_gemfile_lock?
16
+ raise '"bundle install" failed and the Gemfile.lock is part of gem' \
17
+ '(Should be changed by developer)'
18
+ end
19
+
20
+ prepare_with_removable_gemfile_lock
21
+ end
22
+
23
+ def tests
24
+ [::EacRubyGemsUtils::Tests::Minitest.new(__getobj__),
25
+ ::EacRubyGemsUtils::Tests::Rspec.new(__getobj__)]
26
+ end
27
+
28
+ private
29
+
30
+ def log(message)
31
+ infov self, message
32
+ end
33
+
34
+ def prepare_with_removable_gemfile_lock
35
+ log('"bundle install" failed, removing Gemfile.lock and trying again...')
36
+ gemfile_lock_path.unlink if gemfile_lock_path.exist?
37
+ bundle('install').execute!
38
+ end
39
+
40
+ def can_remove_gemfile_lock?
41
+ !files.include?(gemfile_lock_path.relative_path_from(root))
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyGemsUtils
4
+ module Tests
5
+ class Multiple
6
+ class Result
7
+ common_constructor :result
8
+
9
+ COLORS = {
10
+ ::EacRubyGemsUtils::Tests::Base::RESULT_FAILED => :red,
11
+ ::EacRubyGemsUtils::Tests::Base::RESULT_NONEXISTENT => :white,
12
+ ::EacRubyGemsUtils::Tests::Base::RESULT_SUCCESSFUL => :green
13
+ }.freeze
14
+
15
+ def tag
16
+ result.to_s.send(color)
17
+ end
18
+
19
+ def color
20
+ COLORS.fetch(result)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyGemsUtils
4
- VERSION = '0.7.0'
4
+ VERSION = '0.9.0'
5
5
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_gems_utils/gem'
4
+
5
+ ::RSpec.describe ::EacRubyGemsUtils::Gem::VersionFile do
6
+ let(:stubs_dir) { ::Pathname.new(__dir__).join('version_file_spec_files') }
7
+ let(:stub_file) { stubs_dir.join('a_version_file.rb') }
8
+ let(:instance) { described_class.new(stub_file) }
9
+ let(:target_version) { ::Gem::Version.new('0.69.1') }
10
+
11
+ describe '#value' do
12
+ it { expect(instance.value).to eq(target_version) }
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Tools
5
+ VERSION = '0.69.1'
6
+ end
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_ruby_gems_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
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: 2020-09-02 00:00:00.000000000 Z
11
+ date: 2021-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_ruby_utils
@@ -60,10 +60,14 @@ files:
60
60
  - lib/eac_ruby_gems_utils/tests/base.rb
61
61
  - lib/eac_ruby_gems_utils/tests/minitest.rb
62
62
  - lib/eac_ruby_gems_utils/tests/multiple.rb
63
+ - lib/eac_ruby_gems_utils/tests/multiple/decorated_gem.rb
64
+ - lib/eac_ruby_gems_utils/tests/multiple/result.rb
63
65
  - lib/eac_ruby_gems_utils/tests/rspec.rb
64
66
  - lib/eac_ruby_gems_utils/version.rb
67
+ - spec/code/rubocop_check_spec.rb
68
+ - spec/lib/eac_ruby_gems_utils/gem/version_file_spec.rb
69
+ - spec/lib/eac_ruby_gems_utils/gem/version_file_spec_files/a_version_file.rb
65
70
  - spec/lib/eac_ruby_gems_utils/gem_spec.rb
66
- - spec/rubocop_check_spec.rb
67
71
  - spec/spec_helper.rb
68
72
  - spec/support/mygem/Gemfile
69
73
  - spec/support/mygem/Gemfile.lock
@@ -93,13 +97,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
97
  - !ruby/object:Gem::Version
94
98
  version: '0'
95
99
  requirements: []
96
- rubygems_version: 3.0.8
100
+ rubygems_version: 3.0.9
97
101
  signing_key:
98
102
  specification_version: 4
99
103
  summary: Utilities for Ruby gems development.
100
104
  test_files:
105
+ - spec/code/rubocop_check_spec.rb
106
+ - spec/lib/eac_ruby_gems_utils/gem/version_file_spec.rb
107
+ - spec/lib/eac_ruby_gems_utils/gem/version_file_spec_files/a_version_file.rb
101
108
  - spec/lib/eac_ruby_gems_utils/gem_spec.rb
102
- - spec/rubocop_check_spec.rb
103
109
  - spec/spec_helper.rb
104
110
  - spec/support/mygem/Gemfile
105
111
  - spec/support/mygem/Gemfile.lock