rbenv-migrate 0.1 → 0.2.1

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: 3e5126f72459cd9a3cf2203cff5f51a5d7bc563696e7ded64cb1a89fa180331c
4
+ data.tar.gz: 8505701f997514f9b9dced13c7c30f5cd64e0cabc76808608e2bdafefd6d4b4e
5
5
  SHA512:
6
- metadata.gz: '0270908d16018af97ecab7c9a0014cb00e2fcae65958feb04e302c0b0f876f2a7a42390e2c8e5217d624e0e74a40154d86ce71975381b5ba10ba4f2f224466e3'
7
- data.tar.gz: ce9295a66861ea8656c0cee0b04b66655d9e8551ccc7891f008009a867fbd00352a9173feb8e35f2fc2b5d5a7cf9dbd631106216c6bbbebdaab2c5fb6981749c
6
+ metadata.gz: 583abe4fbd75c51a7e3a69a6c4eb6cc4f166d5741bcd71d410aacf876e6b643a02568e6085feb5754054aaf1b434448b099357e00a3f1eaa6f8d810d591198b2
7
+ data.tar.gz: ec6c3cfb66a2c07ab3e96949ca94f772e87703cfed8267febd12bb2937b6432b46bdfe60818ff35f0b41e86580ef4f2624098113e8f0958ecd5cf0379d1146b9
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1
1
+ 0.2.1
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,11 @@ 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
- gem.required_ruby_version = "~> 3.0"
20
-
21
20
  gem.add_dependency "optimist", "~> 3.0"
21
+ gem.add_development_dependency "rake", "~> 13.0"
22
+ gem.add_development_dependency "rspec", "~> 3.12"
23
+ gem.add_development_dependency "fuubar", "~> 2.5"
22
24
  end
@@ -0,0 +1,123 @@
1
+ require "spec_helper"
2
+
3
+ # Arbitrary valid old version
4
+ OLD_VERSION = "2.7.8"
5
+
6
+ def set_version(version=OLD_VERSION)
7
+ ARGV.replace version.nil? ? [] : [version]
8
+ end
9
+
10
+ def args_should_trigger_help_screen(args)
11
+ it "shows the help screen" do
12
+ set_version args
13
+ expect(Optimist).to receive :educate
14
+
15
+ RBEMigrate::CLI.new
16
+ end
17
+ end
18
+
19
+ RSpec.describe RBEMigrate::CLI do
20
+ let(:cli) { described_class.new }
21
+ let(:gemspecs) { "/path/to/versions/#{OLD_VERSION}/lib/ruby/gems/*/specifications/*.gemspec" }
22
+
23
+ before(:each) do
24
+ set_version
25
+
26
+ allow(ENV).to receive(:[]).with("RBENV_ROOT").and_return("/path/to")
27
+
28
+ allow(Dir).to receive(:[]).with("/path/to/versions/**").
29
+ and_return instance_double(Dir, map: [OLD_VERSION, RUBY_VERSION])
30
+ allow(Dir).to receive(:glob).with(gemspecs).
31
+ and_return instance_double(Dir, map: %w[spec1 spec2])
32
+ end
33
+
34
+ describe "#initialize" do
35
+ context "when no argument is provided" do
36
+ args_should_trigger_help_screen nil
37
+ end
38
+
39
+ context "when an invalid argument is provided" do
40
+ args_should_trigger_help_screen "not a version"
41
+ end
42
+
43
+ context "when the current version is given as an argument" do
44
+ args_should_trigger_help_screen RUBY_VERSION
45
+ end
46
+ end
47
+
48
+ describe "#run" do
49
+ before(:each) { expect(Optimist).not_to receive :educate }
50
+
51
+ context "when there are no gems to migrate" do
52
+ it "prints a message and exits" do
53
+ allow(cli).to receive(:gemspecs_for).and_return([])
54
+ expect { cli.run }.to output(/appear to be up-to-date/).
55
+ to_stdout.and raise_error(SystemExit)
56
+ end
57
+ end
58
+
59
+ context "when there are gems to migrate" do
60
+ let(:install_command_double) { instance_double Gem::Commands::InstallCommand, execute: true }
61
+
62
+ before :each do
63
+ allow(cli).to receive(:gemspecs_for).with(OLD_VERSION).and_return(old_gems)
64
+ allow(cli).to receive(:gemspecs_for).with(RUBY_VERSION).and_return(current_gems)
65
+ allow(Gem::Commands::InstallCommand).to receive(:new).and_return(install_command_double)
66
+ end
67
+
68
+ context "when some gems are already installed on the target version" do
69
+ let(:old_gems_names) { %w[gem1 gem2 gem3 gem4] }
70
+ let(:current_gems_names) { %w[gem1 gem3 ] }
71
+ let(:result) { %w[ gem2 gem4] }
72
+
73
+ %i[old_gems current_gems].each do |var|
74
+ let var do
75
+ send(:"#{var}_names").map do |name|
76
+ Gem::Specification.new do |gem|
77
+ gem.name = name
78
+ gem.version = "0.1"
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 will be skipped
98
+ gem.required_ruby_version = "#{i == 0 ? '~>' : '>='} #{OLD_VERSION}"
99
+ end
100
+ end
101
+ end
102
+
103
+ let(:result) { %w[gem2 gem3] }
104
+
105
+ it "passes the correct gems to RubyGems" do
106
+ expect(install_command_double).to receive(:handle_options).with(result)
107
+ cli.run
108
+ end
109
+
110
+ it "outputs that it is skipping that gem" do
111
+ allow(install_command_double).to receive(:handle_options).with(result)
112
+ expect { cli.run }.to output(/skipping/).to_stderr
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ describe "#gemspecs_for" do
119
+ it "returns the gemspecs for the specified version" do
120
+ expect(cli.send(:gemspecs_for, OLD_VERSION)).to eq(%w[spec1 spec2])
121
+ end
122
+ end
123
+ 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.1
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
@@ -51,9 +95,9 @@ require_paths:
51
95
  - lib
52
96
  required_ruby_version: !ruby/object:Gem::Requirement
53
97
  requirements:
54
- - - "~>"
98
+ - - ">="
55
99
  - !ruby/object:Gem::Version
56
- version: '3.0'
100
+ version: '0'
57
101
  required_rubygems_version: !ruby/object:Gem::Requirement
58
102
  requirements:
59
103
  - - ">="
@@ -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