-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Refactor Bundler tests to invoke RubyGems API directly #9195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -182,19 +182,6 @@ def gembin(cmd, options = {}) | |
| sys_exec(cmd.to_s, options) | ||
| end | ||
|
|
||
| def gem_command(command, options = {}) | ||
| env = options[:env] || {} | ||
| env["RUBYOPT"] = opt_add(opt_add("-r#{hax}", env["RUBYOPT"]), ENV["RUBYOPT"]) | ||
| options[:env] = env | ||
|
|
||
| # Sometimes `gem install` commands hang at dns resolution, which has a | ||
| # default timeout of 60 seconds. When that happens, the timeout for a | ||
| # command is expired too. So give `gem install` commands a bit more time. | ||
| options[:timeout] = 120 | ||
|
|
||
| sys_exec("#{Path.gem_bin} #{command}", options) | ||
| end | ||
|
|
||
| def sys_exec(cmd, options = {}, &block) | ||
| env = options[:env] || {} | ||
| env["RUBYOPT"] = opt_add(opt_add("-r#{spec_dir}/support/switch_rubygems.rb", env["RUBYOPT"]), ENV["RUBYOPT"]) | ||
|
|
@@ -326,9 +313,17 @@ def self.install_dev_bundler | |
| def install_gem(path, install_dir, default = false) | ||
| raise ArgumentError, "`#{path}` does not exist!" unless File.exist?(path) | ||
|
|
||
| args = "--no-document --ignore-dependencies --verbose --local --install-dir #{install_dir}" | ||
| require "rubygems/installer" | ||
|
|
||
| gem_command "install #{args} '#{path}'" | ||
| installer = Gem::Installer.at( | ||
| path.to_s, | ||
| install_dir: install_dir.to_s, | ||
| document: [], | ||
| ignore_dependencies: true, | ||
| wrappers: true, | ||
| force: true | ||
| ) | ||
| installer.install | ||
|
|
||
| if default | ||
| gem = Pathname.new(path).basename.to_s.match(/(.*)\.gem/)[1] | ||
|
|
@@ -343,6 +338,52 @@ def install_gem(path, install_dir, default = false) | |
| end | ||
| end | ||
|
|
||
| def uninstall_gem(name, options = {}) | ||
| require "rubygems/uninstaller" | ||
|
|
||
| gem_home = options.dig(:env, "GEM_HOME") || system_gem_path.to_s | ||
|
|
||
| uninstaller = Gem::Uninstaller.new( | ||
| name, | ||
| install_dir: gem_home, | ||
| ignore: true, | ||
| executables: true, | ||
| all: true | ||
| ) | ||
| uninstaller.uninstall | ||
| end | ||
|
|
||
| def installed_gems_list(options = {}) | ||
| gem_home = options.dig(:env, "GEM_HOME") || system_gem_path.to_s | ||
|
|
||
| # Temporarily set GEM_HOME for the command | ||
| old_gem_home = ENV["GEM_HOME"] | ||
| ENV["GEM_HOME"] = gem_home | ||
| Gem.clear_paths | ||
|
|
||
| begin | ||
| require "rubygems/commands/list_command" | ||
|
|
||
| # Capture output from the list command | ||
| output_io = StringIO.new | ||
| cmd = Gem::Commands::ListCommand.new | ||
| cmd.ui = Gem::StreamUI.new(StringIO.new, output_io, StringIO.new, false) | ||
| cmd.invoke | ||
| output = output_io.string.strip | ||
| ensure | ||
| ENV["GEM_HOME"] = old_gem_home | ||
| Gem.clear_paths | ||
| end | ||
|
Comment on lines
+359
to
+376
|
||
|
|
||
| # Create a fake command execution so `out` helper works | ||
| command_execution = Spec::CommandExecution.new("gem list", timeout: 60) | ||
| command_execution.original_stdout << output | ||
| command_execution.exitstatus = 0 | ||
| command_executions << command_execution | ||
|
|
||
| output | ||
| end | ||
|
|
||
| def with_built_bundler(version = nil, opts = {}, &block) | ||
| require_relative "builders" | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
uninstall_gemmethod should temporarily set ENV["GEM_HOME"] to ensureGem::Uninstalleroperates on the correct gem installation directory. Without this, the uninstaller may not properly locate gems in the specifiedinstall_dir, especially when it differs from the current ENV["GEM_HOME"]. Consider wrapping the uninstaller logic with temporary ENV["GEM_HOME"] modification and Gem.clear_paths calls, similar to howinstalled_gems_listhandles this.