From 678d58c8508ec46aa270e3c5d81fc09cd0fee175 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Fri, 1 Apr 2022 20:36:59 +0900 Subject: [PATCH] Merge rubygems master 1e4eda741d732ca1bd7031aef0a16c7348adf7a5 --- lib/bundler.rb | 2 +- lib/bundler/build_metadata.rb | 2 +- lib/bundler/cli.rb | 2 +- lib/bundler/cli/info.rb | 2 +- lib/bundler/cli/init.rb | 2 +- lib/bundler/cli/show.rb | 2 +- lib/bundler/installer.rb | 4 +-- lib/bundler/shared_helpers.rb | 6 ++-- lib/bundler/source/metadata.rb | 2 +- lib/bundler/templates/Executable | 6 ++-- lib/bundler/templates/Executable.bundler | 2 +- lib/bundler/templates/Executable.standalone | 6 ++-- .../templates/newgem/newgem.gemspec.tt | 2 +- lib/rubygems.rb | 2 +- lib/rubygems/commands/setup_command.rb | 2 +- lib/rubygems/ext/ext_conf_builder.rb | 2 +- lib/rubygems/request.rb | 2 +- libexec/bundler | 2 +- spec/bundler/commands/install_spec.rb | 2 +- spec/bundler/commands/update_spec.rb | 30 +++++++++---------- spec/bundler/install/gemfile/git_spec.rb | 8 ++--- spec/bundler/install/gemfile/path_spec.rb | 2 +- .../install/gems/compact_index_spec.rb | 2 +- spec/bundler/install/gems/resolving_spec.rb | 6 ++-- spec/bundler/install/gems/standalone_spec.rb | 4 +-- spec/bundler/install/gems/sudo_spec.rb | 2 +- spec/bundler/lock/lockfile_spec.rb | 2 +- test/rubygems/helper.rb | 2 +- test/rubygems/test_gem.rb | 2 +- test/rubygems/test_gem_command_manager.rb | 2 +- .../test_gem_commands_help_command.rb | 2 +- .../test_gem_commands_setup_command.rb | 2 +- .../rubygems/test_gem_dependency_installer.rb | 4 +-- test/rubygems/test_gem_ext_builder.rb | 2 +- test/rubygems/test_gem_ext_cargo_builder.rb | 6 ++-- .../custom_name/build.rb | 6 ++-- .../rust_ruby_example/build.rb | 6 ++-- test/rubygems/test_gem_specification.rb | 2 +- test/rubygems/test_project_sanity.rb | 2 +- test/rubygems/test_require.rb | 2 +- 40 files changed, 72 insertions(+), 76 deletions(-) diff --git a/lib/bundler.rb b/lib/bundler.rb index 0025dee720..47b352177d 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -370,7 +370,7 @@ EOF if env.key?("RUBYLIB") rubylib = env["RUBYLIB"].split(File::PATH_SEPARATOR) - rubylib.delete(File.expand_path("..", __FILE__)) + rubylib.delete(__dir__) env["RUBYLIB"] = rubylib.join(File::PATH_SEPARATOR) end diff --git a/lib/bundler/build_metadata.rb b/lib/bundler/build_metadata.rb index 0846e82e06..8bffb2fae7 100644 --- a/lib/bundler/build_metadata.rb +++ b/lib/bundler/build_metadata.rb @@ -27,7 +27,7 @@ module Bundler # If Bundler has been installed without its .git directory and without a # commit instance variable then we can't determine its commits SHA. - git_dir = File.join(File.expand_path("../../../..", __FILE__), ".git") + git_dir = File.expand_path("../../../.git", __dir__) if File.directory?(git_dir) return @git_commit_sha = Dir.chdir(git_dir) { `git rev-parse --short HEAD`.strip.freeze } end diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 922ba469a4..e1c284130b 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -610,7 +610,7 @@ module Bundler private :gem def self.source_root - File.expand_path(File.join(File.dirname(__FILE__), "templates")) + File.expand_path("templates", __dir__) end desc "clean [OPTIONS]", "Cleans up unused gems in your bundler directory", :hide => true diff --git a/lib/bundler/cli/info.rb b/lib/bundler/cli/info.rb index 38bc008cb5..0545ce8c75 100644 --- a/lib/bundler/cli/info.rb +++ b/lib/bundler/cli/info.rb @@ -47,7 +47,7 @@ module Bundler def print_gem_path(spec) name = spec.name if name == "bundler" - path = File.expand_path("../../../..", __FILE__) + path = File.expand_path("../../..", __dir__) else path = spec.full_gem_path if spec.deleted_gem? diff --git a/lib/bundler/cli/init.rb b/lib/bundler/cli/init.rb index d851d02d42..e4f8229c48 100644 --- a/lib/bundler/cli/init.rb +++ b/lib/bundler/cli/init.rb @@ -32,7 +32,7 @@ module Bundler file << spec.to_gemfile end else - FileUtils.cp(File.expand_path("../../templates/#{gemfile}", __FILE__), gemfile) + FileUtils.cp(File.expand_path("../templates/#{gemfile}", __dir__), gemfile) end puts "Writing new #{gemfile} to #{SharedHelpers.pwd}/#{gemfile}" diff --git a/lib/bundler/cli/show.rb b/lib/bundler/cli/show.rb index 5eaaba1ef7..2df13db1fa 100644 --- a/lib/bundler/cli/show.rb +++ b/lib/bundler/cli/show.rb @@ -18,7 +18,7 @@ module Bundler if gem_name if gem_name == "bundler" - path = File.expand_path("../../../..", __FILE__) + path = File.expand_path("../../..", __dir__) else spec = Bundler::CLI::Common.select_spec(gem_name, :regex_match) return unless spec diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index 61bf1e06d4..ca9df4a21e 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -119,7 +119,7 @@ module Bundler relative_gemfile_path = relative_gemfile_path ruby_command = Thor::Util.ruby_command ruby_command = ruby_command - template_path = File.expand_path("../templates/Executable", __FILE__) + template_path = File.expand_path("templates/Executable", __dir__) if spec.name == "bundler" template_path += ".bundler" spec.executables = %(bundle) @@ -172,7 +172,7 @@ module Bundler end standalone_path = Bundler.root.join(path).relative_path_from(bin_path) standalone_path = standalone_path - template = File.read(File.expand_path("../templates/Executable.standalone", __FILE__)) + template = File.read(File.expand_path("templates/Executable.standalone", __dir__)) ruby_command = Thor::Util.ruby_command ruby_command = ruby_command diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index ed0b072b65..ffdbdee503 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -274,10 +274,10 @@ module Bundler def set_bundle_variables # bundler exe & lib folders have same root folder, typical gem installation - exe_file = File.expand_path("../../../exe/bundle", __FILE__) + exe_file = File.expand_path("../../exe/bundle", __dir__) # for Ruby core repository testing - exe_file = File.expand_path("../../../libexec/bundle", __FILE__) unless File.exist?(exe_file) + exe_file = File.expand_path("../../libexec/bundle", __dir__) unless File.exist?(exe_file) # bundler is a default gem, exe path is separate exe_file = Bundler.rubygems.bin_path("bundler", "bundle", VERSION) unless File.exist?(exe_file) @@ -309,7 +309,7 @@ module Bundler end def bundler_ruby_lib - resolve_path File.expand_path("../..", __FILE__) + File.expand_path("..", __dir__) end def clean_load_path diff --git a/lib/bundler/source/metadata.rb b/lib/bundler/source/metadata.rb index 8bdbaa5527..524afd750a 100644 --- a/lib/bundler/source/metadata.rb +++ b/lib/bundler/source/metadata.rb @@ -22,7 +22,7 @@ module Bundler s.summary = "The best way to manage your application's dependencies" s.executables = %w[bundle] # can't point to the actual gemspec or else the require paths will be wrong - s.loaded_from = File.expand_path("..", __FILE__) + s.loaded_from = __dir__ end if local_spec = Bundler.rubygems.find_bundler(VERSION) diff --git a/lib/bundler/templates/Executable b/lib/bundler/templates/Executable index 3e8d5b317a..f6487e3c89 100644 --- a/lib/bundler/templates/Executable +++ b/lib/bundler/templates/Executable @@ -8,11 +8,9 @@ # this file is here to facilitate running it. # -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../<%= relative_gemfile_path %>", - Pathname.new(__FILE__).realpath) +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("<%= relative_gemfile_path %>", __dir__) -bundle_binstub = File.expand_path("../bundle", __FILE__) +bundle_binstub = File.expand_path("bundle", __dir__) if File.file?(bundle_binstub) if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ diff --git a/lib/bundler/templates/Executable.bundler b/lib/bundler/templates/Executable.bundler index 6bb5c51090..51650c7664 100644 --- a/lib/bundler/templates/Executable.bundler +++ b/lib/bundler/templates/Executable.bundler @@ -41,7 +41,7 @@ m = Module.new do gemfile = ENV["BUNDLE_GEMFILE"] return gemfile if gemfile && !gemfile.empty? - File.expand_path("../<%= relative_gemfile_path %>", __FILE__) + File.expand_path("<%= relative_gemfile_path %>", __dir__) end def lockfile diff --git a/lib/bundler/templates/Executable.standalone b/lib/bundler/templates/Executable.standalone index 4bf0753f44..d591e3fc04 100644 --- a/lib/bundler/templates/Executable.standalone +++ b/lib/bundler/templates/Executable.standalone @@ -6,9 +6,7 @@ # this file is here to facilitate running it. # -require "pathname" -path = Pathname.new(__FILE__) -$:.unshift File.expand_path "../<%= standalone_path %>", path.realpath +$:.unshift File.expand_path "<%= standalone_path %>", __dir__ require "bundler/setup" -load File.expand_path "../<%= executable_path %>", path.realpath +load File.expand_path "<%= executable_path %>", __dir__ diff --git a/lib/bundler/templates/newgem/newgem.gemspec.tt b/lib/bundler/templates/newgem/newgem.gemspec.tt index 546a28b78a..ceb2e9b28d 100644 --- a/lib/bundler/templates/newgem/newgem.gemspec.tt +++ b/lib/bundler/templates/newgem/newgem.gemspec.tt @@ -24,7 +24,7 @@ Gem::Specification.new do |spec| # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. - spec.files = Dir.chdir(File.expand_path(__dir__)) do + spec.files = Dir.chdir(__dir__) do `git ls-files -z`.split("\x0").reject do |f| (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)}) end diff --git a/lib/rubygems.rb b/lib/rubygems.rb index 1f706b004f..d2c404d7d3 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -112,7 +112,7 @@ require_relative 'rubygems/errors' # -The RubyGems Team module Gem - RUBYGEMS_DIR = File.dirname File.expand_path(__FILE__) + RUBYGEMS_DIR = __dir__ # Taint support is deprecated in Ruby 2.7. # This allows switching ".untaint" to ".tap(&Gem::UNTAINT)", diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb index 01714f0342..7b6890013c 100644 --- a/lib/rubygems/commands/setup_command.rb +++ b/lib/rubygems/commands/setup_command.rb @@ -341,7 +341,7 @@ By default, this RubyGems will install gem as: fake_spec = Gem::Specification.new 'rubygems', Gem::VERSION def fake_spec.full_gem_path - File.expand_path '../../../..', __FILE__ + File.expand_path '../../..', __dir__ end generate_ri = options[:document].include? 'ri' diff --git a/lib/rubygems/ext/ext_conf_builder.rb b/lib/rubygems/ext/ext_conf_builder.rb index 3ca3463615..3e8aa950c9 100644 --- a/lib/rubygems/ext/ext_conf_builder.rb +++ b/lib/rubygems/ext/ext_conf_builder.rb @@ -39,7 +39,7 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder # workaround for https://github.com/oracle/truffleruby/issues/2115 siteconf_path = RUBY_ENGINE == "truffleruby" ? siteconf.path.dup : siteconf.path require "shellwords" - cmd = Gem.ruby.shellsplit << "-I" << File.expand_path("../../..", __FILE__) << + cmd = Gem.ruby.shellsplit << "-I" << File.expand_path('../..', __dir__) << "-r" << get_relative_path(siteconf_path, extension_dir) << File.basename(extension) cmd.push(*args) diff --git a/lib/rubygems/request.rb b/lib/rubygems/request.rb index d6100c914b..136b154bee 100644 --- a/lib/rubygems/request.rb +++ b/lib/rubygems/request.rb @@ -39,7 +39,7 @@ class Gem::Request def cert_files; @connection_pool.cert_files; end def self.get_cert_files - pattern = File.expand_path("./ssl_certs/*/*.pem", File.dirname(__FILE__)) + pattern = File.expand_path("./ssl_certs/*/*.pem", __dir__) Dir.glob(pattern) end diff --git a/libexec/bundler b/libexec/bundler index d9131fe834..a6826a8c89 100755 --- a/libexec/bundler +++ b/libexec/bundler @@ -1,4 +1,4 @@ #!/usr/bin/env ruby # frozen_string_literal: true -load File.expand_path("../bundle", __FILE__) +load File.expand_path("bundle", __dir__) diff --git a/spec/bundler/commands/install_spec.rb b/spec/bundler/commands/install_spec.rb index 9e06c51a08..f189a70b10 100644 --- a/spec/bundler/commands/install_spec.rb +++ b/spec/bundler/commands/install_spec.rb @@ -798,7 +798,7 @@ RSpec.describe "bundle install with gem sources" do it "includes the standalone path" do bundle "binstubs rack", :standalone => true standalone_line = File.read(bundled_app("bin/rackup")).each_line.find {|line| line.include? "$:.unshift" }.strip - expect(standalone_line).to eq %($:.unshift File.expand_path "../../bundle", path.realpath) + expect(standalone_line).to eq %($:.unshift File.expand_path "../bundle", __dir__) end end diff --git a/spec/bundler/commands/update_spec.rb b/spec/bundler/commands/update_spec.rb index ee5d53c527..d013d5bd73 100644 --- a/spec/bundler/commands/update_spec.rb +++ b/spec/bundler/commands/update_spec.rb @@ -1147,7 +1147,7 @@ RSpec.describe "bundle update --bundler" do end it "updates the bundler version in the lockfile without re-resolving if the highest version is already installed" do - system_gems "bundler-2.3.3" + system_gems "bundler-2.3.9" build_repo4 do build_gem "rack", "1.0" @@ -1157,7 +1157,7 @@ RSpec.describe "bundle update --bundler" do source "#{file_uri_for(gem_repo4)}" gem "rack" G - lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, "2.3.3") + lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, "2.3.9") bundle :update, :bundler => true, :artifice => "compact_index", :verbose => true expect(out).to include("Using bundler #{Bundler::VERSION}") @@ -1182,7 +1182,7 @@ RSpec.describe "bundle update --bundler" do end it "updates the bundler version in the lockfile even if the latest version is not installed", :ruby_repo, :realworld do - pristine_system_gems "bundler-2.3.3" + pristine_system_gems "bundler-2.3.9" build_repo4 do build_gem "rack", "1.0" @@ -1192,16 +1192,16 @@ RSpec.describe "bundle update --bundler" do source "#{file_uri_for(gem_repo4)}" gem "rack" G - lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, "2.3.3") + lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, "2.3.9") bundle :update, :bundler => true, :artifice => "vcr", :verbose => true # Only updates properly on modern RubyGems. if Gem.rubygems_version >= Gem::Version.new("3.3.0.dev") - expect(out).to include("Updating bundler to 2.3.4") - expect(out).to include("Using bundler 2.3.4") - expect(out).not_to include("Installing Bundler 2.3.3 and restarting using that version.") + expect(out).to include("Updating bundler to 2.3.10") + expect(out).to include("Using bundler 2.3.10") + expect(out).not_to include("Installing Bundler 2.3.9 and restarting using that version.") expect(lockfile).to eq <<~L GEM @@ -1216,17 +1216,17 @@ RSpec.describe "bundle update --bundler" do rack BUNDLED WITH - 2.3.4 + 2.3.10 L - expect(the_bundle).to include_gems "bundler 2.3.4" + expect(the_bundle).to include_gems "bundler 2.3.10" end expect(the_bundle).to include_gems "rack 1.0" end it "errors if the explicit target version does not exist", :realworld do - pristine_system_gems "bundler-2.3.3" + pristine_system_gems "bundler-2.3.9" build_repo4 do build_gem "rack", "1.0" @@ -1236,7 +1236,7 @@ RSpec.describe "bundle update --bundler" do source "#{file_uri_for(gem_repo4)}" gem "rack" G - lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, "2.3.3") + lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, "2.3.9") bundle :update, :bundler => "999.999.999", :artifice => "vcr", :raise_on_error => false @@ -1286,7 +1286,7 @@ RSpec.describe "bundle update --bundler" do end it "does not touch the network if not necessary" do - system_gems "bundler-2.3.3" + system_gems "bundler-2.3.9" build_repo4 do build_gem "rack", "1.0" @@ -1297,7 +1297,7 @@ RSpec.describe "bundle update --bundler" do gem "rack" G - bundle :update, :bundler => "2.3.3", :raise_on_error => false + bundle :update, :bundler => "2.3.9", :raise_on_error => false expect(out).not_to include("Fetching gem metadata from https://rubygems.org/") @@ -1317,10 +1317,10 @@ RSpec.describe "bundle update --bundler" do rack BUNDLED WITH - 2.3.3 + 2.3.9 L - expect(out).to include("Using bundler 2.3.3") + expect(out).to include("Using bundler 2.3.9") end end end diff --git a/spec/bundler/install/gemfile/git_spec.rb b/spec/bundler/install/gemfile/git_spec.rb index 365a84f39e..07995d013b 100644 --- a/spec/bundler/install/gemfile/git_spec.rb +++ b/spec/bundler/install/gemfile/git_spec.rb @@ -1180,7 +1180,7 @@ RSpec.describe "bundle install with git sources" do s.extensions << "Rakefile" s.write "Rakefile", <<-RUBY task :default do - path = File.expand_path("../lib", __FILE__) + path = File.expand_path("lib", __dir__) FileUtils.mkdir_p(path) File.open("\#{path}/foo.rb", "w") do |f| f.puts "FOO = 'YES'" @@ -1273,7 +1273,7 @@ In Gemfile: s.extensions << "Rakefile" s.write "Rakefile", <<-RUBY task :default do - path = File.expand_path("../lib", __FILE__) + path = File.expand_path("lib", __dir__) FileUtils.mkdir_p(path) cur_time = Time.now.to_f.to_s File.open("\#{path}/foo.rb", "w") do |f| @@ -1314,7 +1314,7 @@ In Gemfile: s.extensions << "Rakefile" s.write "Rakefile", <<-RUBY task :default do - path = File.expand_path("../lib", __FILE__) + path = File.expand_path("lib", __dir__) FileUtils.mkdir_p(path) cur_time = Time.now.to_f.to_s File.open("\#{path}/foo.rb", "w") do |f| @@ -1357,7 +1357,7 @@ In Gemfile: s.extensions << "Rakefile" s.write "Rakefile", <<-RUBY task :default do - path = File.expand_path("../lib", __FILE__) + path = File.expand_path("lib", __dir__) FileUtils.mkdir_p(path) cur_time = Time.now.to_f.to_s File.open("\#{path}/foo.rb", "w") do |f| diff --git a/spec/bundler/install/gemfile/path_spec.rb b/spec/bundler/install/gemfile/path_spec.rb index bea7c11dec..515901064f 100644 --- a/spec/bundler/install/gemfile/path_spec.rb +++ b/spec/bundler/install/gemfile/path_spec.rb @@ -137,7 +137,7 @@ RSpec.describe "bundle install with explicit source paths" do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" - gem 'foo', :path => File.expand_path("../foo-1.0", __FILE__) + gem 'foo', :path => File.expand_path("foo-1.0", __dir__) G bundle "config set --local frozen true" diff --git a/spec/bundler/install/gems/compact_index_spec.rb b/spec/bundler/install/gems/compact_index_spec.rb index 1282dbf381..72ad40e24f 100644 --- a/spec/bundler/install/gems/compact_index_spec.rb +++ b/spec/bundler/install/gems/compact_index_spec.rb @@ -258,7 +258,7 @@ The checksum of /versions does not match the checksum provided by the server! So s.extensions << "Rakefile" s.write "Rakefile", <<-RUBY task :default do - path = File.expand_path("../lib", __FILE__) + path = File.expand_path("lib", __dir__) FileUtils.mkdir_p(path) File.open("\#{path}/net_build_extensions.rb", "w") do |f| f.puts "NET_BUILD_EXTENSIONS = 'YES'" diff --git a/spec/bundler/install/gems/resolving_spec.rb b/spec/bundler/install/gems/resolving_spec.rb index b0209489b9..209996f61f 100644 --- a/spec/bundler/install/gems/resolving_spec.rb +++ b/spec/bundler/install/gems/resolving_spec.rb @@ -7,7 +7,7 @@ RSpec.describe "bundle install with install-time dependencies" do s.extensions << "Rakefile" s.write "Rakefile", <<-RUBY task :default do - path = File.expand_path("../lib", __FILE__) + path = File.expand_path("lib", __dir__) FileUtils.mkdir_p(path) File.open("\#{path}/implicit_rake_dep.rb", "w") do |f| f.puts "IMPLICIT_RAKE_DEP = 'YES'" @@ -20,7 +20,7 @@ RSpec.describe "bundle install with install-time dependencies" do s.extensions << "Rakefile" s.write "Rakefile", <<-RUBY task :default do - path = File.expand_path("../lib", __FILE__) + path = File.expand_path("lib", __dir__) FileUtils.mkdir_p(path) File.open("\#{path}/another_implicit_rake_dep.rb", "w") do |f| f.puts "ANOTHER_IMPLICIT_RAKE_DEP = 'YES'" @@ -42,7 +42,7 @@ RSpec.describe "bundle install with install-time dependencies" do s.extensions << "Rakefile" s.write "Rakefile", <<-RUBY task :default do - path = File.expand_path("../lib", __FILE__) + path = File.expand_path("lib", __dir__) FileUtils.mkdir_p(path) File.open("\#{path}/net_build_extensions.rb", "w") do |f| f.puts "NET_BUILD_EXTENSIONS = 'YES'" diff --git a/spec/bundler/install/gems/standalone_spec.rb b/spec/bundler/install/gems/standalone_spec.rb index c7efc836a8..66dd7f534a 100644 --- a/spec/bundler/install/gems/standalone_spec.rb +++ b/spec/bundler/install/gems/standalone_spec.rb @@ -205,7 +205,7 @@ RSpec.shared_examples "bundle install --standalone" do build_git "bar", :gemspec => false do |s| s.write "lib/bar/version.rb", %(BAR_VERSION = '1.0') s.write "bar.gemspec", <<-G - lib = File.expand_path('../lib/', __FILE__) + lib = File.expand_path('lib/', __dir__) $:.unshift lib unless $:.include?(lib) require 'bar/version' @@ -419,7 +419,7 @@ RSpec.shared_examples "bundle install --standalone" do it "creates stubs with the correct load path" do extension_line = File.read(bundled_app("bin/rails")).each_line.find {|line| line.include? "$:.unshift" }.strip - expect(extension_line).to eq %($:.unshift File.expand_path "../../bundle", path.realpath) + expect(extension_line).to eq %($:.unshift File.expand_path "../bundle", __dir__) end end end diff --git a/spec/bundler/install/gems/sudo_spec.rb b/spec/bundler/install/gems/sudo_spec.rb index 3e5d38ea4c..41b241da25 100644 --- a/spec/bundler/install/gems/sudo_spec.rb +++ b/spec/bundler/install/gems/sudo_spec.rb @@ -54,7 +54,7 @@ RSpec.describe "when using sudo", :sudo => true do s.extensions << "Rakefile" s.write "Rakefile", <<-RUBY task :default do - path = File.expand_path("../lib", __FILE__) + path = File.expand_path("lib", __dir__) FileUtils.mkdir_p(path) File.open("\#{path}/another_implicit_rake_dep.rb", "w") do |f| f.puts "ANOTHER_IMPLICIT_RAKE_DEP = 'YES'" diff --git a/spec/bundler/lock/lockfile_spec.rb b/spec/bundler/lock/lockfile_spec.rb index 561de9f3bc..8ec0a80bd0 100644 --- a/spec/bundler/lock/lockfile_spec.rb +++ b/spec/bundler/lock/lockfile_spec.rb @@ -897,7 +897,7 @@ RSpec.describe "the lockfile format" do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" - path File.expand_path("../foo", __FILE__) do + path File.expand_path("foo", __dir__) do gem "foo" end G diff --git a/test/rubygems/helper.rb b/test/rubygems/helper.rb index 5ed51fec10..be9016b831 100644 --- a/test/rubygems/helper.rb +++ b/test/rubygems/helper.rb @@ -3,7 +3,7 @@ require 'rubygems' # If bundler gemspec exists, add to stubs -bundler_gemspec = File.expand_path("../../../bundler/bundler.gemspec", __FILE__) +bundler_gemspec = File.expand_path('../../bundler/bundler.gemspec', __dir__) if File.exist?(bundler_gemspec) Gem::Specification.dirs.unshift File.dirname(bundler_gemspec) Gem::Specification.class_variable_set :@@stubs, nil diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index cc4772a0c6..a8be078046 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -10,7 +10,7 @@ require 'rbconfig' class TestGem < Gem::TestCase PLUGINS_LOADED = [] # rubocop:disable Style/MutableConstant - PROJECT_DIR = File.expand_path('../../..', __FILE__).tap(&Gem::UNTAINT) + PROJECT_DIR = File.expand_path('../..', __dir__).tap(&Gem::UNTAINT) def setup super diff --git a/test/rubygems/test_gem_command_manager.rb b/test/rubygems/test_gem_command_manager.rb index ff1f955c6c..bee635d67e 100644 --- a/test/rubygems/test_gem_command_manager.rb +++ b/test/rubygems/test_gem_command_manager.rb @@ -3,7 +3,7 @@ require_relative 'helper' require 'rubygems/command_manager' class TestGemCommandManager < Gem::TestCase - PROJECT_DIR = File.expand_path('../../..', __FILE__).tap(&Gem::UNTAINT) + PROJECT_DIR = File.expand_path('../..', __dir__).tap(&Gem::UNTAINT) def setup super diff --git a/test/rubygems/test_gem_commands_help_command.rb b/test/rubygems/test_gem_commands_help_command.rb index a70dd770e1..98e5b62be0 100644 --- a/test/rubygems/test_gem_commands_help_command.rb +++ b/test/rubygems/test_gem_commands_help_command.rb @@ -11,7 +11,7 @@ class TestGemCommandsHelpCommand < Gem::TestCase @cmd = Gem::Commands::HelpCommand.new - load File.expand_path('../rubygems_plugin.rb', __FILE__) unless Gem::Commands.const_defined? :InterruptCommand + load File.expand_path('rubygems_plugin.rb', __dir__) unless Gem::Commands.const_defined? :InterruptCommand end def test_gem_help_bad diff --git a/test/rubygems/test_gem_commands_setup_command.rb b/test/rubygems/test_gem_commands_setup_command.rb index 934c76b1d1..ab563b28ee 100644 --- a/test/rubygems/test_gem_commands_setup_command.rb +++ b/test/rubygems/test_gem_commands_setup_command.rb @@ -4,7 +4,7 @@ require_relative 'helper' require 'rubygems/commands/setup_command' class TestGemCommandsSetupCommand < Gem::TestCase - bundler_gemspec = File.expand_path("../../../bundler/lib/bundler/version.rb", __FILE__) + bundler_gemspec = File.expand_path('../../bundler/lib/bundler/version.rb', __dir__) if File.exist?(bundler_gemspec) BUNDLER_VERS = File.read(bundler_gemspec).match(/VERSION = "(#{Gem::Version::VERSION_PATTERN})"/)[1] else diff --git a/test/rubygems/test_gem_dependency_installer.rb b/test/rubygems/test_gem_dependency_installer.rb index 9cbdcefea4..f2404d61c7 100644 --- a/test/rubygems/test_gem_dependency_installer.rb +++ b/test/rubygems/test_gem_dependency_installer.rb @@ -941,7 +941,7 @@ class TestGemDependencyInstaller < Gem::TestCase end def test_install_legacy_spec_with_nil_required_ruby_version - path = File.expand_path "../data/null-required-ruby-version.gemspec.rz", __FILE__ + path = File.expand_path 'data/null-required-ruby-version.gemspec.rz', __dir__ spec = Marshal.load Gem.read_binary(path) def spec.validate(*args); end @@ -966,7 +966,7 @@ class TestGemDependencyInstaller < Gem::TestCase end def test_install_legacy_spec_with_nil_required_rubygems_version - path = File.expand_path "../data/null-required-rubygems-version.gemspec.rz", __FILE__ + path = File.expand_path 'data/null-required-rubygems-version.gemspec.rz', __dir__ spec = Marshal.load Gem.read_binary(path) def spec.validate(*args); end diff --git a/test/rubygems/test_gem_ext_builder.rb b/test/rubygems/test_gem_ext_builder.rb index 165194510e..7e19782e61 100644 --- a/test/rubygems/test_gem_ext_builder.rb +++ b/test/rubygems/test_gem_ext_builder.rb @@ -291,7 +291,7 @@ install: File.open File.join(@spec.gem_dir, "extconf.rb"), "w" do |f| f.write <<-'RUBY' puts "IN EXTCONF" - extconf_args = File.join File.dirname(__FILE__), 'extconf_args' + extconf_args = File.join __dir__, 'extconf_args' File.open extconf_args, 'w' do |f| f.puts ARGV.inspect end diff --git a/test/rubygems/test_gem_ext_cargo_builder.rb b/test/rubygems/test_gem_ext_cargo_builder.rb index 5a1c035947..0c8de2ff6c 100644 --- a/test/rubygems/test_gem_ext_cargo_builder.rb +++ b/test/rubygems/test_gem_ext_cargo_builder.rb @@ -20,7 +20,7 @@ class TestGemExtCargoBuilder < Gem::TestCase def setup_rust_gem(name) @ext = File.join(@tempdir, 'ext') @dest_path = File.join(@tempdir, 'prefix') - @fixture_dir = Pathname.new(File.expand_path("../test_gem_ext_cargo_builder/#{name}/", __FILE__)) + @fixture_dir = Pathname.new(File.expand_path("test_gem_ext_cargo_builder/#{name}/", __dir__)) FileUtils.mkdir_p @dest_path FileUtils.cp_r(@fixture_dir.to_s, @ext) @@ -103,7 +103,7 @@ class TestGemExtCargoBuilder < Gem::TestCase Dir.chdir @ext do require 'tmpdir' - gem = [@rust_envs, *ruby_with_rubygems_in_load_path, File.expand_path("./../../../bin/gem", __FILE__)] + gem = [@rust_envs, *ruby_with_rubygems_in_load_path, File.expand_path('../../bin/gem', __dir__)] Dir.mktmpdir("rust_ruby_example") do |dir| built_gem = File.expand_path(File.join(dir, "rust_ruby_example.gem")) @@ -125,7 +125,7 @@ class TestGemExtCargoBuilder < Gem::TestCase Dir.chdir @ext do require 'tmpdir' - gem = [@rust_envs, *ruby_with_rubygems_in_load_path, File.expand_path("./../../../bin/gem", __FILE__)] + gem = [@rust_envs, *ruby_with_rubygems_in_load_path, File.expand_path('../../bin/gem', __dir__)] Dir.mktmpdir("custom_name") do |dir| built_gem = File.expand_path(File.join(dir, "custom_name.gem")) diff --git a/test/rubygems/test_gem_ext_cargo_builder/custom_name/build.rb b/test/rubygems/test_gem_ext_cargo_builder/custom_name/build.rb index a521dceb4a..4d2f8488a4 100644 --- a/test/rubygems/test_gem_ext_cargo_builder/custom_name/build.rb +++ b/test/rubygems/test_gem_ext_cargo_builder/custom_name/build.rb @@ -9,9 +9,9 @@ end require 'tmpdir' -lp = File.expand_path("./../../../../../lib", __FILE__) -gem = ["ruby", "-I#{lp}", File.expand_path("./../../../../../bin/gem", __FILE__)] -gemspec = File.expand_path("./../custom_name.gemspec", __FILE__) +lp = File.expand_path('../../../../lib', __dir__) +gem = ["ruby", "-I#{lp}", File.expand_path('../../../../bin/gem', __dir__)] +gemspec = File.expand_path('custom_name.gemspec', __dir__) Dir.mktmpdir("custom_name") do |dir| built_gem = File.expand_path(File.join(dir, "custom_name.gem")) diff --git a/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/build.rb b/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/build.rb index 468274c9a7..da9e82315e 100644 --- a/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/build.rb +++ b/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/build.rb @@ -9,9 +9,9 @@ end require 'tmpdir' -lp = File.expand_path("./../../../../../lib", __FILE__) -gem = ["ruby", "-I#{lp}", File.expand_path("./../../../../../bin/gem", __FILE__)] -gemspec = File.expand_path("./../rust_ruby_example.gemspec", __FILE__) +lp = File.expand_path('../../../../lib', __dir__) +gem = ["ruby", "-I#{lp}", File.expand_path('../../../../bin/gem', __dir__)] +gemspec = File.expand_path('rust_ruby_example.gemspec', __dir__) Dir.mktmpdir("rust_ruby_example") do |dir| built_gem = File.expand_path(File.join(dir, "rust_ruby_example.gem")) diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index 8b4a07d23b..55dd7f0ff2 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -1068,7 +1068,7 @@ dependencies: [] end def test_handles_private_null_type - path = File.expand_path "../data/null-type.gemspec.rz", __FILE__ + path = File.expand_path 'data/null-type.gemspec.rz', __dir__ data = Marshal.load Gem::Util.inflate(Gem.read_binary(path)) diff --git a/test/rubygems/test_project_sanity.rb b/test/rubygems/test_project_sanity.rb index 38c2541df6..27b1f11d62 100644 --- a/test/rubygems/test_project_sanity.rb +++ b/test/rubygems/test_project_sanity.rb @@ -5,7 +5,7 @@ require "open3" class TestProjectSanity < Gem::TestCase def test_manifest_is_up_to_date - pend unless File.exist?(File.expand_path("../../../Rakefile", __FILE__)) + pend unless File.exist?(File.expand_path('../../Rakefile', __dir__)) _, status = Open3.capture2e("rake check_manifest") diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb index 5b826d052b..90b943dff3 100644 --- a/test/rubygems/test_require.rb +++ b/test/rubygems/test_require.rb @@ -230,7 +230,7 @@ class TestGemRequire < Gem::TestCase pend "not installed yet" unless RbConfig::TOPDIR - lib_dir = File.expand_path("../../lib", File.dirname(__FILE__)) + lib_dir = File.expand_path("../lib", __dir__) rubylibdir = File.realdirpath(RbConfig::CONFIG["rubylibdir"]) if rubylibdir == lib_dir # testing in the ruby repository where RubyGems' lib/ == stdlib lib/