rbenv-migrate 0.1 → 0.2

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: 4ecdf659d12926e87bfcb55be76aea2f76382e41c2b846d67edb2d4606f6705a
4
- data.tar.gz: a0bd87a26684ef260fe59b2eabb8e2704eece12d2e601057787c9c091ea34e5d
3
+ metadata.gz: 49145e22acf7d4b7af8be7c2569f25b95b66403c28497edebc7f90bc006254ef
4
+ data.tar.gz: 784858699e46829747ce23c4359e5720ee685253c26d5c900a0ef605069d25be
5
5
  SHA512:
6
- metadata.gz: '0270908d16018af97ecab7c9a0014cb00e2fcae65958feb04e302c0b0f876f2a7a42390e2c8e5217d624e0e74a40154d86ce71975381b5ba10ba4f2f224466e3'
7
- data.tar.gz: ce9295a66861ea8656c0cee0b04b66655d9e8551ccc7891f008009a867fbd00352a9173feb8e35f2fc2b5d5a7cf9dbd631106216c6bbbebdaab2c5fb6981749c
6
+ metadata.gz: b32e825c07fa1f0c50071c322b62120f0abac62a85d9953501d49fe91a9adb827ff3ecd714a179c925590359ab1c9713d5a508d4b4e611bc6dbec410abf70bdf
7
+ data.tar.gz: a561957be5b6dc85c8367696a9eba8233c2e6516f8798a79fcbaf0bc17f6bfbe5e13915104871c4bb578f70b0c2695d19ea4c4fbf6259fb62e622d0dfb41d16f
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1
1
+ 0.2
data/lib/rbenv_migrate.rb CHANGED
@@ -15,14 +15,25 @@ module RBEMigrate
15
15
  educate_on_error
16
16
  end
17
17
 
18
- Optimist::educate if ARGV.empty?
19
-
20
18
  @old_version = ARGV.first
19
+
20
+ if @old_version.nil? || @old_version == RUBY_VERSION ||
21
+ !Dir["#{ENV['RBENV_ROOT']}/versions/**"].map { |f| File.basename f }.include?(@old_version)
22
+ Optimist::educate
23
+ end
21
24
  end
22
25
 
23
26
  def run
24
- old_gems = gemspecs_for @old_version
25
- current_gems = gemspecs_for RUBY_VERSION
27
+ old_gems = gemspecs_for(@old_version).select do |gem|
28
+ if gem.required_ruby_version =~ Gem::Version.new(RUBY_VERSION)
29
+ true
30
+ else
31
+ $stderr.puts "#{gem.name} #{gem.version} is not compatible with Ruby #{RUBY_VERSION}, skipping."
32
+ false
33
+ end
34
+ end.map(&:name)
35
+
36
+ current_gems = gemspecs_for(RUBY_VERSION).map(&:name)
26
37
 
27
38
  if (gems_to_install = old_gems - current_gems).any?
28
39
  command = Gem::Commands::InstallCommand.new.tap { |c| c.handle_options gems_to_install }
@@ -43,7 +54,7 @@ module RBEMigrate
43
54
 
44
55
  def gemspecs_for(version)
45
56
  gemspecs = "#{ENV['RBENV_ROOT']}/versions/#{version}/lib/ruby/gems/*/specifications/*.gemspec"
46
- Dir.glob(File.join gemspecs).map { |s| Gem::Specification.load(s).name }
57
+ Dir.glob(File.join gemspecs).map { |s| Gem::Specification.load(s) }
47
58
  end
48
59
  end
49
60
  end
@@ -14,9 +14,13 @@ Gem::Specification.new do |gem|
14
14
  gem.bindir = "bin"
15
15
  gem.executables = %w[rbenv-migrate]
16
16
  gem.require_paths = %w[lib]
17
+ gem.test_files = Dir["spec/**/*"]
17
18
  gem.files = `git ls-files -z`.split "\x0"
18
19
 
19
20
  gem.required_ruby_version = "~> 3.0"
20
21
 
21
22
  gem.add_dependency "optimist", "~> 3.0"
23
+ gem.add_development_dependency "rake", "~> 13.0"
24
+ gem.add_development_dependency "rspec", "~> 3.12"
25
+ gem.add_development_dependency "fuubar", "~> 2.5"
22
26
  end
