[前][次][番号順一覧][スレッド一覧]

ruby-changes:67438

From: David <ko1@a...>
Date: Tue, 31 Aug 2021 19:07:28 +0900 (JST)
Subject: [ruby-changes:67438] 76b77d9275 (master): [rubygems/rubygems] Refactor reseting `RUBYGEMS_GEMDEPS` in tests

https://git.ruby-lang.org/ruby.git/commit/?id=76b77d9275

From 76b77d92757affbc75b393b3a10c6815d69fd34d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...>
Date: Wed, 30 Oct 2019 16:51:38 +0100
Subject: [rubygems/rubygems] Refactor reseting `RUBYGEMS_GEMDEPS` in tests

https://github.com/rubygems/rubygems/commit/91dca11112
---
 test/rubygems/test_gem.rb | 268 ++++++++++++++++++++++------------------------
 1 file changed, 130 insertions(+), 138 deletions(-)

diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index 98cad54..d34aad7 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -19,7 +19,6 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L19
 
     common_installer_setup
 
-    ENV.delete 'RUBYGEMS_GEMDEPS'
     @additional = %w[a b].map {|d| File.join @tempdir, d }
 
     util_remove_interrupt_command
@@ -663,24 +662,22 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L662
   end
 
   def test_self_use_gemdeps
-    rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], '-'
+    with_rubygems_gemdeps('-') do
+      FileUtils.mkdir_p 'detect/a/b'
+      FileUtils.mkdir_p 'detect/a/Isolate'
 
-    FileUtils.mkdir_p 'detect/a/b'
-    FileUtils.mkdir_p 'detect/a/Isolate'
+      FileUtils.touch 'detect/Isolate'
 
-    FileUtils.touch 'detect/Isolate'
-
-    begin
-      Dir.chdir 'detect/a/b'
+      begin
+        Dir.chdir 'detect/a/b'
 
-      Gem.use_gemdeps
+        Gem.use_gemdeps
 
-      assert_equal add_bundler_full_name([]), loaded_spec_names
-    ensure
-      Dir.chdir @tempdir
+        assert_equal add_bundler_full_name([]), loaded_spec_names
+      ensure
+        Dir.chdir @tempdir
+      end
     end
-  ensure
-    ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
   end
 
   def test_self_dir
@@ -1690,11 +1687,11 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1687
       f.puts "gem 'c'"
     end
 
-    ENV['RUBYGEMS_GEMDEPS'] = path
-
-    Gem.use_gemdeps
+    with_rubygems_gemdeps(path) do
+      Gem.use_gemdeps
 
-    assert_equal add_bundler_full_name(%W[a-1 b-1 c-1]), loaded_spec_names
+      assert_equal add_bundler_full_name(%W[a-1 b-1 c-1]), loaded_spec_names
+    end
   end
 
   def test_auto_activation_of_used_gemdeps_file
@@ -1712,13 +1709,13 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1709
       f.puts "gem 'c'"
     end
 
-    ENV['RUBYGEMS_GEMDEPS'] = "-"
-
-    expected_specs = [a, b, util_spec("bundler", Bundler::VERSION), c].compact.map(&:full_name)
+    with_rubygems_gemdeps("-") do
+      expected_specs = [a, b, util_spec("bundler", Bundler::VERSION), c].compact.map(&:full_name)
 
-    Gem.use_gemdeps
+      Gem.use_gemdeps
 
-    assert_equal expected_specs, loaded_spec_names
+      assert_equal expected_specs, loaded_spec_names
+    end
   end
 
   BUNDLER_LIB_PATH = File.expand_path $LOAD_PATH.find {|lp| File.file?(File.join(lp, "bundler.rb")) }
@@ -1753,29 +1750,30 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1750
     install_gem c, :install_dir => path
 
     ENV['GEM_PATH'] = path
-    ENV['RUBYGEMS_GEMDEPS'] = "-"
 
-    new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
-    new_RUBYOPT = "-I#{rubygems_path} -I#{BUNDLER_LIB_PATH}"
+    with_rubygems_gemdeps("-") do
+      new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
+      new_RUBYOPT = "-I#{rubygems_path} -I#{BUNDLER_LIB_PATH}"
 
-    path = File.join @tempdir, "gem.deps.rb"
+      path = File.join @tempdir, "gem.deps.rb"
 
-    File.open path, "w" do |f|
-      f.puts "gem 'a'"
-    end
-    out0 = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
-      IO.popen("foo", &:read).split(/\n/)
-    end
+      File.open path, "w" do |f|
+        f.puts "gem 'a'"
+      end
+      out0 = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
+        IO.popen("foo", &:read).split(/\n/)
+      end
 
-    File.open path, "a" do |f|
-      f.puts "gem 'b'"
-      f.puts "gem 'c'"
-    end
-    out = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
-      IO.popen("foo", &:read).split(/\n/)
-    end
+      File.open path, "a" do |f|
+        f.puts "gem 'b'"
+        f.puts "gem 'c'"
+      end
+      out = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
+        IO.popen("foo", &:read).split(/\n/)
+      end
 
-    assert_equal ["b-1", "c-1"], out - out0
+      assert_equal ["b-1", "c-1"], out - out0
+    end
   end
 
   def test_looks_for_gemdeps_files_automatically_from_binstubs_in_parent_dir
