[rubygems/rubygems] Don't create an empty bundled_app when setting up deps

Running everything in `bundled_app` by default causes the `bundled_app`
helper to be used everytime, and that will create a scoped bundled_app
folder if it does not exist. That causes `bin/rake spec:deps` to create
an empty `tmp/2.1/bundled_app` folder which is a bit weird.

This commit changes specs to not switch to a (possibly empty)
bundled_app directory when not necessary (for example, when running
`gem` commands in order to setup test dependencies).

4bf89c0705
This commit is contained in:
David Rodríguez 2025-07-23 17:41:58 +02:00 committed by Hiroshi SHIBATA
parent bc5b594946
commit 63c4223775
7 changed files with 21 additions and 14 deletions

View file

@ -139,7 +139,7 @@ RSpec.describe "bundle exec" do
G
install_gemfile "source \"https://gem.repo1\""
sys_exec "#{Gem.ruby} #{command.path}"
in_bundled_app "#{Gem.ruby} #{command.path}"
expect(out).to be_empty
expect(err).to be_empty

View file

@ -42,7 +42,7 @@ RSpec.describe "bundle install --standalone" do
testrb << "\nrequire \"#{k}\""
testrb << "\nputs #{k.upcase}"
end
sys_exec %(#{Gem.ruby} --disable-gems -w -e #{testrb.shellescape})
in_bundled_app %(#{Gem.ruby} --disable-gems -w -e #{testrb.shellescape})
expect(out).to eq(expected_gems.values.join("\n"))
end
@ -113,7 +113,7 @@ RSpec.describe "bundle install --standalone" do
testrb << "\nrequire \"#{k}\""
testrb << "\nputs #{k.upcase}"
end
sys_exec %(#{Gem.ruby} -w -e #{testrb.shellescape})
in_bundled_app %(#{Gem.ruby} -w -e #{testrb.shellescape})
expect(out).to eq(expected_gems.values.join("\n"))
end
@ -485,7 +485,7 @@ RSpec.describe "bundle install --standalone" do
include_examples "common functionality"
it "creates stubs that use the standalone load path" do
expect(sys_exec("bin/rails -v").chomp).to eql "2.3.2"
expect(in_bundled_app("bin/rails -v").chomp).to eql "2.3.2"
end
it "creates stubs that can be executed from anywhere" do

View file

@ -42,7 +42,7 @@ RSpec.describe "loading dynamically linked library on a bundle exec context", re
}
C
sys_exec "gcc -g -o libfoo.so -shared -fpic libfoo.c"
in_bundled_app "gcc -g -o libfoo.so -shared -fpic libfoo.c"
install_gemfile <<-G
source "https://rubygems.org"

View file

@ -66,7 +66,7 @@ RSpec.describe "require 'bundler/gem_tasks'" do
it "includes the relevant tasks" do
define_local_gem_using_gem_tasks
sys_exec "rake -T"
in_bundled_app "rake -T"
expect(err).to be_empty
expected_tasks = [
@ -83,7 +83,7 @@ RSpec.describe "require 'bundler/gem_tasks'" do
it "defines a working `rake install` task", :ruby_repo do
define_local_gem_using_gem_tasks
sys_exec "rake install"
in_bundled_app "rake install"
expect(err).to be_empty
@ -151,7 +151,7 @@ RSpec.describe "require 'bundler/gem_tasks'" do
it "adds 'pkg' to rake/clean's CLOBBER" do
define_local_gem_using_gem_tasks
sys_exec %(rake -e 'load "Rakefile"; puts CLOBBER.inspect')
in_bundled_app %(rake -e 'load "Rakefile"; puts CLOBBER.inspect')
expect(out).to eq '["pkg"]'
end

View file

@ -54,7 +54,7 @@ RSpec.describe "Self management" do
RUBY
file.chmod(0o777)
cmd = Gem.win_platform? ? "#{Gem.ruby} bin/bundle_version.rb" : "bin/bundle_version.rb"
sys_exec cmd
in_bundled_app cmd
expect(out).to eq(previous_minor)
end
@ -95,7 +95,7 @@ RSpec.describe "Self management" do
RUBY
file.chmod(0o777)
cmd = Gem.win_platform? ? "#{Gem.ruby} bin/bundle_version.rb" : "bin/bundle_version.rb"
sys_exec cmd
in_bundled_app cmd
expect(out).to eq(previous_minor)
end
@ -212,7 +212,7 @@ RSpec.describe "Self management" do
lockfile_bundled_with("9.9.9")
sys_exec "#{Gem.ruby} #{test}", raise_on_error: false
in_bundled_app "#{Gem.ruby} #{test}", raise_on_error: false
expect(err).to include("Could not find myrack-1.0.0")
expect(err).not_to include("this is the program name")
end
@ -234,7 +234,7 @@ RSpec.describe "Self management" do
lockfile_bundled_with("9.9.9")
sys_exec "#{Gem.ruby} #{runner} #{script}", raise_on_error: false
in_bundled_app "#{Gem.ruby} #{runner} #{script}", raise_on_error: false
expect(err).to include("Could not find myrack-1.0.0")
end

View file

@ -62,6 +62,10 @@ module Spec
run(cmd, *args)
end
def in_bundled_app(cmd, options = {})
sys_exec(cmd, dir: bundled_app, raise_on_error: options[:raise_on_error])
end
def bundle(cmd, options = {}, &block)
bundle_bin = options.delete(:bundle_bin)
bundle_bin ||= installed_bindir.join("bundle")
@ -119,6 +123,7 @@ module Spec
env = build_env({ artifice: nil }.merge(options))
escaped_ruby = ruby.shellescape
options[:env] = env if env
options[:dir] ||= bundled_app
sys_exec(%(#{Gem.ruby} -w -e #{escaped_ruby}), options)
end
@ -200,7 +205,6 @@ module Spec
env = options[:env] || {}
env["RUBYOPT"] = opt_add(opt_add("-r#{spec_dir}/support/switch_rubygems.rb", env["RUBYOPT"]), ENV["RUBYOPT"])
options[:env] = env
options[:dir] ||= bundled_app
sh(cmd, options, &block)
end

View file

@ -40,9 +40,12 @@ module Spec
command_execution = CommandExecution.new(cmd.to_s, timeout: options[:timeout] || 60)
open3_opts = {}
open3_opts[:chdir] = dir if dir
require "open3"
require "shellwords"
Open3.popen3(env, *cmd.shellsplit, chdir: dir) do |stdin, stdout, stderr, wait_thr|
Open3.popen3(env, *cmd.shellsplit, **open3_opts) do |stdin, stdout, stderr, wait_thr|
yield stdin, stdout, wait_thr if block_given?
stdin.close