@@ -0,0 +1,117 @@
1
+ require "spec_helper"
2
+ require "stringio"
3
+
4
+ # Arbitrary valid old version
5
+ OLD_VERSION = "2.7.8"
6
+
7
+ def set_version(version=OLD_VERSION)
8
+ ARGV.replace version.nil? ? [] : [version]
9
+ end
10
+
11
+ def args_should_trigger_help_screen(args)
12
+ it "shows the help screen" do
13
+ set_version args
14
+ expect(Optimist).to receive :educate
15
+
16
+ RBEMigrate::CLI.new
17
+ end
18
+ end
19
+
20
+ RSpec.describe RBEMigrate::CLI do
21
+ let(:cli) { described_class.new }
22
+ let(:gemspecs) { "/path/to/versions/#{OLD_VERSION}/lib/ruby/gems/*/specifications/*.gemspec" }
23
+
24
+ before(:each) do
25
+ set_version
26
+
27
+ allow(ENV).to receive(:[]).with("RBENV_ROOT").and_return("/path/to")
28
+
29
+ allow(Dir).to receive(:[]).with("/path/to/versions/**").
30
+ and_return instance_double(Dir, map: [OLD_VERSION, RUBY_VERSION])
31
+ allow(Dir).to receive(:glob).with(gemspecs).
32
+ and_return instance_double(Dir, map: %w[spec1 spec2])
33
+ end
34
+
35
+ describe "#initialize" do
36
+ context "when no argument is provided" do
37
+ args_should_trigger_help_screen nil
38
+ end
39
+
40
+ context "when an invalid argument is provided" do
41
+ args_should_trigger_help_screen "not a version"
42
+ end
43
+
44
+ context "when the current version is given as an argument" do
45
+ args_should_trigger_help_screen RUBY_VERSION
46
+ end
47
+ end
48
+
49
+ describe "#run" do
50
+ context "when there are no gems to migrate" do
51
+ it "prints a message and exits" do
52
+ allow(cli).to receive(:gemspecs_for).and_return([])
53
+ expect { cli.run }.to output(/appear to be up-to-date/).
54
+ to_stdout.and raise_error(SystemExit)
55
+ end
56
+ end
57
+
58
+ context "when there are gems to migrate" do
59
+ let(:install_command_double) { instance_double Gem::Commands::InstallCommand, execute: true }
60
+
61
+ before :each do
62
+ allow(cli).to receive(:gemspecs_for).with(OLD_VERSION).and_return(old_gems)
63
+ allow(cli).to receive(:gemspecs_for).with(RUBY_VERSION).and_return(current_gems)
64
+ allow(Gem::Commands::InstallCommand).to receive(:new).and_return(install_command_double)
65
+ end
66
+
67
+ context "when some gems are already installed on the target version" do
68
+ let(:old_gems_names) { %w[gem1 gem2 gem3 gem4] }
69
+ let(:current_gems_names) { %w[gem1 gem3 ] }
70
+ let(:result) { %w[ gem2 gem4] }
71
+
72
+ %i[old_gems current_gems].each do |var|
73
+ let var do
74
+ send(:"#{var}_names").map do |name|
75
+ Gem::Specification.new do |gem|
76
+ gem.name = name
77
+ gem.version = "0.1"
78
+ gem.required_ruby_version = ">= #{OLD_VERSION}"
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ it "passes the correct gems to RubyGems" do
85
+ expect(install_command_double).to receive(:handle_options).with(result)
86
+ expect { cli.run }.not_to output(/skipping/).to_stdout
87
+ end
88
+ end
89
+
90
+ context "when an old gem is incompatible" do
91
+ let(:current_gems) { [] }
92
+ let :old_gems do
93
+ %w[gem1 gem2 gem3].each_with_index.map do |name, i|
94
+ Gem::Specification.new do |gem|
95
+ gem.name = name
96
+ gem.version = "0.1"
97
+ # First one tested will be skipped
98
+ gem.required_ruby_version = "#{i == 0 ? '~>' : '>='} #{OLD_VERSION}"
99
+ end
100
+ end
101
+ end
102
+ let(:result) { %w[gem2 gem3] }
103
+
104
+ it "passes the correct gems to RubyGems" do
105
+ allow(install_command_double).to receive(:handle_options).with(result)
106
+ expect { cli.run }.to output(/skipping/).to_stderr
107
+ end
108
+ end
109
+ end
110
+ end
111
+
112
+ describe "#gemspecs_for" do
113
+ it "returns the gemspecs for the specified version" do
114
+ expect(cli.send(:gemspecs_for, OLD_VERSION)).to eq(%w[spec1 spec2])
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,28 @@
1
+ require "rbenv_migrate"
2
+
3
+ # Include all files in spec/support
4
+ Dir[File.expand_path("../support/**/*.rb", __FILE__)].each { |f| require f }
5
+
6
+ RSpec.configure do |config|
7
+ # Add `focus: true` hash parameter to a describe/context/it block
8
+ # to only run the specs in that block
9
+ config.filter_run_when_matching :focus
10
+
11
+ # Fuubar
12
+ config.add_formatter "Fuubar"
13
+ config.fuubar_progress_bar_options = { format: " %c/%C |%b>%i|%e " }
14
+
15
+ # More verbose output if only running one spec
16
+ config.default_formatter = "doc" if config.files_to_run.one?
17
+
18
+ # Print the 10 slowest examples and example groups at the
19
+ # end of the spec run, to help surface which specs are running
20
+ # particularly slow.
21
+ config.profile_examples = 10
22
+
23
+ # Run specs in random order to surface order dependencies. If you find an
24
+ # order dependency and want to debug it, fix the order by providing the seed,
25
+ # which is printed after each run, e.g. --seed 1234
26
+ config.order = :random
27
+ Kernel.srand config.seed
28
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbenv-migrate
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vinny Diehl
@@ -24,6 +24,48 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fuubar
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.5'
27
69
  description: Installs all of your gems from an old version of Ruby so that you may
28
70
  uninstall it.
29
71
  email: vinny.diehl@gmail.com
@@ -41,6 +83,8 @@ files:
41
83
  - bin/rbenv-migrate
42
84
  - lib/rbenv_migrate.rb
43
85
  - rbenv-migrate.gemspec
86
+ - spec/migrate_spec.rb
87
+ - spec/spec_helper.rb
44
88
  homepage: https://github.com/vinnydiehl/rbenv-migrate
45
89
  licenses:
46
90
  - MIT
@@ -64,4 +108,6 @@ rubygems_version: 3.4.10
64
108
  signing_key:
65
109
  specification_version: 4
66
110
  summary: Transfer your gems from old rbenv installs.
67
- test_files: []
111
+ test_files:
112
+ - spec/migrate_spec.rb
113
+ - spec/spec_helper.rb