@@ -1801,33 +1799,34 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1799
     install_gem c, :install_dir => path
 
     ENV['GEM_PATH'] = path
-    ENV['RUBYGEMS_GEMDEPS'] = "-"
 
-    Dir.mkdir "sub1"
+    with_rubygems_gemdeps("-") do
+      Dir.mkdir "sub1"
 
-    new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
-    new_RUBYOPT = "-I#{rubygems_path} -I#{BUNDLER_LIB_PATH}"
+      new_PATH = [File.join(path, "bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
+      new_RUBYOPT = "-I#{rubygems_path} -I#{BUNDLER_LIB_PATH}"
 
-    path = File.join @tempdir, "gem.deps.rb"
+      path = File.join @tempdir, "gem.deps.rb"
 
-    File.open path, "w" do |f|
-      f.puts "gem 'a'"
-    end
-    out0 = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
-      IO.popen("foo", :chdir => "sub1", &:read).split(/\n/)
-    end
+      File.open path, "w" do |f|
+        f.puts "gem 'a'"
+      end
+      out0 = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
+        IO.popen("foo", :chdir => "sub1", &:read).split(/\n/)
+      end
 
-    File.open path, "a" do |f|
-      f.puts "gem 'b'"
-      f.puts "gem 'c'"
-    end
-    out = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
-      IO.popen("foo", :chdir => "sub1", &:read).split(/\n/)
-    end
+      File.open path, "a" do |f|
+        f.puts "gem 'b'"
+        f.puts "gem 'c'"
+      end
+      out = with_path_and_rubyopt(new_PATH, new_RUBYOPT) do
+        IO.popen("foo", :chdir => "sub1", &:read).split(/\n/)
+      end
 
-    Dir.rmdir "sub1"
+      Dir.rmdir "sub1"
 
-    assert_equal ["b-1", "c-1"], out - out0
+      assert_equal ["b-1", "c-1"], out - out0
+    end
   end
 
   def test_register_default_spec
@@ -1891,21 +1890,19 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1890
   end
 
   def test_use_gemdeps_ENV
-    rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], nil
-
-    spec = util_spec 'a', 1
+    with_rubygems_gemdeps(nil) do
+      spec = util_spec 'a', 1
 
-    refute spec.activated?
+      refute spec.activated?
 
-    File.open 'gem.deps.rb', 'w' do |io|
-      io.write 'gem "a"'
-    end
+      File.open 'gem.deps.rb', 'w' do |io|
+        io.write 'gem "a"'
+      end
 
-    Gem.use_gemdeps
+      Gem.use_gemdeps
 
-    refute spec.activated?
-  ensure
-    ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
+      refute spec.activated?
+    end
   end
 
   def test_use_gemdeps_argument_missing
@@ -1918,109 +1915,96 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1915
   end
 
   def test_use_gemdeps_argument_missing_match_ENV
-    rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] =
-      ENV['RUBYGEMS_GEMDEPS'], 'gem.deps.rb'
+    with_rubygems_gemdeps('gem.deps.rb') do
+      e = assert_raise ArgumentError do
+        Gem.use_gemdeps 'gem.deps.rb'
+      end
 
-    e = assert_raise ArgumentError do
-      Gem.use_gemdeps 'gem.deps.rb'
+      assert_equal 'Unable to find gem dependencies file at gem.deps.rb',
+                   e.message
     end
-
-    assert_equal 'Unable to find gem dependencies file at gem.deps.rb',
-                 e.message
-  ensure
-    ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
   end
 
   def test_use_gemdeps_automatic
-    rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], '-'
-
-    spec = util_spec 'a', 1
-    install_specs spec
-    spec = Gem::Specification.find {|s| s == spec }
+    with_rubygems_gemdeps('-') do
+      spec = util_spec 'a', 1
+      install_specs spec
+      spec = Gem::Specification.find {|s| s == spec }
 
-    refute spec.activated?
+      refute spec.activated?
 
-    File.open 'Gemfile', 'w' do |io|
-      io.write 'gem "a"'
-    end
+      File.open 'Gemfile', 'w' do |io|
+        io.write 'gem "a"'
+      end
 
-    Gem.use_gemdeps
+      Gem.use_gemdeps
 
-    assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
-  ensure
-    ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
+      assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
+    end
   end
 
   def test_use_gemdeps_automatic_missing
-    rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], '-'
-
-    Gem.use_gemdeps
+    with_rubygems_gemdeps('-') do
+      Gem.use_gemdeps
 
-    assert true # count
-  ensure
-    ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
+      assert true # count
+    end
   end
 
   def test_use_gemdeps_disabled
-    rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], ''
+    with_rubygems_gemdeps('') do
+      spec = util_spec 'a', 1
 
-    spec = util_spec 'a', 1
+      refute spec.activated?
 
-    refute spec.activated?
-
-    File.open 'gem.deps.rb', 'w' do |io|
-      io.write 'gem "a"'
-    end
+      File.open 'gem.deps.rb', 'w' do |io|
+        io.write 'gem "a"'
+      end
 
-    Gem.use_gemdeps
+      Gem.use_gemdeps
 
-    refute spec.activated?
-  ensure
-    ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
+      refute spec.activated?
+    end
   end
 
   def test_use_gemdeps_missing_gem
-    rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], 'x'
-
-    File.open 'x', 'w' do |io|
-      io.write 'gem "a"'
-    end
+    with_ruby (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]