1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Sync Bundler PR #3624

This commit is contained in:
Hiroshi SHIBATA 2020-05-15 21:31:12 +09:00
parent f4f157fc81
commit c7ebeb7eda
Notes: git 2020-05-22 20:33:04 +09:00
54 changed files with 443 additions and 362 deletions

View file

@ -222,7 +222,6 @@ module Bundler
def github(repo, options = {}) def github(repo, options = {})
raise ArgumentError, "GitHub sources require a block" unless block_given? raise ArgumentError, "GitHub sources require a block" unless block_given?
raise DeprecatedError, "The #github method has been removed" if Bundler.feature_flag.skip_default_git_sources?
github_uri = @git_sources["github"].call(repo) github_uri = @git_sources["github"].call(repo)
git_options = normalize_hash(options).merge("uri" => github_uri) git_options = normalize_hash(options).merge("uri" => github_uri)
git_source = @sources.add_git_source(git_options) git_source = @sources.add_git_source(git_options)
@ -283,8 +282,6 @@ module Bundler
private private
def add_git_sources def add_git_sources
return if Bundler.feature_flag.skip_default_git_sources?
git_source(:github) do |repo_name| git_source(:github) do |repo_name|
warn_deprecated_git_source(:github, <<-'RUBY'.strip, 'Change any "reponame" :github sources to "username/reponame".') warn_deprecated_git_source(:github, <<-'RUBY'.strip, 'Change any "reponame" :github sources to "username/reponame".')
"https://github.com/#{repo_name}.git" "https://github.com/#{repo_name}.git"

View file

@ -41,7 +41,6 @@ module Bundler
settings_flag(:plugins) { @bundler_version >= Gem::Version.new("1.14") } settings_flag(:plugins) { @bundler_version >= Gem::Version.new("1.14") }
settings_flag(:print_only_version_number) { bundler_3_mode? } settings_flag(:print_only_version_number) { bundler_3_mode? }
settings_flag(:setup_makes_kernel_gem_public) { !bundler_3_mode? } settings_flag(:setup_makes_kernel_gem_public) { !bundler_3_mode? }
settings_flag(:skip_default_git_sources) { bundler_3_mode? }
settings_flag(:specific_platform) { bundler_3_mode? } settings_flag(:specific_platform) { bundler_3_mode? }
settings_flag(:suppress_install_using_messages) { bundler_3_mode? } settings_flag(:suppress_install_using_messages) { bundler_3_mode? }
settings_flag(:unlock_source_unlocks_spec) { !bundler_3_mode? } settings_flag(:unlock_source_unlocks_spec) { !bundler_3_mode? }

View file

@ -76,7 +76,7 @@ module Bundler
I tried... I tried...
- **Have you read our issues document, https://github.com/rubygems/bundler/blob/master/doc/contributing/ISSUES.md?** - **Have you read our issues document, https://github.com/rubygems/rubygems/blob/master/doc/contributing/ISSUES.md?**
... ...
@ -100,7 +100,7 @@ module Bundler
#{issues_url(e)} #{issues_url(e)}
If there aren't any reports for this error yet, please create copy and paste the report template above into a new issue. Don't forget to anonymize any private data! The new issue form is located at: If there aren't any reports for this error yet, please create copy and paste the report template above into a new issue. Don't forget to anonymize any private data! The new issue form is located at:
https://github.com/rubygems/bundler/issues/new https://github.com/rubygems/rubygems/issues/new
EOS EOS
end end
@ -108,7 +108,7 @@ module Bundler
message = exception.message.lines.first.tr(":", " ").chomp message = exception.message.lines.first.tr(":", " ").chomp
message = message.split("-").first if exception.is_a?(Errno) message = message.split("-").first if exception.is_a?(Errno)
require "cgi" require "cgi"
"https://github.com/rubygems/bundler/search?q=" \ "https://github.com/rubygems/rubygems/search?q=" \
"#{CGI.escape(message)}&type=Issues" "#{CGI.escape(message)}&type=Issues"
end end
end end

View file

@ -42,7 +42,6 @@ module Bundler
setup_makes_kernel_gem_public setup_makes_kernel_gem_public
silence_deprecations silence_deprecations
silence_root_warning silence_root_warning
skip_default_git_sources
specific_platform specific_platform
suppress_install_using_messages suppress_install_using_messages
unlock_source_unlocks_spec unlock_source_unlocks_spec

View file

@ -262,9 +262,6 @@ The following is a list of all configuration keys and their purpose\. You can le
\fBsilence_root_warning\fR (\fBBUNDLE_SILENCE_ROOT_WARNING\fR): Silence the warning Bundler prints when installing gems as root\. \fBsilence_root_warning\fR (\fBBUNDLE_SILENCE_ROOT_WARNING\fR): Silence the warning Bundler prints when installing gems as root\.
. .
.IP "\(bu" 4 .IP "\(bu" 4
\fBskip_default_git_sources\fR (\fBBUNDLE_SKIP_DEFAULT_GIT_SOURCES\fR): Whether Bundler should skip adding default git source shortcuts to the Gemfile DSL\.
.
.IP "\(bu" 4
\fBspecific_platform\fR (\fBBUNDLE_SPECIFIC_PLATFORM\fR): Allow bundler to resolve for the specific running platform and store it in the lockfile, instead of only using a generic platform\. A specific platform is the exact platform triple reported by \fBGem::Platform\.local\fR, such as \fBx86_64\-darwin\-16\fR or \fBuniversal\-java\-1\.8\fR\. On the other hand, generic platforms are those such as \fBruby\fR, \fBmswin\fR, or \fBjava\fR\. In this example, \fBx86_64\-darwin\-16\fR would map to \fBruby\fR and \fBuniversal\-java\-1\.8\fR to \fBjava\fR\. \fBspecific_platform\fR (\fBBUNDLE_SPECIFIC_PLATFORM\fR): Allow bundler to resolve for the specific running platform and store it in the lockfile, instead of only using a generic platform\. A specific platform is the exact platform triple reported by \fBGem::Platform\.local\fR, such as \fBx86_64\-darwin\-16\fR or \fBuniversal\-java\-1\.8\fR\. On the other hand, generic platforms are those such as \fBruby\fR, \fBmswin\fR, or \fBjava\fR\. In this example, \fBx86_64\-darwin\-16\fR would map to \fBruby\fR and \fBuniversal\-java\-1\.8\fR to \fBjava\fR\.
. .
.IP "\(bu" 4 .IP "\(bu" 4

View file

@ -312,10 +312,6 @@ LIST OF AVAILABLE KEYS
o silence_root_warning (BUNDLE_SILENCE_ROOT_WARNING): Silence the o silence_root_warning (BUNDLE_SILENCE_ROOT_WARNING): Silence the
warning Bundler prints when installing gems as root. warning Bundler prints when installing gems as root.
o skip_default_git_sources (BUNDLE_SKIP_DEFAULT_GIT_SOURCES): Whether
Bundler should skip adding default git source shortcuts to the
Gemfile DSL.
o specific_platform (BUNDLE_SPECIFIC_PLATFORM): Allow bundler to o specific_platform (BUNDLE_SPECIFIC_PLATFORM): Allow bundler to
resolve for the specific running platform and store it in the resolve for the specific running platform and store it in the
lockfile, instead of only using a generic platform. A specific lockfile, instead of only using a generic platform. A specific

View file

@ -249,9 +249,6 @@ learn more about their operation in [bundle install(1)](bundle-install.1.html).
be changed in the next major version. be changed in the next major version.
* `silence_root_warning` (`BUNDLE_SILENCE_ROOT_WARNING`): * `silence_root_warning` (`BUNDLE_SILENCE_ROOT_WARNING`):
Silence the warning Bundler prints when installing gems as root. Silence the warning Bundler prints when installing gems as root.
* `skip_default_git_sources` (`BUNDLE_SKIP_DEFAULT_GIT_SOURCES`):
Whether Bundler should skip adding default git source shortcuts to the
Gemfile DSL.
* `specific_platform` (`BUNDLE_SPECIFIC_PLATFORM`): * `specific_platform` (`BUNDLE_SPECIFIC_PLATFORM`):
Allow bundler to resolve for the specific running platform and store it in Allow bundler to resolve for the specific running platform and store it in
the lockfile, instead of only using a generic platform. the lockfile, instead of only using a generic platform.

View file

@ -141,17 +141,17 @@ RSpec.describe "bundle executable" do
describe "printing the outdated warning" do describe "printing the outdated warning" do
shared_examples_for "no warning" do shared_examples_for "no warning" do
it "prints no warning" do it "prints no warning" do
bundle "fail" bundle "fail", :env => { "BUNDLER_VERSION" => bundler_version }
expect(last_command.stdboth).to eq("Could not find command \"fail\".") expect(last_command.stdboth).to eq("Could not find command \"fail\".")
end end
end end
let(:bundler_version) { "1.1" } let(:bundler_version) { "2.0" }
let(:latest_version) { nil } let(:latest_version) { nil }
before do before do
bundle! "config set --global disable_version_check false" bundle! "config set --global disable_version_check false"
system_gems "bundler-#{bundler_version}" pristine_system_gems "bundler-#{bundler_version}"
if latest_version if latest_version
info_path = home(".bundle/cache/compact_index/rubygems.org.443.29b0360b937aa4d161703e6160654e47/info/bundler") info_path = home(".bundle/cache/compact_index/rubygems.org.443.29b0360b937aa4d161703e6160654e47/info/bundler")
info_path.parent.mkpath info_path.parent.mkpath
@ -176,7 +176,7 @@ RSpec.describe "bundle executable" do
context "when the latest version is greater than the current version" do context "when the latest version is greater than the current version" do
let(:latest_version) { "222.0" } let(:latest_version) { "222.0" }
it "prints the version warning" do it "prints the version warning" do
bundle "fail", :system_bundler => true, :env => { "BUNDLER_SPEC_IGNORE_DEFAULT_BUNDLER_GEM" => "true" } bundle "fail", :env => { "BUNDLER_VERSION" => bundler_version }
expect(err).to start_with(<<-EOS.strip) expect(err).to start_with(<<-EOS.strip)
The latest bundler is #{latest_version}, but you are currently running #{bundler_version}. The latest bundler is #{latest_version}, but you are currently running #{bundler_version}.
To install the latest version, run `gem install bundler` To install the latest version, run `gem install bundler`
@ -184,16 +184,16 @@ To install the latest version, run `gem install bundler`
end end
context "and disable_version_check is set" do context "and disable_version_check is set" do
before { bundle! "config set disable_version_check true" } before { bundle! "config set disable_version_check true", :env => { "BUNDLER_VERSION" => bundler_version } }
include_examples "no warning" include_examples "no warning"
end end
context "running a parseable command" do context "running a parseable command" do
it "prints no warning" do it "prints no warning" do
bundle! "config get --parseable foo" bundle! "config get --parseable foo", :env => { "BUNDLER_VERSION" => bundler_version }
expect(last_command.stdboth).to eq "" expect(last_command.stdboth).to eq ""
bundle "platform --ruby" bundle "platform --ruby", :env => { "BUNDLER_VERSION" => bundler_version }
expect(last_command.stdboth).to eq "Could not locate Gemfile" expect(last_command.stdboth).to eq "Could not locate Gemfile"
end end
end end
@ -201,7 +201,7 @@ To install the latest version, run `gem install bundler`
context "and is a pre-release" do context "and is a pre-release" do
let(:latest_version) { "222.0.0.pre.4" } let(:latest_version) { "222.0.0.pre.4" }
it "prints the version warning" do it "prints the version warning" do
bundle "fail", :system_bundler => true, :env => { "BUNDLER_SPEC_IGNORE_DEFAULT_BUNDLER_GEM" => "true" } bundle "fail", :env => { "BUNDLER_VERSION" => bundler_version }
expect(err).to start_with(<<-EOS.strip) expect(err).to start_with(<<-EOS.strip)
The latest bundler is #{latest_version}, but you are currently running #{bundler_version}. The latest bundler is #{latest_version}, but you are currently running #{bundler_version}.
To install the latest version, run `gem install bundler --pre` To install the latest version, run `gem install bundler --pre`

View file

@ -63,16 +63,16 @@ RSpec.describe Bundler::Dsl do
end end
end end
context "default git sources", :bundler => "3" do context "default git sources" do
it "has none" do it "has bitbucket, gist, and github" do
expect(subject.instance_variable_get(:@git_sources)).to eq({}) expect(subject.instance_variable_get(:@git_sources).keys.sort).to eq(%w[bitbucket gist github])
end end
end end
end end
describe "#method_missing" do describe "#method_missing" do
it "raises an error for unknown DSL methods" do it "raises an error for unknown DSL methods" do
expect(Bundler).to receive(:read_file).with(root.join("Gemfile").to_s). expect(Bundler).to receive(:read_file).with(source_root.join("Gemfile").to_s).
and_return("unknown") and_return("unknown")
error_msg = "There was an error parsing `Gemfile`: Undefined local variable or method `unknown' for Gemfile. Bundler cannot continue." error_msg = "There was an error parsing `Gemfile`: Undefined local variable or method `unknown' for Gemfile. Bundler cannot continue."
@ -83,13 +83,13 @@ RSpec.describe Bundler::Dsl do
describe "#eval_gemfile" do describe "#eval_gemfile" do
it "handles syntax errors with a useful message" do it "handles syntax errors with a useful message" do
expect(Bundler).to receive(:read_file).with(root.join("Gemfile").to_s).and_return("}") expect(Bundler).to receive(:read_file).with(source_root.join("Gemfile").to_s).and_return("}")
expect { subject.eval_gemfile("Gemfile") }. expect { subject.eval_gemfile("Gemfile") }.
to raise_error(Bundler::GemfileError, /There was an error parsing `Gemfile`: (syntax error, unexpected tSTRING_DEND|(compile error - )?syntax error, unexpected '\}'). Bundler cannot continue./) to raise_error(Bundler::GemfileError, /There was an error parsing `Gemfile`: (syntax error, unexpected tSTRING_DEND|(compile error - )?syntax error, unexpected '\}'). Bundler cannot continue./)
end end
it "distinguishes syntax errors from evaluation errors" do it "distinguishes syntax errors from evaluation errors" do
expect(Bundler).to receive(:read_file).with(root.join("Gemfile").to_s).and_return( expect(Bundler).to receive(:read_file).with(source_root.join("Gemfile").to_s).and_return(
"ruby '2.1.5', :engine => 'ruby', :engine_version => '1.2.4'" "ruby '2.1.5', :engine => 'ruby', :engine_version => '1.2.4'"
) )
expect { subject.eval_gemfile("Gemfile") }. expect { subject.eval_gemfile("Gemfile") }.
@ -208,7 +208,7 @@ RSpec.describe Bundler::Dsl do
end end
end end
describe "#github", :bundler => "2" do describe "#github" do
it "from github" do it "from github" do
spree_gems = %w[spree_core spree_api spree_backend] spree_gems = %w[spree_core spree_api spree_backend]
subject.github "spree" do subject.github "spree" do
@ -220,17 +220,6 @@ RSpec.describe Bundler::Dsl do
end end
end end
end end
describe "#github", :bundler => "3" do
it "from github" do
expect do
spree_gems = %w[spree_core spree_api spree_backend]
subject.github "spree" do
spree_gems.each {|spree_gem| subject.send :gem, spree_gem }
end
end.to raise_error(Bundler::DeprecatedError, /github method has been removed/)
end
end
end end
describe "syntax errors" do describe "syntax errors" do

View file

@ -215,7 +215,7 @@ RSpec.describe Bundler, "friendly errors" do
it "generates a search URL for the exception message" do it "generates a search URL for the exception message" do
exception = Exception.new("Exception message") exception = Exception.new("Exception message")
expect(Bundler::FriendlyErrors.issues_url(exception)).to eq("https://github.com/rubygems/bundler/search?q=Exception+message&type=Issues") expect(Bundler::FriendlyErrors.issues_url(exception)).to eq("https://github.com/rubygems/rubygems/search?q=Exception+message&type=Issues")
end end
it "generates a search URL for only the first line of a multi-line exception message" do it "generates a search URL for only the first line of a multi-line exception message" do
@ -224,7 +224,7 @@ First line of the exception message
Second line of the exception message Second line of the exception message
END END
expect(Bundler::FriendlyErrors.issues_url(exception)).to eq("https://github.com/rubygems/bundler/search?q=First+line+of+the+exception+message&type=Issues") expect(Bundler::FriendlyErrors.issues_url(exception)).to eq("https://github.com/rubygems/rubygems/search?q=First+line+of+the+exception+message&type=Issues")
end end
it "generates the url without colons" do it "generates the url without colons" do
@ -233,7 +233,7 @@ Exception ::: with ::: colons :::
END END
issues_url = Bundler::FriendlyErrors.issues_url(exception) issues_url = Bundler::FriendlyErrors.issues_url(exception)
expect(issues_url).not_to include("%3A") expect(issues_url).not_to include("%3A")
expect(issues_url).to eq("https://github.com/rubygems/bundler/search?q=#{CGI.escape("Exception with colons ")}&type=Issues") expect(issues_url).to eq("https://github.com/rubygems/rubygems/search?q=#{CGI.escape("Exception with colons ")}&type=Issues")
end end
it "removes information after - for Errono::EACCES" do it "removes information after - for Errono::EACCES" do
@ -243,7 +243,7 @@ END
allow(exception).to receive(:is_a?).with(Errno).and_return(true) allow(exception).to receive(:is_a?).with(Errno).and_return(true)
issues_url = Bundler::FriendlyErrors.issues_url(exception) issues_url = Bundler::FriendlyErrors.issues_url(exception)
expect(issues_url).not_to include("/Users/foo/bar") expect(issues_url).not_to include("/Users/foo/bar")
expect(issues_url).to eq("https://github.com/rubygems/bundler/search?q=#{CGI.escape("Errno EACCES Permission denied @ dir_s_mkdir ")}&type=Issues") expect(issues_url).to eq("https://github.com/rubygems/rubygems/search?q=#{CGI.escape("Errno EACCES Permission denied @ dir_s_mkdir ")}&type=Issues")
end end
end end
end end

View file

@ -163,7 +163,7 @@ RSpec.describe Bundler::SharedHelpers do
let(:pwd_stub) { nil } let(:pwd_stub) { nil }
it "returns the current absolute path" do it "returns the current absolute path" do
expect(subject.pwd).to eq(root) expect(subject.pwd).to eq(source_root)
end end
end end
@ -242,7 +242,7 @@ RSpec.describe Bundler::SharedHelpers do
shared_examples_for "ENV['RUBYOPT'] gets set correctly" do shared_examples_for "ENV['RUBYOPT'] gets set correctly" do
it "ensures -rbundler/setup is at the beginning of ENV['RUBYOPT']" do it "ensures -rbundler/setup is at the beginning of ENV['RUBYOPT']" do
subject.set_bundle_environment subject.set_bundle_environment
expect(ENV["RUBYOPT"].split(" ")).to start_with("-r#{lib_dir}/bundler/setup") expect(ENV["RUBYOPT"].split(" ")).to start_with("-r#{source_lib_dir}/bundler/setup")
end end
end end

View file

@ -1,15 +1,13 @@
# frozen_string_literal: true # frozen_string_literal: true
RSpec.describe Bundler::StubSpecification do RSpec.describe Bundler::StubSpecification do
let(:gemspec) do let(:with_bundler_stub_spec) do
Gem::Specification.new do |s| gemspec = Gem::Specification.new do |s|
s.name = "gemname" s.name = "gemname"
s.version = "1.0.0" s.version = "1.0.0"
s.loaded_from = __FILE__ s.loaded_from = __FILE__
end end
end
let(:with_bundler_stub_spec) do
described_class.from_stub(gemspec) described_class.from_stub(gemspec)
end end

View file

@ -98,7 +98,7 @@ RSpec.describe "bundle binstubs <gem>" do
context "the bundle binstub" do context "the bundle binstub" do
before do before do
system_gems "bundler-#{system_bundler_version}" pristine_system_gems "bundler-#{system_bundler_version}"
build_repo2 do build_repo2 do
build_gem "prints_loaded_gems", "1.0" do |s| build_gem "prints_loaded_gems", "1.0" do |s|
s.executables = "print_loaded_gems" s.executables = "print_loaded_gems"

View file

@ -765,7 +765,7 @@ RSpec.describe "bundle clean" do
should_not_have_gems "foo-1.0" should_not_have_gems "foo-1.0"
end end
it "doesn't remove extensions artifacts from bundled git gems after clean", :ruby_repo do it "doesn't remove extensions artifacts from bundled git gems after clean" do
build_git "very_simple_git_binary", &:add_c_extension build_git "very_simple_git_binary", &:add_c_extension
revision = revision_for(lib_path("very_simple_git_binary-1.0")) revision = revision_for(lib_path("very_simple_git_binary-1.0"))
@ -788,7 +788,7 @@ RSpec.describe "bundle clean" do
expect(vendored_gems("bundler/gems/very_simple_git_binary-1.0-#{revision[0..11]}")).to exist expect(vendored_gems("bundler/gems/very_simple_git_binary-1.0-#{revision[0..11]}")).to exist
end end
it "removes extension directories", :ruby_repo do it "removes extension directories" do
gemfile <<-G gemfile <<-G
source "#{file_uri_for(gem_repo1)}" source "#{file_uri_for(gem_repo1)}"
@ -824,7 +824,7 @@ RSpec.describe "bundle clean" do
expect(simple_binary_extensions_dir).to exist expect(simple_binary_extensions_dir).to exist
end end
it "removes git extension directories", :ruby_repo do it "removes git extension directories" do
build_git "very_simple_git_binary", &:add_c_extension build_git "very_simple_git_binary", &:add_c_extension
revision = revision_for(lib_path("very_simple_git_binary-1.0")) revision = revision_for(lib_path("very_simple_git_binary-1.0"))

View file

@ -6,7 +6,7 @@ RSpec.describe "bundle exec" do
system_gems(system_gems_to_install, :path => default_bundle_path) system_gems(system_gems_to_install, :path => default_bundle_path)
end end
it "works with --gemfile flag", :ruby_repo do it "works with --gemfile flag" do
create_file "CustomGemfile", <<-G create_file "CustomGemfile", <<-G
gem "rack", "1.0.0" gem "rack", "1.0.0"
G G
@ -15,7 +15,7 @@ RSpec.describe "bundle exec" do
expect(out).to eq("1.0.0") expect(out).to eq("1.0.0")
end end
it "activates the correct gem", :ruby_repo do it "activates the correct gem" do
gemfile <<-G gemfile <<-G
gem "rack", "0.9.1" gem "rack", "0.9.1"
G G
@ -24,7 +24,7 @@ RSpec.describe "bundle exec" do
expect(out).to eq("0.9.1") expect(out).to eq("0.9.1")
end end
it "works when the bins are in ~/.bundle", :ruby_repo do it "works when the bins are in ~/.bundle" do
install_gemfile <<-G install_gemfile <<-G
gem "rack" gem "rack"
G G
@ -33,7 +33,7 @@ RSpec.describe "bundle exec" do
expect(out).to eq("1.0.0") expect(out).to eq("1.0.0")
end end
it "works when running from a random directory", :ruby_repo do it "works when running from a random directory" do
install_gemfile <<-G install_gemfile <<-G
gem "rack" gem "rack"
G G
@ -269,7 +269,7 @@ RSpec.describe "bundle exec" do
) )
end end
it "handles gems installed with --without", :ruby_repo do it "handles gems installed with --without" do
install_gemfile <<-G, forgotten_command_line_options(:without => "middleware") install_gemfile <<-G, forgotten_command_line_options(:without => "middleware")
source "#{file_uri_for(gem_repo1)}" source "#{file_uri_for(gem_repo1)}"
gem "rack" # rack 0.9.1 and 1.0 exist gem "rack" # rack 0.9.1 and 1.0 exist
@ -353,7 +353,7 @@ RSpec.describe "bundle exec" do
expect(err).to include("bundler: exec needs a command to run") expect(err).to include("bundler: exec needs a command to run")
end end
it "raises a helpful error when exec'ing to something outside of the bundle", :ruby_repo do it "raises a helpful error when exec'ing to something outside of the bundle" do
bundle! "config set clean false" # want to keep the rackup binstub bundle! "config set clean false" # want to keep the rackup binstub
install_gemfile! <<-G install_gemfile! <<-G
source "#{file_uri_for(gem_repo1)}" source "#{file_uri_for(gem_repo1)}"
@ -457,7 +457,7 @@ RSpec.describe "bundle exec" do
end end
describe "with gem executables" do describe "with gem executables" do
describe "run from a random directory", :ruby_repo do describe "run from a random directory" do
before(:each) do before(:each) do
install_gemfile <<-G install_gemfile <<-G
gem "rack" gem "rack"
@ -598,8 +598,9 @@ RSpec.describe "bundle exec" do
end end
Bundler.rubygems.extend(Monkey) Bundler.rubygems.extend(Monkey)
G G
bundle "install --deployment" bundle! "config set path.system true"
bundle "exec ruby -e '`#{bindir.join("bundler")} -v`; puts $?.success?'" bundle! "install"
bundle "exec ruby -e '`bundle -v`; puts $?.success?'", :env => { "BUNDLER_VERSION" => Bundler::VERSION }
expect(out).to match("true") expect(out).to match("true")
end end
end end
@ -881,7 +882,7 @@ __FILE__: #{path.to_s.inspect}
puts `bundle exec echo foo` puts `bundle exec echo foo`
RUBY RUBY
file.chmod(0o777) file.chmod(0o777)
bundle! "exec #{file}" bundle! "exec #{file}", :env => { "PATH" => path }
expect(out).to eq("foo") expect(out).to eq("foo")
end end
end end
@ -904,7 +905,7 @@ __FILE__: #{path.to_s.inspect}
end end
end end
system_gems(:bundler, "openssl-#{openssl_version}", :gem_repo => gem_repo4) system_gems("openssl-#{openssl_version}", :gem_repo => gem_repo4)
file = bundled_app("require_openssl.rb") file = bundled_app("require_openssl.rb")
create_file(file, <<-RUBY) create_file(file, <<-RUBY)
@ -915,15 +916,17 @@ __FILE__: #{path.to_s.inspect}
RUBY RUBY
file.chmod(0o777) file.chmod(0o777)
env = { "PATH" => path }
aggregate_failures do aggregate_failures do
expect(bundle!("exec #{file}", :artifice => nil)).to eq(expected) expect(bundle!("exec #{file}", :artifice => nil, :env => env)).to eq(expected)
expect(bundle!("exec bundle exec #{file}", :artifice => nil)).to eq(expected) expect(bundle!("exec bundle exec #{file}", :artifice => nil, :env => env)).to eq(expected)
expect(bundle!("exec ruby #{file}", :artifice => nil)).to eq(expected) expect(bundle!("exec ruby #{file}", :artifice => nil, :env => env)).to eq(expected)
expect(run!(file.read, :artifice => nil)).to eq(expected) expect(run!(file.read, :artifice => nil, :env => env)).to eq(expected)
end end
skip "ruby_core has openssl and rubygems in the same folder, and this test needs rubygems require but default openssl not in a directly added entry in $LOAD_PATH" if ruby_core?
# sanity check that we get the newer, custom version without bundler # sanity check that we get the newer, custom version without bundler
sys_exec("#{Gem.ruby} #{file}") sys_exec("#{Gem.ruby} #{file}", :env => env)
expect(err).to include("custom openssl should not be loaded") expect(err).to include("custom openssl should not be loaded")
end end
end end

View file

@ -41,7 +41,7 @@ RSpec.describe "bundle info" do
expect(err).to eq("Could not find gem 'missing'.") expect(err).to eq("Could not find gem 'missing'.")
end end
context "given a default gem shippped in ruby", :ruby_repo do context "given a default gem shippped in ruby" do
it "prints information about the default gem" do it "prints information about the default gem" do
bundle! "info rdoc" bundle! "info rdoc"
expect(out).to include("* rdoc") expect(out).to include("* rdoc")

View file

@ -246,7 +246,7 @@ RSpec.describe "bundle gem" do
end end
end end
it "generates a valid gemspec", :readline, :ruby_repo do it "generates a valid gemspec", :readline do
bundle! "gem newgem --bin" bundle! "gem newgem --bin"
prepare_gemspec(bundled_app("newgem", "newgem.gemspec")) prepare_gemspec(bundled_app("newgem", "newgem.gemspec"))

View file

@ -2,7 +2,7 @@
require "bundler/vendored_fileutils" require "bundler/vendored_fileutils"
RSpec.describe "bundle pristine", :ruby_repo do RSpec.describe "bundle pristine" do
before :each do before :each do
build_lib "baz", :path => bundled_app do |s| build_lib "baz", :path => bundled_app do |s|
s.version = "1.0.0" s.version = "1.0.0"
@ -34,7 +34,7 @@ RSpec.describe "bundle pristine", :ruby_repo do
context "when sourced from RubyGems" do context "when sourced from RubyGems" do
it "reverts using cached .gem file" do it "reverts using cached .gem file" do
spec = Bundler.definition.specs["weakling"].first spec = find_spec("weakling")
changes_txt = Pathname.new(spec.full_gem_path).join("lib/changes.txt") changes_txt = Pathname.new(spec.full_gem_path).join("lib/changes.txt")
FileUtils.touch(changes_txt) FileUtils.touch(changes_txt)
@ -45,10 +45,9 @@ RSpec.describe "bundle pristine", :ruby_repo do
end end
it "does not delete the bundler gem" do it "does not delete the bundler gem" do
system_gems :bundler
bundle! "install" bundle! "install"
bundle! "pristine", :system_bundler => true bundle! "pristine"
bundle! "-v", :system_bundler => true bundle! "-v"
expected = if Bundler::VERSION < "3.0" expected = if Bundler::VERSION < "3.0"
"Bundler version" "Bundler version"
@ -62,7 +61,7 @@ RSpec.describe "bundle pristine", :ruby_repo do
context "when sourced from git repo" do context "when sourced from git repo" do
it "reverts by resetting to current revision`" do it "reverts by resetting to current revision`" do
spec = Bundler.definition.specs["foo"].first spec = find_spec("foo")
changed_file = Pathname.new(spec.full_gem_path).join("lib/foo.rb") changed_file = Pathname.new(spec.full_gem_path).join("lib/foo.rb")
diff = "#Pristine spec changes" diff = "#Pristine spec changes"
@ -74,7 +73,7 @@ RSpec.describe "bundle pristine", :ruby_repo do
end end
it "removes added files" do it "removes added files" do
spec = Bundler.definition.specs["foo"].first spec = find_spec("foo")
changes_txt = Pathname.new(spec.full_gem_path).join("lib/changes.txt") changes_txt = Pathname.new(spec.full_gem_path).join("lib/changes.txt")
FileUtils.touch(changes_txt) FileUtils.touch(changes_txt)
@ -85,7 +84,7 @@ RSpec.describe "bundle pristine", :ruby_repo do
end end
it "displays warning and ignores changes when a local config exists" do it "displays warning and ignores changes when a local config exists" do
spec = Bundler.definition.specs["foo"].first spec = find_spec("foo")
bundle "config set local.#{spec.name} #{lib_path(spec.name)}" bundle "config set local.#{spec.name} #{lib_path(spec.name)}"
changes_txt = Pathname.new(spec.full_gem_path).join("lib/changes.txt") changes_txt = Pathname.new(spec.full_gem_path).join("lib/changes.txt")
@ -100,7 +99,7 @@ RSpec.describe "bundle pristine", :ruby_repo do
context "when sourced from gemspec" do context "when sourced from gemspec" do
it "displays warning and ignores changes when sourced from gemspec" do it "displays warning and ignores changes when sourced from gemspec" do
spec = Bundler.definition.specs["baz"].first spec = find_spec("baz")
changed_file = Pathname.new(spec.full_gem_path).join("lib/baz.rb") changed_file = Pathname.new(spec.full_gem_path).join("lib/baz.rb")
diff = "#Pristine spec changes" diff = "#Pristine spec changes"
@ -113,7 +112,7 @@ RSpec.describe "bundle pristine", :ruby_repo do
end end
it "reinstall gemspec dependency" do it "reinstall gemspec dependency" do
spec = Bundler.definition.specs["baz-dev"].first spec = find_spec("baz-dev")
changed_file = Pathname.new(spec.full_gem_path).join("lib/baz/dev.rb") changed_file = Pathname.new(spec.full_gem_path).join("lib/baz/dev.rb")
diff = "#Pristine spec changes" diff = "#Pristine spec changes"
@ -127,7 +126,7 @@ RSpec.describe "bundle pristine", :ruby_repo do
context "when sourced from path" do context "when sourced from path" do
it "displays warning and ignores changes when sourced from local path" do it "displays warning and ignores changes when sourced from local path" do
spec = Bundler.definition.specs["bar"].first spec = find_spec("bar")
changes_txt = Pathname.new(spec.full_gem_path).join("lib/changes.txt") changes_txt = Pathname.new(spec.full_gem_path).join("lib/changes.txt")
FileUtils.touch(changes_txt) FileUtils.touch(changes_txt)
expect(changes_txt).to be_file expect(changes_txt).to be_file
@ -139,17 +138,17 @@ RSpec.describe "bundle pristine", :ruby_repo do
context "when passing a list of gems to pristine" do context "when passing a list of gems to pristine" do
it "resets them" do it "resets them" do
foo = Bundler.definition.specs["foo"].first foo = find_spec("foo")
foo_changes_txt = Pathname.new(foo.full_gem_path).join("lib/changes.txt") foo_changes_txt = Pathname.new(foo.full_gem_path).join("lib/changes.txt")
FileUtils.touch(foo_changes_txt) FileUtils.touch(foo_changes_txt)
expect(foo_changes_txt).to be_file expect(foo_changes_txt).to be_file
bar = Bundler.definition.specs["bar"].first bar = find_spec("bar")
bar_changes_txt = Pathname.new(bar.full_gem_path).join("lib/changes.txt") bar_changes_txt = Pathname.new(bar.full_gem_path).join("lib/changes.txt")
FileUtils.touch(bar_changes_txt) FileUtils.touch(bar_changes_txt)
expect(bar_changes_txt).to be_file expect(bar_changes_txt).to be_file
weakling = Bundler.definition.specs["weakling"].first weakling = find_spec("weakling")
weakling_changes_txt = Pathname.new(weakling.full_gem_path).join("lib/changes.txt") weakling_changes_txt = Pathname.new(weakling.full_gem_path).join("lib/changes.txt")
FileUtils.touch(weakling_changes_txt) FileUtils.touch(weakling_changes_txt)
expect(weakling_changes_txt).to be_file expect(weakling_changes_txt).to be_file
@ -171,7 +170,7 @@ RSpec.describe "bundle pristine", :ruby_repo do
end end
context "when a build config exists for one of the gems" do context "when a build config exists for one of the gems" do
let(:very_simple_binary) { Bundler.definition.specs["very_simple_binary"].first } let(:very_simple_binary) { find_spec("very_simple_binary") }
let(:c_ext_dir) { Pathname.new(very_simple_binary.full_gem_path).join("ext") } let(:c_ext_dir) { Pathname.new(very_simple_binary.full_gem_path).join("ext") }
let(:build_opt) { "--with-ext-lib=#{c_ext_dir}" } let(:build_opt) { "--with-ext-lib=#{c_ext_dir}" }
before { bundle "config set build.very_simple_binary -- #{build_opt}" } before { bundle "config set build.very_simple_binary -- #{build_opt}" }
@ -188,7 +187,7 @@ RSpec.describe "bundle pristine", :ruby_repo do
end end
context "when a build config exists for a git sourced gem" do context "when a build config exists for a git sourced gem" do
let(:git_with_ext) { Bundler.definition.specs["git_with_ext"].first } let(:git_with_ext) { find_spec("git_with_ext") }
let(:c_ext_dir) { Pathname.new(git_with_ext.full_gem_path).join("ext") } let(:c_ext_dir) { Pathname.new(git_with_ext.full_gem_path).join("ext") }
let(:build_opt) { "--with-ext-lib=#{c_ext_dir}" } let(:build_opt) { "--with-ext-lib=#{c_ext_dir}" }
before { bundle "config set build.git_with_ext -- #{build_opt}" } before { bundle "config set build.git_with_ext -- #{build_opt}" }
@ -203,4 +202,10 @@ RSpec.describe "bundle pristine", :ruby_repo do
expect(makefile_contents).to match(/LIBPATH =.*-L#{c_ext_dir}/) expect(makefile_contents).to match(/LIBPATH =.*-L#{c_ext_dir}/)
end end
end end
def find_spec(name)
without_env_side_effects do
Bundler.definition.specs[name].first
end
end
end end

View file

@ -964,7 +964,7 @@ RSpec.describe "bundle update conservative" do
isolated_owner isolated_owner
BUNDLED WITH BUNDLED WITH
1.13.0 #{Bundler::VERSION}
L L
end end

View file

@ -1,13 +1,10 @@
# frozen_string_literal: true # frozen_string_literal: true
RSpec.describe "bundle viz", :bundler => "< 3", :if => Bundler.which("dot") do RSpec.describe "bundle viz", :bundler => "< 3", :if => Bundler.which("dot") do
let(:ruby_graphviz) do
graphviz_glob = base_system_gems.join("cache/ruby-graphviz*")
Pathname.glob(graphviz_glob).first
end
before do before do
system_gems ruby_graphviz graphviz_version = RUBY_VERSION >= "2.4" ? "1.2.5" : "1.2.4"
realworld_system_gems "ruby-graphviz --version #{graphviz_version}"
end end
it "graphs gems from the Gemfile" do it "graphs gems from the Gemfile" do
@ -82,7 +79,7 @@ RSpec.describe "bundle viz", :bundler => "< 3", :if => Bundler.which("dot") do
end end
end end
system_gems ruby_graphviz, "graphviz-999", :gem_repo => gem_repo4 system_gems "graphviz-999", :gem_repo => gem_repo4
end end
it "loads the correct ruby-graphviz gem" do it "loads the correct ruby-graphviz gem" do

View file

@ -136,12 +136,12 @@ RSpec.describe "bundle install" do
system_gems "bundler-99999999.99.1" system_gems "bundler-99999999.99.1"
install_gemfile! <<-G, :system_bundler => true install_gemfile! <<-G
source "#{file_uri_for(gem_repo2)}" source "#{file_uri_for(gem_repo2)}"
gem "rails", "3.0" gem "rails", "3.0"
G G
bundle! "check", :system_bundler => true bundle! "check"
expect(out).to include("The Gemfile's dependencies are satisfied") expect(out).to include("The Gemfile's dependencies are satisfied")
end end
@ -150,12 +150,12 @@ RSpec.describe "bundle install" do
system_gems "bundler-99999999.99.1" system_gems "bundler-99999999.99.1"
install_gemfile! <<-G, :system_bundler => true install_gemfile! <<-G
source "#{file_uri_for(gem_repo2)}" source "#{file_uri_for(gem_repo2)}"
gem "rails", "3.0" gem "rails", "3.0"
G G
bundle! "check", :system_bundler => true bundle! "check"
expect(out).to include("The Gemfile's dependencies are satisfied") expect(out).to include("The Gemfile's dependencies are satisfied")
end end

View file

@ -68,7 +68,7 @@ RSpec.describe "install with --deployment or --frozen" do
bundle! :install bundle! :install
bundle "install --deployment" bundle "install --deployment"
bundle! "exec bundle check" bundle! "exec bundle check", :env => { "PATH" => path }
end end
it "works when using path gems from the same path and the version is specified" do it "works when using path gems from the same path and the version is specified" do

View file

@ -172,7 +172,7 @@ RSpec.describe "bundle install from an existing gemspec" do
s.add_dependency "platform_specific" s.add_dependency "platform_specific"
end end
system_gems "platform_specific-1.0-java", :path => default_bundle_path, :keep_path => true system_gems "platform_specific-1.0-java", :path => default_bundle_path
install_gemfile! <<-G install_gemfile! <<-G
gemspec :path => '#{tmp.join("foo")}' gemspec :path => '#{tmp.join("foo")}'
@ -420,6 +420,8 @@ RSpec.describe "bundle install from an existing gemspec" do
end end
end end
bundle "config specific_platform false"
%w[ruby jruby].each do |platform| %w[ruby jruby].each do |platform|
simulate_platform(platform) do simulate_platform(platform) do
install_gemfile <<-G install_gemfile <<-G

View file

@ -1139,7 +1139,7 @@ RSpec.describe "bundle install with git sources" do
expect(out).to include(Pathname.glob(default_bundle_path("bundler/gems/extensions/**/foo-1.0-*")).first.to_s) expect(out).to include(Pathname.glob(default_bundle_path("bundler/gems/extensions/**/foo-1.0-*")).first.to_s)
end end
it "does not use old extension after ref changes", :ruby_repo do it "does not use old extension after ref changes" do
git_reader = build_git "foo", :no_default => true do |s| git_reader = build_git "foo", :no_default => true do |s|
s.extensions = ["ext/extconf.rb"] s.extensions = ["ext/extconf.rb"]
s.write "ext/extconf.rb", <<-RUBY s.write "ext/extconf.rb", <<-RUBY

View file

@ -352,7 +352,9 @@ RSpec.describe "bundle install with groups" do
describe "when locked and installed with --without" do describe "when locked and installed with --without" do
before(:each) do before(:each) do
build_repo2 build_repo2
system_gems "rack-0.9.1" do
system_gems "rack-0.9.1"
install_gemfile <<-G, forgotten_command_line_options(:without => "rack") install_gemfile <<-G, forgotten_command_line_options(:without => "rack")
source "#{file_uri_for(gem_repo2)}" source "#{file_uri_for(gem_repo2)}"
gem "rack" gem "rack"
@ -362,7 +364,6 @@ RSpec.describe "bundle install with groups" do
end end
G G
end end
end
it "uses the correct versions even if --without was used on the original" do it "uses the correct versions even if --without was used on the original" do
expect(the_bundle).to include_gems "rack 0.9.1" expect(the_bundle).to include_gems "rack 0.9.1"

View file

@ -410,7 +410,7 @@ The checksum of /versions does not match the checksum provided by the server! So
api_request_limit = low_api_request_limit_for(gem_repo2) api_request_limit = low_api_request_limit_for(gem_repo2)
install_gemfile! <<-G, :artifice => "compact_index_extra_missing", :env => { "BUNDLER_SPEC_API_REQUEST_LIMIT" => api_request_limit.to_s } install_gemfile! <<-G, :artifice => "compact_index_extra_missing", :env => { "BUNDLER_SPEC_API_REQUEST_LIMIT" => api_request_limit.to_s }.merge(env_for_missing_prerelease_default_gem_activation)
source "#{source_uri}" source "#{source_uri}"
source "#{source_uri}/extra" do source "#{source_uri}/extra" do
gem "back_deps" gem "back_deps"
@ -432,7 +432,7 @@ The checksum of /versions does not match the checksum provided by the server! So
api_request_limit = low_api_request_limit_for(gem_repo4) api_request_limit = low_api_request_limit_for(gem_repo4)
install_gemfile! <<-G, :artifice => "compact_index_extra_api_missing", :env => { "BUNDLER_SPEC_API_REQUEST_LIMIT" => api_request_limit.to_s } install_gemfile! <<-G, :artifice => "compact_index_extra_api_missing", :env => { "BUNDLER_SPEC_API_REQUEST_LIMIT" => api_request_limit.to_s }.merge(env_for_missing_prerelease_default_gem_activation)
source "#{source_uri}" source "#{source_uri}"
source "#{source_uri}/extra" do source "#{source_uri}/extra" do
gem "back_deps" gem "back_deps"

View file

@ -384,7 +384,7 @@ RSpec.describe "gemcutter's dependency API" do
api_request_limit = low_api_request_limit_for(gem_repo2) api_request_limit = low_api_request_limit_for(gem_repo2)
install_gemfile! <<-G, :artifice => "endpoint_extra_missing", :env => { "BUNDLER_SPEC_API_REQUEST_LIMIT" => api_request_limit.to_s } install_gemfile! <<-G, :artifice => "endpoint_extra_missing", :env => { "BUNDLER_SPEC_API_REQUEST_LIMIT" => api_request_limit.to_s }.merge(env_for_missing_prerelease_default_gem_activation)
source "#{source_uri}" source "#{source_uri}"
source "#{source_uri}/extra" source "#{source_uri}/extra"
gem "back_deps" gem "back_deps"
@ -405,7 +405,7 @@ RSpec.describe "gemcutter's dependency API" do
api_request_limit = low_api_request_limit_for(gem_repo2) api_request_limit = low_api_request_limit_for(gem_repo2)
install_gemfile! <<-G, :artifice => "endpoint_extra_missing", :env => { "BUNDLER_SPEC_API_REQUEST_LIMIT" => api_request_limit.to_s } install_gemfile! <<-G, :artifice => "endpoint_extra_missing", :env => { "BUNDLER_SPEC_API_REQUEST_LIMIT" => api_request_limit.to_s }.merge(env_for_missing_prerelease_default_gem_activation)
source "#{source_uri}" source "#{source_uri}"
source "#{source_uri}/extra" do source "#{source_uri}/extra" do
gem "back_deps" gem "back_deps"

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
RSpec.describe "installing a gem with native extensions", :ruby_repo do RSpec.describe "installing a gem with native extensions" do
it "installs" do it "installs" do
build_repo2 do build_repo2 do
build_gem "c_extension" do |s| build_gem "c_extension" do |s|

View file

@ -21,7 +21,7 @@ RSpec.shared_examples "bundle install --standalone" do
testrb << "\nrequire \"#{k}\"" testrb << "\nrequire \"#{k}\""
testrb << "\nputs #{k.upcase}" testrb << "\nputs #{k.upcase}"
end end
ruby testrb, :no_lib => true ruby testrb
expect(out).to eq(expected_gems.values.join("\n")) expect(out).to eq(expected_gems.values.join("\n"))
end end
@ -43,7 +43,7 @@ RSpec.shared_examples "bundle install --standalone" do
testrb << "\nrequire \"#{k}\"" testrb << "\nrequire \"#{k}\""
testrb << "\nputs #{k.upcase}" testrb << "\nputs #{k.upcase}"
end end
ruby testrb, :no_lib => true, :dir => "#{bundled_app}2" ruby testrb, :dir => "#{bundled_app}2"
expect(out).to eq(expected_gems.values.join("\n")) expect(out).to eq(expected_gems.values.join("\n"))
end end
@ -68,7 +68,7 @@ RSpec.shared_examples "bundle install --standalone" do
include_examples "common functionality" include_examples "common functionality"
end end
describe "with gems with native extension", :ruby_repo do describe "with gems with native extension" do
before do before do
install_gemfile <<-G, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :dir => cwd) install_gemfile <<-G, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :dir => cwd)
source "#{file_uri_for(gem_repo1)}" source "#{file_uri_for(gem_repo1)}"
@ -165,7 +165,7 @@ RSpec.shared_examples "bundle install --standalone" do
it "allows creating a standalone file with limited groups" do it "allows creating a standalone file with limited groups" do
bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => "default", :dir => cwd) bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => "default", :dir => cwd)
load_error_ruby <<-RUBY, "spec", :no_lib => true load_error_ruby <<-RUBY, "spec"
$:.unshift File.expand_path("bundle") $:.unshift File.expand_path("bundle")
require "bundler/setup" require "bundler/setup"
@ -181,7 +181,7 @@ RSpec.shared_examples "bundle install --standalone" do
it "allows --without to limit the groups used in a standalone" do it "allows --without to limit the groups used in a standalone" do
bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle"), :without => "test").merge(:standalone => true, :dir => cwd) bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle"), :without => "test").merge(:standalone => true, :dir => cwd)
load_error_ruby <<-RUBY, "spec", :no_lib => true load_error_ruby <<-RUBY, "spec"
$:.unshift File.expand_path("bundle") $:.unshift File.expand_path("bundle")
require "bundler/setup" require "bundler/setup"
@ -197,7 +197,7 @@ RSpec.shared_examples "bundle install --standalone" do
it "allows --path to change the location of the standalone bundle" do it "allows --path to change the location of the standalone bundle" do
bundle! "install", forgotten_command_line_options(:path => "path/to/bundle").merge(:standalone => true, :dir => cwd) bundle! "install", forgotten_command_line_options(:path => "path/to/bundle").merge(:standalone => true, :dir => cwd)
ruby <<-RUBY, :no_lib => true ruby <<-RUBY
$:.unshift File.expand_path("path/to/bundle") $:.unshift File.expand_path("path/to/bundle")
require "bundler/setup" require "bundler/setup"
@ -212,7 +212,7 @@ RSpec.shared_examples "bundle install --standalone" do
bundle! :install, forgotten_command_line_options(:without => "test").merge(:dir => cwd) bundle! :install, forgotten_command_line_options(:without => "test").merge(:dir => cwd)
bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :dir => cwd) bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :dir => cwd)
load_error_ruby <<-RUBY, "spec", :no_lib => true load_error_ruby <<-RUBY, "spec"
$:.unshift File.expand_path("bundle") $:.unshift File.expand_path("bundle")
require "bundler/setup" require "bundler/setup"

View file

@ -145,6 +145,8 @@ RSpec.describe "when using sudo", :sudo => true do
sudo "mkdir -p #{gem_home}" sudo "mkdir -p #{gem_home}"
sudo "chmod ugo-w #{gem_home}" sudo "chmod ugo-w #{gem_home}"
system_gems :bundler, :path => gem_home
gemfile <<-G gemfile <<-G
source "#{file_uri_for(gem_repo1)}" source "#{file_uri_for(gem_repo1)}"
gem "rack", '1.0' gem "rack", '1.0'

View file

@ -44,7 +44,7 @@ RSpec.describe "global gem caching" do
gem "rack" gem "rack"
G G
FileUtils.rm_r(default_bundle_path) simulate_new_machine
expect(the_bundle).not_to include_gems "rack 1.0.0" expect(the_bundle).not_to include_gems "rack 1.0.0"
expect(source_global_cache("rack-1.0.0.gem")).to exist expect(source_global_cache("rack-1.0.0.gem")).to exist
# rack 1.0.0 is not installed and it is in the global cache # rack 1.0.0 is not installed and it is in the global cache
@ -54,7 +54,7 @@ RSpec.describe "global gem caching" do
gem "rack", "0.9.1" gem "rack", "0.9.1"
G G
FileUtils.rm_r(default_bundle_path) simulate_new_machine
expect(the_bundle).not_to include_gems "rack 0.9.1" expect(the_bundle).not_to include_gems "rack 0.9.1"
expect(source2_global_cache("rack-0.9.1.gem")).to exist expect(source2_global_cache("rack-0.9.1.gem")).to exist
# rack 0.9.1 is not installed and it is in the global cache # rack 0.9.1 is not installed and it is in the global cache
@ -68,7 +68,7 @@ RSpec.describe "global gem caching" do
# rack 1.0.0 is installed and rack 0.9.1 is not # rack 1.0.0 is installed and rack 0.9.1 is not
expect(the_bundle).to include_gems "rack 1.0.0" expect(the_bundle).to include_gems "rack 1.0.0"
expect(the_bundle).not_to include_gems "rack 0.9.1" expect(the_bundle).not_to include_gems "rack 0.9.1"
FileUtils.rm_r(default_bundle_path) simulate_new_machine
gemfile <<-G gemfile <<-G
source "#{source2}" source "#{source2}"
@ -88,7 +88,7 @@ RSpec.describe "global gem caching" do
G G
bundle! :install, :artifice => "compact_index" bundle! :install, :artifice => "compact_index"
FileUtils.rm_r(default_bundle_path) simulate_new_machine
expect(the_bundle).not_to include_gems "rack 1.0.0" expect(the_bundle).not_to include_gems "rack 1.0.0"
expect(source_global_cache("rack-1.0.0.gem")).to exist expect(source_global_cache("rack-1.0.0.gem")).to exist
# rack 1.0.0 is not installed and it is in the global cache # rack 1.0.0 is not installed and it is in the global cache
@ -99,7 +99,7 @@ RSpec.describe "global gem caching" do
G G
bundle! :install, :artifice => "compact_index" bundle! :install, :artifice => "compact_index"
FileUtils.rm_r(default_bundle_path) simulate_new_machine
expect(the_bundle).not_to include_gems "rack 0.9.1" expect(the_bundle).not_to include_gems "rack 0.9.1"
expect(source2_global_cache("rack-0.9.1.gem")).to exist expect(source2_global_cache("rack-0.9.1.gem")).to exist
# rack 0.9.1 is not installed and it is in the global cache # rack 0.9.1 is not installed and it is in the global cache
@ -145,7 +145,7 @@ RSpec.describe "global gem caching" do
expect(the_bundle).to include_gems "activesupport 2.3.5" expect(the_bundle).to include_gems "activesupport 2.3.5"
expect(source_global_cache("rack-1.0.0.gem")).to exist expect(source_global_cache("rack-1.0.0.gem")).to exist
expect(source_global_cache("activesupport-2.3.5.gem")).to exist expect(source_global_cache("activesupport-2.3.5.gem")).to exist
FileUtils.rm_r(default_bundle_path) simulate_new_machine
# Both gems are now only in the global cache # Both gems are now only in the global cache
expect(the_bundle).not_to include_gems "rack 1.0.0" expect(the_bundle).not_to include_gems "rack 1.0.0"
expect(the_bundle).not_to include_gems "activesupport 2.3.5" expect(the_bundle).not_to include_gems "activesupport 2.3.5"
@ -185,7 +185,7 @@ RSpec.describe "global gem caching" do
end end
end end
describe "extension caching", :ruby_repo do describe "extension caching" do
it "works" do it "works" do
skip "gets incorrect ref in path" if Gem.win_platform? skip "gets incorrect ref in path" if Gem.win_platform?

View file

@ -162,7 +162,7 @@ RSpec.describe "bundle install" do
expect(the_bundle).to include_gems "rack 1.0.0" expect(the_bundle).to include_gems "rack 1.0.0"
end end
it "re-installs gems whose extensions have been deleted", :ruby_repo do it "re-installs gems whose extensions have been deleted" do
build_lib "very_simple_binary", "1.0.0", :to_system => true do |s| build_lib "very_simple_binary", "1.0.0", :to_system => true do |s|
s.write "lib/very_simple_binary.rb", "raise 'FAIL'" s.write "lib/very_simple_binary.rb", "raise 'FAIL'"
end end

View file

@ -28,6 +28,8 @@ RSpec.describe "the lockfile format" do
end end
it "updates the lockfile's bundler version if current ver. is newer" do it "updates the lockfile's bundler version if current ver. is newer" do
system_gems "bundler-1.8.2"
lockfile <<-L lockfile <<-L
GIT GIT
remote: git://github.com/nex3/haml.git remote: git://github.com/nex3/haml.git
@ -50,7 +52,7 @@ RSpec.describe "the lockfile format" do
1.8.2 1.8.2
L L
install_gemfile <<-G install_gemfile <<-G, :env => { "BUNDLER_VERSION" => Bundler::VERSION }
source "#{file_uri_for(gem_repo1)}" source "#{file_uri_for(gem_repo1)}"
gem "rack" gem "rack"
@ -206,6 +208,8 @@ RSpec.describe "the lockfile format" do
current_version = Bundler::VERSION current_version = Bundler::VERSION
older_major = previous_major(current_version) older_major = previous_major(current_version)
system_gems "bundler-#{older_major}"
lockfile <<-L lockfile <<-L
GEM GEM
remote: #{file_uri_for(gem_repo1)}/ remote: #{file_uri_for(gem_repo1)}/
@ -222,7 +226,7 @@ RSpec.describe "the lockfile format" do
#{older_major} #{older_major}
L L
install_gemfile <<-G install_gemfile <<-G, :env => { "BUNDLER_VERSION" => Bundler::VERSION }
source "#{file_uri_for(gem_repo1)}/" source "#{file_uri_for(gem_repo1)}/"
gem "rack" gem "rack"

View file

@ -394,7 +394,7 @@ RSpec.describe "major deprecations" do
context "when `bundler/deployment` is required in a ruby script" do context "when `bundler/deployment` is required in a ruby script" do
before do before do
ruby(<<-RUBY) ruby(<<-RUBY, :env => env_for_missing_prerelease_default_gem_activation)
require 'bundler/deployment' require 'bundler/deployment'
RUBY RUBY
end end
@ -416,25 +416,34 @@ RSpec.describe "major deprecations" do
end end
context "with github gems" do context "with github gems" do
it "warns about removal", :bundler => "2" do it "does not warn about removal", :bundler => "2" do
expect(Bundler.ui).not_to receive(:warn)
subject.gem("sparks", :github => "indirect/sparks")
github_uri = "https://github.com/indirect/sparks.git"
expect(subject.dependencies.first.source.uri).to eq(github_uri)
end
it "warns about removal", :bundler => "3" do
msg = <<-EOS msg = <<-EOS
The :github git source is deprecated, and will be removed in the future. Change any "reponame" :github sources to "username/reponame". Add this code to the top of your Gemfile to ensure it continues to work: The :github git source is deprecated, and will be removed in the future. Change any "reponame" :github sources to "username/reponame". Add this code to the top of your Gemfile to ensure it continues to work:
git_source(:github) {|repo_name| "https://github.com/\#{repo_name}.git" } git_source(:github) {|repo_name| "https://github.com/\#{repo_name}.git" }
EOS EOS
expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(3, msg) expect(Bundler.ui).to receive(:warn).with("[DEPRECATED] #{msg}")
subject.gem("sparks", :github => "indirect/sparks") subject.gem("sparks", :github => "indirect/sparks")
github_uri = "https://github.com/indirect/sparks.git" github_uri = "https://github.com/indirect/sparks.git"
expect(subject.dependencies.first.source.uri).to eq(github_uri) expect(subject.dependencies.first.source.uri).to eq(github_uri)
end end
pending "should fail with a helpful error", :bundler => "3"
end end
context "with bitbucket gems" do context "with bitbucket gems" do
it "warns about removal", :bundler => "2" do it "does not warn about removal", :bundler => "2" do
allow(Bundler.ui).to receive(:deprecate) expect(Bundler.ui).not_to receive(:warn)
subject.gem("not-really-a-gem", :bitbucket => "mcorp/flatlab-rails")
end
it "warns about removal", :bundler => "3" do
msg = <<-EOS msg = <<-EOS
The :bitbucket git source is deprecated, and will be removed in the future. Add this code to the top of your Gemfile to ensure it continues to work: The :bitbucket git source is deprecated, and will be removed in the future. Add this code to the top of your Gemfile to ensure it continues to work:
@ -445,27 +454,27 @@ The :bitbucket git source is deprecated, and will be removed in the future. Add
end end
EOS EOS
expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(3, msg) expect(Bundler.ui).to receive(:warn).with("[DEPRECATED] #{msg}")
subject.gem("not-really-a-gem", :bitbucket => "mcorp/flatlab-rails") subject.gem("not-really-a-gem", :bitbucket => "mcorp/flatlab-rails")
end end
pending "should fail with a helpful error", :bundler => "3"
end end
context "with gist gems" do context "with gist gems" do
it "warns about removal", :bundler => "2" do it "does not warn about removal", :bundler => "2" do
allow(Bundler.ui).to receive(:deprecate) expect(Bundler.ui).not_to receive(:warn)
subject.gem("not-really-a-gem", :gist => "1234")
end
it "warns about removal", :bundler => "3" do
msg = <<-EOS msg = <<-EOS
The :gist git source is deprecated, and will be removed in the future. Add this code to the top of your Gemfile to ensure it continues to work: The :gist git source is deprecated, and will be removed in the future. Add this code to the top of your Gemfile to ensure it continues to work:
git_source(:gist) {|repo_name| "https://gist.github.com/\#{repo_name}.git" } git_source(:gist) {|repo_name| "https://gist.github.com/\#{repo_name}.git" }
EOS EOS
expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(3, msg) expect(Bundler.ui).to receive(:warn).with("[DEPRECATED] #{msg}")
subject.gem("not-really-a-gem", :gist => "1234") subject.gem("not-really-a-gem", :gist => "1234")
end end
pending "should fail with a helpful error", :bundler => "3"
end end
end end
@ -564,13 +573,9 @@ The :gist git source is deprecated, and will be removed in the future. Add this
end end
context "bundle viz" do context "bundle viz" do
let(:ruby_graphviz) do
graphviz_glob = base_system_gems.join("cache/ruby-graphviz*")
Pathname.glob(graphviz_glob).first
end
before do before do
system_gems ruby_graphviz graphviz_version = RUBY_VERSION >= "2.4" ? "1.2.5" : "1.2.4"
realworld_system_gems "ruby-graphviz --version #{graphviz_version}"
create_file "gems.rb" create_file "gems.rb"
bundle "viz" bundle "viz"
end end

View file

@ -823,7 +823,7 @@ G
end end
end end
context "bundle exec", :ruby_repo do context "bundle exec" do
before do before do
ENV["BUNDLER_FORCE_TTY"] = "true" ENV["BUNDLER_FORCE_TTY"] = "true"
system_gems "rack-1.0.0", "rack-0.9.1", :path => default_bundle_path system_gems "rack-1.0.0", "rack-0.9.1", :path => default_bundle_path
@ -1051,7 +1051,7 @@ G
FileUtils.rm(bundled_app_lock) FileUtils.rm(bundled_app_lock)
ruby "require 'bundler/setup'" ruby "require 'bundler/setup'", :env => { "BUNDLER_VERSION" => Bundler::VERSION }
expect(bundled_app_lock).not_to exist expect(bundled_app_lock).not_to exist
should_be_ruby_version_incorrect should_be_ruby_version_incorrect
@ -1068,7 +1068,7 @@ G
FileUtils.rm(bundled_app_lock) FileUtils.rm(bundled_app_lock)
ruby "require 'bundler/setup'" ruby "require 'bundler/setup'", :env => { "BUNDLER_VERSION" => Bundler::VERSION }
expect(bundled_app_lock).not_to exist expect(bundled_app_lock).not_to exist
should_be_engine_incorrect should_be_engine_incorrect
@ -1085,7 +1085,7 @@ G
FileUtils.rm(bundled_app_lock) FileUtils.rm(bundled_app_lock)
ruby "require 'bundler/setup'" ruby "require 'bundler/setup'", :env => { "BUNDLER_VERSION" => Bundler::VERSION }
expect(bundled_app_lock).not_to exist expect(bundled_app_lock).not_to exist
should_be_engine_version_incorrect should_be_engine_version_incorrect
@ -1102,7 +1102,7 @@ G
FileUtils.rm(bundled_app_lock) FileUtils.rm(bundled_app_lock)
ruby "require 'bundler/setup'" ruby "require 'bundler/setup'", :env => { "BUNDLER_VERSION" => Bundler::VERSION }
expect(bundled_app_lock).not_to exist expect(bundled_app_lock).not_to exist
should_be_patchlevel_incorrect should_be_patchlevel_incorrect

View file

@ -242,7 +242,7 @@ RSpec.describe "bundler plugin install" do
end end
RUBY RUBY
ruby code ruby code, :env => { "BUNDLER_VERSION" => Bundler::VERSION }
expect(local_plugin_gem("foo-1.0", "plugins.rb")).to exist expect(local_plugin_gem("foo-1.0", "plugins.rb")).to exist
end end
end end

View file

@ -218,7 +218,7 @@ RSpec.describe "The library itself" do
it "ships the correct set of files" do it "ships the correct set of files" do
git_list = shipped_files git_list = shipped_files
gem_list = Gem::Specification.load(gemspec.to_s).files gem_list = loaded_gemspec.files
expect(git_list.to_set).to eq(gem_list.to_set) expect(git_list.to_set).to eq(gem_list.to_set)
end end
@ -233,7 +233,7 @@ RSpec.describe "The library itself" do
] ]
files_to_require = lib_tracked_files.grep(/\.rb$/) - exclusions files_to_require = lib_tracked_files.grep(/\.rb$/) - exclusions
files_to_require.reject! {|f| f.start_with?("lib/bundler/vendor") } files_to_require.reject! {|f| f.start_with?("lib/bundler/vendor") }
files_to_require.map! {|f| File.expand_path(root.join("#{f}"), __dir__) } files_to_require.map! {|f| File.expand_path(f, source_root) }
sys_exec!("ruby -w") do |input, _, _| sys_exec!("ruby -w") do |input, _, _|
files_to_require.each do |f| files_to_require.each do |f|
input.puts "require '#{f}'" input.puts "require '#{f}'"

View file

@ -53,7 +53,7 @@ RSpec.describe "parallel", :realworld => true, :sometimes => true do
bundle :install, :standalone => true, :jobs => 4 bundle :install, :standalone => true, :jobs => 4
ruby <<-RUBY, :no_lib => true ruby <<-RUBY
$:.unshift File.expand_path("bundle") $:.unshift File.expand_path("bundle")
require "bundler/setup" require "bundler/setup"

View file

@ -89,10 +89,6 @@ RSpec.describe "Running bin/* commands" do
end end
it "creates a bundle binstub" do it "creates a bundle binstub" do
build_gem "bundler", Bundler::VERSION, :to_system => true do |s|
s.executables = "bundle"
end
gemfile <<-G gemfile <<-G
source "#{file_uri_for(gem_repo1)}" source "#{file_uri_for(gem_repo1)}"
gem "bundler" gem "bundler"

View file

@ -112,7 +112,7 @@ RSpec.describe "Bundler.setup" do
lp.map! {|p| p.sub(/^#{Regexp.union system_gem_path.to_s, default_bundle_path.to_s, lib_dir.to_s}/i, "") } lp.map! {|p| p.sub(/^#{Regexp.union system_gem_path.to_s, default_bundle_path.to_s, lib_dir.to_s}/i, "") }
end end
it "puts loaded gems after -I and RUBYLIB", :ruby_repo do it "puts loaded gems after -I and RUBYLIB" do
install_gemfile <<-G install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}" source "#{file_uri_for(gem_repo1)}"
gem "rack" gem "rack"
@ -136,7 +136,7 @@ RSpec.describe "Bundler.setup" do
end end
it "orders the load path correctly when there are dependencies" do it "orders the load path correctly when there are dependencies" do
system_gems :bundler bundle "config set path.system true"
install_gemfile <<-G install_gemfile <<-G
source "#{file_uri_for(gem_repo1)}" source "#{file_uri_for(gem_repo1)}"
@ -755,7 +755,7 @@ end
expect(out).to eq("yay") expect(out).to eq("yay")
end end
it "should clean $LOAD_PATH properly", :ruby_repo do it "should clean $LOAD_PATH properly" do
gem_name = "very_simple_binary" gem_name = "very_simple_binary"
full_gem_name = gem_name + "-1.0" full_gem_name = gem_name + "-1.0"
ext_dir = File.join(tmp("extensions", full_gem_name)) ext_dir = File.join(tmp("extensions", full_gem_name))
@ -802,7 +802,7 @@ end
Dir.mkdir(gems_dir) Dir.mkdir(gems_dir)
Dir.mkdir(specifications_dir) Dir.mkdir(specifications_dir)
FileUtils.ln_s(root, File.join(gems_dir, full_name)) FileUtils.ln_s(source_root, File.join(gems_dir, full_name))
gemspec_content = File.binread(gemspec). gemspec_content = File.binread(gemspec).
sub("Bundler::VERSION", %("#{Bundler::VERSION}")). sub("Bundler::VERSION", %("#{Bundler::VERSION}")).
@ -816,9 +816,9 @@ end
it "should not remove itself from the LOAD_PATH and require a different copy of 'bundler/setup'" do it "should not remove itself from the LOAD_PATH and require a different copy of 'bundler/setup'" do
install_gemfile "" install_gemfile ""
ruby <<-R, :env => { "GEM_PATH" => symlinked_gem_home }, :no_lib => true ruby <<-R, :env => { "GEM_PATH" => symlinked_gem_home }
TracePoint.trace(:class) do |tp| TracePoint.trace(:class) do |tp|
if tp.path.include?("bundler") && !tp.path.start_with?("#{root}") if tp.path.include?("bundler") && !tp.path.start_with?("#{source_root}")
puts "OMG. Defining a class from another bundler at \#{tp.path}:\#{tp.lineno}" puts "OMG. Defining a class from another bundler at \#{tp.path}:\#{tp.lineno}"
end end
end end
@ -1209,6 +1209,7 @@ end
%w[io-console openssl] %w[io-console openssl]
end << "bundler" end << "bundler"
exempts << "fiddle" if Gem.win_platform? && Gem::Version.new(Gem::VERSION) >= Gem::Version.new("2.7") exempts << "fiddle" if Gem.win_platform? && Gem::Version.new(Gem::VERSION) >= Gem::Version.new("2.7")
exempts << "uri" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.7")
exempts exempts
end end
@ -1273,7 +1274,8 @@ end
build_gem "net-http-pipeline", "1.0.1" build_gem "net-http-pipeline", "1.0.1"
end end
system_gems "net-http-pipeline-1.0.1", :gem_repo => gem_repo4 do system_gems "net-http-pipeline-1.0.1", :gem_repo => gem_repo4
gemfile <<-G gemfile <<-G
source "#{file_uri_for(gem_repo4)}" source "#{file_uri_for(gem_repo4)}"
gem "net-http-pipeline", "1.0.1" gem "net-http-pipeline", "1.0.1"
@ -1287,6 +1289,28 @@ end
expect(out).to eq("The Gemfile's dependencies are satisfied") expect(out).to eq("The Gemfile's dependencies are satisfied")
end end
# bundler respects paths specified direclty in RUBYLIB or RUBYOPT, and
# that happens when running ruby from the ruby-core setup. To
# workaround, we manually remove those for these tests when they would
# override the default gem.
def load_path_exclusions_hack_for(name)
if ruby_core?
ext_folder = source_root.join(".ext/common")
require_name = name.tr("-", "/")
if File.exist?(ext_folder.join("#{require_name}.rb"))
{ :exclude_from_load_path => ext_folder.to_s }
else
lib_folder = source_root.join("lib")
if File.exist?(lib_folder.join("#{require_name}.rb"))
{ :exclude_from_load_path => lib_folder.to_s }
else
{}
end
end
else
{}
end
end end
Gem::Specification.select(&:default_gem?).map(&:name).each do |g| Gem::Specification.select(&:default_gem?).map(&:name).each do |g|
@ -1302,7 +1326,8 @@ end
gem "#{g}", "999999" gem "#{g}", "999999"
G G
expect(the_bundle).to include_gem("#{g} 999999", :env => { "RUBYOPT" => activation_warning_hack_rubyopt }) opts = { :env => { "RUBYOPT" => activation_warning_hack_rubyopt } }
expect(the_bundle).to include_gem("#{g} 999999", opts.merge(load_path_exclusions_hack_for(g)))
end end
it "activates older versions of #{g}" do it "activates older versions of #{g}" do
@ -1317,7 +1342,8 @@ end
gem "#{g}", "0.0.0.a" gem "#{g}", "0.0.0.a"
G G
expect(the_bundle).to include_gem("#{g} 0.0.0.a", :env => { "RUBYOPT" => activation_warning_hack_rubyopt }) opts = { :env => { "RUBYOPT" => activation_warning_hack_rubyopt } }
expect(the_bundle).to include_gem("#{g} 0.0.0.a", opts.merge(load_path_exclusions_hack_for(g)))
end end
end end
end end

View file

@ -39,7 +39,7 @@ RSpec.describe "Bundler.with_env helpers" do
end end
end end
it "works with nested bundle exec invocations", :ruby_repo do it "works with nested bundle exec invocations" do
create_file("exe.rb", <<-'RUBY') create_file("exe.rb", <<-'RUBY')
count = ARGV.first.to_i count = ARGV.first.to_i
exit if count < 0 exit if count < 0
@ -61,7 +61,7 @@ RSpec.describe "Bundler.with_env helpers" do
EOS EOS
end end
it "removes variables that bundler added", :ruby_repo do it "removes variables that bundler added" do
# Simulate bundler has not yet been loaded # Simulate bundler has not yet been loaded
ENV.replace(ENV.to_hash.delete_if {|k, _v| k.start_with?(Bundler::EnvironmentPreserver::BUNDLER_PREFIX) }) ENV.replace(ENV.to_hash.delete_if {|k, _v| k.start_with?(Bundler::EnvironmentPreserver::BUNDLER_PREFIX) })
@ -89,11 +89,13 @@ RSpec.describe "Bundler.with_env helpers" do
print #{modified_env}['RUBYOPT'] print #{modified_env}['RUBYOPT']
RUBY RUBY
ENV["RUBYOPT"] = "-W2 -rbundler/setup #{ENV["RUBYOPT"]}" ENV["RUBYOPT"] = "-W2 -rbundler/setup #{ENV["RUBYOPT"]}"
bundle_exec_ruby! bundled_app("source.rb"), :env => { "BUNDLER_SPEC_DISABLE_DEFAULT_BUNDLER_GEM" => "true" } simulate_bundler_version_when_missing_prerelease_default_gem_activation do
bundle_exec_ruby! bundled_app("source.rb")
end
expect(last_command.stdboth).not_to include("-rbundler/setup") expect(last_command.stdboth).not_to include("-rbundler/setup")
end end
it "should restore RUBYLIB", :ruby_repo do it "should restore RUBYLIB" do
create_file("source.rb", <<-RUBY) create_file("source.rb", <<-RUBY)
print #{modified_env}['RUBYLIB'] print #{modified_env}['RUBYLIB']
RUBY RUBY
@ -202,7 +204,7 @@ RSpec.describe "Bundler.with_env helpers" do
RUBY RUBY
end end
it "runs system inside with_clean_env", :ruby_repo do it "runs system inside with_clean_env" do
run_bundler_script({ "BUNDLE_FOO" => "bar" }, bundled_app("source.rb")) run_bundler_script({ "BUNDLE_FOO" => "bar" }, bundled_app("source.rb"))
expect($?.exitstatus).to eq(42) expect($?.exitstatus).to eq(42)
end end
@ -217,7 +219,7 @@ RSpec.describe "Bundler.with_env helpers" do
RUBY RUBY
end end
it "runs system inside with_unbundled_env", :ruby_repo do it "runs system inside with_unbundled_env" do
run_bundler_script({ "BUNDLE_FOO" => "bar" }, bundled_app("source.rb")) run_bundler_script({ "BUNDLE_FOO" => "bar" }, bundled_app("source.rb"))
expect($?.exitstatus).to eq(42) expect($?.exitstatus).to eq(42)
end end

View file

@ -1,9 +1,5 @@
# frozen_string_literal: true # frozen_string_literal: true
require_relative "support/path"
$:.unshift Spec::Path.lib_dir.to_s
require "bundler/psyched_yaml" require "bundler/psyched_yaml"
require "bundler/vendored_fileutils" require "bundler/vendored_fileutils"
require "bundler/vendored_uri" require "bundler/vendored_uri"
@ -61,8 +57,6 @@ RSpec.configure do |config|
config.bisect_runner = :shell config.bisect_runner = :shell
original_env = ENV.to_hash
config.expect_with :rspec do |c| config.expect_with :rspec do |c|
c.syntax = :expect c.syntax = :expect
end end
@ -90,22 +84,21 @@ RSpec.configure do |config|
# Don't wrap output in tests # Don't wrap output in tests
ENV["THOR_COLUMNS"] = "10000" ENV["THOR_COLUMNS"] = "10000"
original_env = ENV.to_hash extend(Spec::Helpers)
system_gems :bundler, :path => pristine_system_gem_path
if ENV["RUBY"]
FileUtils.cp_r Spec::Path.bindir, File.join(Spec::Path.root, "lib", "exe")
end
end end
config.before :all do config.before :all do
build_repo1 build_repo1
reset_paths!
end end
config.around :each do |example| config.around :each do |example|
ENV.replace(original_env) begin
reset! FileUtils.cp_r pristine_system_gem_path, system_gem_path
system_gems []
with_gem_path_as(system_gem_path) do
@command_executions = [] @command_executions = []
Bundler.ui.silence { example.run } Bundler.ui.silence { example.run }
@ -119,10 +112,12 @@ RSpec.configure do |config|
end end
end end
end end
ensure
reset!
end
end
config.after :suite do config.after :suite do
if ENV["RUBY"] FileUtils.rm_r Spec::Path.pristine_system_gem_path
FileUtils.rm_rf File.join(Spec::Path.root, "lib", "exe")
end
end end
end end

View file

@ -2,11 +2,13 @@
require_relative "endpoint" require_relative "endpoint"
$LOAD_PATH.unshift Dir[base_system_gems.join("gems/compact_index*/lib")].first.to_s $LOAD_PATH.unshift Dir[Spec::Path.base_system_gems.join("gems/compact_index*/lib")].first.to_s
require "compact_index" require "compact_index"
class CompactIndexAPI < Endpoint class CompactIndexAPI < Endpoint
helpers do helpers do
include Spec::Path
def load_spec(name, version, platform, gem_repo) def load_spec(name, version, platform, gem_repo)
full_name = "#{name}-#{version}" full_name = "#{name}-#{version}"
full_name += "-#{platform}" if platform != "ruby" full_name += "-#{platform}" if platform != "ruby"
@ -83,7 +85,7 @@ class CompactIndexAPI < Endpoint
nil nil
end end
CompactIndex::GemVersion.new(spec.version.version, spec.platform.to_s, checksum, nil, CompactIndex::GemVersion.new(spec.version.version, spec.platform.to_s, checksum, nil,
deps, spec.required_ruby_version, spec.required_rubygems_version) deps, spec.required_ruby_version.to_s, spec.required_rubygems_version.to_s)
end end
CompactIndex::Gem.new(name, gem_versions) CompactIndex::Gem.new(name, gem_versions)
end end

View file

@ -1,8 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
require_relative "../path" require_relative "../path"
require Spec::Path.lib_dir.join("bundler/deprecate")
include Spec::Path
$LOAD_PATH.unshift(*Dir[Spec::Path.base_system_gems.join("gems/{artifice,mustermann,rack,tilt,sinatra,ruby2_keywords}-*/lib")].map(&:to_s)) $LOAD_PATH.unshift(*Dir[Spec::Path.base_system_gems.join("gems/{artifice,mustermann,rack,tilt,sinatra,ruby2_keywords}-*/lib")].map(&:to_s))
@ -41,11 +39,11 @@ class Endpoint < Sinatra::Base
end end
helpers do helpers do
include Spec::Path
def dependencies_for(gem_names, gem_repo = GEM_REPO) def dependencies_for(gem_names, gem_repo = GEM_REPO)
return [] if gem_names.nil? || gem_names.empty? return [] if gem_names.nil? || gem_names.empty?
require "#{Spec::Path.lib_dir}/bundler"
Bundler::Deprecate.skip_during do
all_specs = %w[specs.4.8 prerelease_specs.4.8].map do |filename| all_specs = %w[specs.4.8 prerelease_specs.4.8].map do |filename|
Marshal.load(File.open(gem_repo.join(filename)).read) Marshal.load(File.open(gem_repo.join(filename)).read)
end.inject(:+) end.inject(:+)
@ -63,7 +61,6 @@ class Endpoint < Sinatra::Base
} }
end.compact end.compact
end end
end
def load_spec(name, version, platform, gem_repo) def load_spec(name, version, platform, gem_repo)
full_name = "#{name}-#{version}" full_name = "#{name}-#{version}"

View file

@ -1,7 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
require_relative "../path" require_relative "../path"
include Spec::Path
$LOAD_PATH.unshift(*Dir[Spec::Path.base_system_gems.join("gems/{artifice,mustermann,rack,tilt,sinatra,ruby2_keywords}-*/lib")].map(&:to_s)) $LOAD_PATH.unshift(*Dir[Spec::Path.base_system_gems.join("gems/{artifice,mustermann,rack,tilt,sinatra,ruby2_keywords}-*/lib")].map(&:to_s))

View file

@ -1,7 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
require_relative "../path" require_relative "../path"
include Spec::Path
$LOAD_PATH.unshift(*Dir[Spec::Path.base_system_gems.join("gems/{artifice,mustermann,rack,tilt,sinatra,ruby2_keywords}-*/lib")].map(&:to_s)) $LOAD_PATH.unshift(*Dir[Spec::Path.base_system_gems.join("gems/{artifice,mustermann,rack,tilt,sinatra,ruby2_keywords}-*/lib")].map(&:to_s))

View file

@ -758,9 +758,9 @@ module Spec
gem_path = File.expand_path("#{@spec.full_name}.gem", lib_path) gem_path = File.expand_path("#{@spec.full_name}.gem", lib_path)
if opts[:to_system] if opts[:to_system]
@context.system_gems gem_path, :keep_path => true @context.system_gems gem_path
elsif opts[:to_bundle] elsif opts[:to_bundle]
@context.system_gems gem_path, :path => @context.default_bundle_path, :keep_path => true @context.system_gems gem_path, :path => @context.default_bundle_path
else else
FileUtils.mv(gem_path, destination) FileUtils.mv(gem_path, destination)
end end

View file

@ -9,13 +9,25 @@ module Gem
Gem.ruby = ENV["RUBY"] Gem.ruby = ENV["RUBY"]
end end
if ENV["BUNDLER_SPEC_PLATFORM"]
class Platform class Platform
@local = new(ENV["BUNDLER_SPEC_PLATFORM"]) if ENV["BUNDLER_SPEC_PLATFORM"] @local = new(ENV["BUNDLER_SPEC_PLATFORM"])
end end
@platforms = [Gem::Platform::RUBY, Gem::Platform.local] @platforms = [Gem::Platform::RUBY, Gem::Platform.local]
if ENV["BUNDLER_SPEC_PLATFORM"] == "ruby"
class << self
remove_method :finish_resolve
def finish_resolve
[]
end
end
end
end
# We only need this hack for rubygems versions without the BundlerVersionFinder # We only need this hack for rubygems versions without the BundlerVersionFinder
if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0") || ENV["BUNDLER_SPEC_DISABLE_DEFAULT_BUNDLER_GEM"] if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0")
@path_to_default_spec_map.delete_if do |_path, spec| @path_to_default_spec_map.delete_if do |_path, spec|
spec.name == "bundler" spec.name == "bundler"
end end
@ -24,7 +36,7 @@ end
if ENV["BUNDLER_SPEC_WINDOWS"] == "true" if ENV["BUNDLER_SPEC_WINDOWS"] == "true"
require_relative "path" require_relative "path"
require "#{Spec::Path.lib_dir}/bundler/constants" require "bundler/constants"
module Bundler module Bundler
remove_const :WINDOWS if defined?(WINDOWS) remove_const :WINDOWS if defined?(WINDOWS)
@ -34,8 +46,8 @@ end
if ENV["BUNDLER_SPEC_API_REQUEST_LIMIT"] if ENV["BUNDLER_SPEC_API_REQUEST_LIMIT"]
require_relative "path" require_relative "path"
require "#{Spec::Path.lib_dir}/bundler/source" require "bundler/source"
require "#{Spec::Path.lib_dir}/bundler/source/rubygems" require "bundler/source/rubygems"
module Bundler module Bundler
class Source class Source

View file

@ -2,17 +2,25 @@
require_relative "command_execution" require_relative "command_execution"
require_relative "the_bundle" require_relative "the_bundle"
require_relative "path"
module Spec module Spec
module Helpers module Helpers
include Spec::Path
def reset! def reset!
Dir.glob("#{tmp}/{gems/*,*}", File::FNM_DOTMATCH).each do |dir| Dir.glob("#{tmp}/{gems/*,*}", File::FNM_DOTMATCH).each do |dir|
next if %w[base remote1 gems rubygems . ..].include?(File.basename(dir)) next if %w[base base_system remote1 gems rubygems . ..].include?(File.basename(dir))
FileUtils.rm_rf(dir) FileUtils.rm_rf(dir)
end end
FileUtils.mkdir_p(home) FileUtils.mkdir_p(home)
FileUtils.mkdir_p(tmpdir) FileUtils.mkdir_p(tmpdir)
reset_paths!
end
def reset_paths!
Bundler.reset! Bundler.reset!
Gem.clear_paths
end end
def self.bang(method) def self.bang(method)
@ -80,14 +88,10 @@ module Spec
with_sudo = options.delete(:sudo) with_sudo = options.delete(:sudo)
sudo = with_sudo == :preserve_env ? "sudo -E --preserve-env=RUBYOPT" : "sudo" if with_sudo sudo = with_sudo == :preserve_env ? "sudo -E --preserve-env=RUBYOPT" : "sudo" if with_sudo
bundle_bin = options.delete("bundle_bin") || bindir.join("bundle") bundle_bin = options.delete(:bundle_bin)
bundle_bin ||= installed_bindir.join("bundle")
if system_bundler = options.delete(:system_bundler)
bundle_bin = system_gem_path.join("bin/bundler")
end
env = options.delete(:env) || {} env = options.delete(:env) || {}
env["PATH"].gsub!("#{Path.root}/exe", "") if env["PATH"] && system_bundler
requires = options.delete(:requires) || [] requires = options.delete(:requires) || []
@ -103,7 +107,6 @@ module Spec
end end
load_path = [] load_path = []
load_path << lib_dir unless system_bundler
load_path << spec_dir load_path << spec_dir
dir = options.delete(:dir) || bundled_app dir = options.delete(:dir) || bundled_app
@ -145,12 +148,12 @@ module Spec
end end
def bundler(cmd, options = {}) def bundler(cmd, options = {})
options["bundle_bin"] = bindir.join("bundler") options[:bundle_bin] = system_gem_path.join("bin/bundler")
bundle(cmd, options) bundle(cmd, options)
end end
def ruby(ruby, options = {}) def ruby(ruby, options = {})
ruby_cmd = build_ruby_cmd({ :load_path => options[:no_lib] ? [] : [lib_dir] }) ruby_cmd = build_ruby_cmd
escaped_ruby = RUBY_PLATFORM == "java" ? ruby.shellescape.dump : ruby.shellescape escaped_ruby = RUBY_PLATFORM == "java" ? ruby.shellescape.dump : ruby.shellescape
sys_exec(%(#{ruby_cmd} -w -e #{escaped_ruby}), options) sys_exec(%(#{ruby_cmd} -w -e #{escaped_ruby}), options)
end end
@ -169,8 +172,8 @@ module Spec
def build_ruby_cmd(options = {}) def build_ruby_cmd(options = {})
sudo = options.delete(:sudo) sudo = options.delete(:sudo)
libs = options.delete(:load_path) || [] libs = options.delete(:load_path)
lib_option = "-I#{libs.join(File::PATH_SEPARATOR)}" lib_option = libs ? "-I#{libs.join(File::PATH_SEPARATOR)}" : []
requires = options.delete(:requires) || [] requires = options.delete(:requires) || []
requires << "#{Path.spec_dir}/support/hax.rb" requires << "#{Path.spec_dir}/support/hax.rb"
@ -180,12 +183,8 @@ module Spec
end end
def gembin(cmd, options = {}) def gembin(cmd, options = {})
old = ENV["RUBYOPT"]
ENV["RUBYOPT"] = "#{ENV["RUBYOPT"]} -I#{lib_dir}"
cmd = bundled_app("bin/#{cmd}") unless cmd.to_s.include?("/") cmd = bundled_app("bin/#{cmd}") unless cmd.to_s.include?("/")
sys_exec(cmd.to_s, options) sys_exec(cmd.to_s, options)
ensure
ENV["RUBYOPT"] = old
end end
def gem_command(command, options = {}) def gem_command(command, options = {})
@ -328,14 +327,16 @@ module Spec
FileUtils.cp shipped_file, target_shipped_file, :preserve => true FileUtils.cp shipped_file, target_shipped_file, :preserve => true
end end
# for Ruby core repository
if File.exist? File.join(build_path, "lib/bundler/bundler.gemspec")
FileUtils.mv File.join(build_path, "lib/bundler/bundler.gemspec"), build_path
end
replace_version_file(version, dir: build_path) # rubocop:disable Style/HashSyntax replace_version_file(version, dir: build_path) # rubocop:disable Style/HashSyntax
gem_command! "build bundler.gemspec", :dir => build_path build_metadata = {
:built_at => loaded_gemspec.date.utc.strftime("%Y-%m-%d"),
:git_commit_sha => sys_exec("git rev-parse --short HEAD", :dir => source_root).strip,
}
replace_build_metadata(build_metadata, dir: build_path) # rubocop:disable Style/HashSyntax
gem_command! "build #{relative_gemspec}", :dir => build_path
yield(bundler_path) yield(bundler_path)
ensure ensure
@ -344,20 +345,25 @@ module Spec
end end
def with_gem_path_as(path) def with_gem_path_as(path)
backup = ENV.to_hash without_env_side_effects do
ENV["GEM_HOME"] = path.to_s ENV["GEM_HOME"] = path.to_s
ENV["GEM_PATH"] = path.to_s ENV["GEM_PATH"] = path.to_s
ENV["BUNDLER_ORIG_GEM_PATH"] = nil ENV["BUNDLER_ORIG_GEM_PATH"] = nil
yield yield
ensure end
ENV.replace(backup)
end end
def with_path_as(path) def with_path_as(path)
backup = ENV.to_hash without_env_side_effects do
ENV["PATH"] = path.to_s ENV["PATH"] = path.to_s
ENV["BUNDLER_ORIG_PATH"] = nil ENV["BUNDLER_ORIG_PATH"] = nil
yield yield
end
end
def without_env_side_effects
backup = ENV.to_hash
yield
ensure ensure
ENV.replace(backup) ENV.replace(backup)
end end
@ -397,56 +403,29 @@ module Spec
with_path_added(tmp("fake_man")) { yield } with_path_added(tmp("fake_man")) { yield }
end end
def pristine_system_gems(*gems)
FileUtils.rm_rf(system_gem_path)
system_gems(*gems)
end
def system_gems(*gems) def system_gems(*gems)
opts = gems.last.is_a?(Hash) ? gems.last : {} opts = gems.last.is_a?(Hash) ? gems.last : {}
path = opts.fetch(:path, system_gem_path) path = opts.fetch(:path, system_gem_path)
gems = gems.flatten gems = gems.flatten
unless opts[:keep_path] with_gem_path_as(path) do
FileUtils.rm_rf(path)
FileUtils.mkdir_p(path)
end
Gem.clear_paths
env_backup = ENV.to_hash
ENV["GEM_HOME"] = path.to_s
ENV["GEM_PATH"] = path.to_s
ENV["BUNDLER_ORIG_GEM_PATH"] = nil
install_gems(*gems) install_gems(*gems)
return unless block_given?
begin
yield
ensure
ENV.replace(env_backup)
end end
end end
def realworld_system_gems(*gems) def realworld_system_gems(*gems)
gems = gems.flatten gems = gems.flatten
FileUtils.rm_rf(system_gem_path) with_gem_path_as(system_gem_path) do
FileUtils.mkdir_p(system_gem_path)
Gem.clear_paths
gem_home = ENV["GEM_HOME"]
gem_path = ENV["GEM_PATH"]
path = ENV["PATH"]
ENV["GEM_HOME"] = system_gem_path.to_s
ENV["GEM_PATH"] = system_gem_path.to_s
gems.each do |gem| gems.each do |gem|
gem_command! "install --no-document #{gem}" gem_command! "install --no-document #{gem}"
end end
return unless block_given?
begin
yield
ensure
ENV["GEM_HOME"] = gem_home
ENV["GEM_PATH"] = gem_path
ENV["PATH"] = path
end end
end end
@ -464,9 +443,8 @@ module Spec
end end
def simulate_new_machine def simulate_new_machine
system_gems []
FileUtils.rm_rf system_gem_path
FileUtils.rm_rf bundled_app(".bundle") FileUtils.rm_rf bundled_app(".bundle")
pristine_system_gems :bundler
end end
def simulate_platform(platform) def simulate_platform(platform)
@ -490,12 +468,34 @@ module Spec
old = ENV["BUNDLER_SPEC_WINDOWS"] old = ENV["BUNDLER_SPEC_WINDOWS"]
ENV["BUNDLER_SPEC_WINDOWS"] = "true" ENV["BUNDLER_SPEC_WINDOWS"] = "true"
simulate_platform platform do simulate_platform platform do
simulate_bundler_version_when_missing_prerelease_default_gem_activation do
yield yield
end end
end
ensure ensure
ENV["BUNDLER_SPEC_WINDOWS"] = old ENV["BUNDLER_SPEC_WINDOWS"] = old
end end
# workaround for missing https://github.com/rubygems/rubygems/commit/929e92d752baad3a08f3ac92eaec162cb96aedd1
def simulate_bundler_version_when_missing_prerelease_default_gem_activation
return yield unless Gem.rubygems_version < Gem::Version.new("3.1.0.pre.1")
old = ENV["BUNDLER_VERSION"]
ENV["BUNDLER_VERSION"] = Bundler::VERSION
yield
ensure
ENV["BUNDLER_VERSION"] = old
end
# workaround for missing https://github.com/rubygems/rubygems/commit/929e92d752baad3a08f3ac92eaec162cb96aedd1
def env_for_missing_prerelease_default_gem_activation
if Gem.rubygems_version < Gem::Version.new("3.1.0.pre.1")
{ "BUNDLER_VERSION" => Bundler::VERSION }
else
{}
end
end
def revision_for(path) def revision_for(path)
sys_exec("git rev-parse HEAD", :dir => path).strip sys_exec("git rev-parse HEAD", :dir => path).strip
end end

View file

@ -115,13 +115,18 @@ module Spec
opts = names.last.is_a?(Hash) ? names.pop : {} opts = names.last.is_a?(Hash) ? names.pop : {}
source = opts.delete(:source) source = opts.delete(:source)
groups = Array(opts[:groups]) groups = Array(opts[:groups])
exclude_from_load_path = opts.delete(:exclude_from_load_path)
groups << opts groups << opts
@errors = names.map do |name| @errors = names.map do |name|
name, version, platform = name.split(/\s+/) name, version, platform = name.split(/\s+/)
require_path = name == "bundler" ? "#{lib_dir}/bundler" : name.tr("-", "/") require_path = name == "bundler" ? "#{lib_dir}/bundler" : name.tr("-", "/")
version_const = name == "bundler" ? "Bundler::VERSION" : Spec::Builders.constantize(name) version_const = name == "bundler" ? "Bundler::VERSION" : Spec::Builders.constantize(name)
begin begin
run! "require '#{require_path}.rb'; puts #{version_const}", *groups code = []
code << "$LOAD_PATH.delete '#{exclude_from_load_path}'" if exclude_from_load_path
code << "require '#{require_path}.rb'"
code << "puts #{version_const}"
run! code.join("; "), *groups
rescue StandardError => e rescue StandardError => e
next "#{name} is not installed:\n#{indent(e)}" next "#{name} is not installed:\n#{indent(e)}"
end end

View file

@ -5,56 +5,82 @@ require "rbconfig"
module Spec module Spec
module Path module Path
def source_root
@source_root ||= Pathname.new(ruby_core? ? "../../../.." : "../../..").expand_path(__FILE__)
end
def root def root
@root ||= Pathname.new(ruby_core? ? "../../../.." : "../../..").expand_path(__FILE__) @root ||= system_gem_path("gems/bundler-#{Bundler::VERSION}")
end end
def gemspec def gemspec
@gemspec ||= root.join(ruby_core? ? "lib/bundler/bundler.gemspec" : "bundler.gemspec") @gemspec ||= source_root.join(relative_gemspec)
end
def relative_gemspec
@relative_gemspec ||= ruby_core? ? "lib/bundler/bundler.gemspec" : "bundler.gemspec"
end end
def gemspec_dir def gemspec_dir
@gemspec_dir ||= gemspec.parent @gemspec_dir ||= gemspec.parent
end end
def loaded_gemspec
@loaded_gemspec ||= Gem::Specification.load(gemspec.to_s)
end
def test_gemfile
@test_gemfile ||= source_root.join(ruby_core? ? "tool/bundler/test_gems.rb" : "test_gems.rb")
end
def dev_gemfile
@dev_gemfile ||= source_root.join("dev_gems.rb")
end
def bindir def bindir
@bindir ||= root.join(ruby_core? ? "libexec" : "exe") @bindir ||= source_root.join(ruby_core? ? "libexec" : "exe")
end
def installed_bindir
@installed_bindir ||= system_gem_path("bin")
end end
def gem_cmd def gem_cmd
@gem_cmd ||= ruby_core? ? root.join("bin/gem") : "gem" @gem_cmd ||= ruby_core? ? source_root.join("bin/gem") : "gem"
end end
def gem_bin def gem_bin
@gem_bin ||= ruby_core? ? ENV["GEM_COMMAND"] : "gem" @gem_bin ||= ruby_core? ? ENV["GEM_COMMAND"] : "gem"
end end
def path
env_path = ENV["PATH"]
env_path = env_path.split(File::PATH_SEPARATOR).reject {|path| path == bindir.to_s }.join(File::PATH_SEPARATOR) if ruby_core?
env_path
end
def spec_dir def spec_dir
@spec_dir ||= root.join(ruby_core? ? "spec/bundler" : "spec") @spec_dir ||= source_root.join(ruby_core? ? "spec/bundler" : "spec")
end end
def tracked_files def tracked_files
skip "not in git working directory" unless git_root_dir? @tracked_files ||= git_ls_files(tracked_files_glob)
@tracked_files ||= sys_exec(ruby_core? ? "git ls-files -z -- lib/bundler lib/bundler.rb spec/bundler man/bundler*" : "git ls-files -z", :dir => root).split("\x0")
end end
def shipped_files def shipped_files
skip "not in git working directory" unless git_root_dir? @shipped_files ||= git_ls_files(shipped_files_glob)
@shipped_files ||= sys_exec(ruby_core? ? "git ls-files -z -- lib/bundler lib/bundler.rb man/bundler* libexec/bundle*" : "git ls-files -z -- lib man exe CHANGELOG.md LICENSE.md README.md bundler.gemspec", :dir => root).split("\x0")
end end
def lib_tracked_files def lib_tracked_files
skip "not in git working directory" unless git_root_dir? @lib_tracked_files ||= git_ls_files(lib_tracked_files_glob)
@lib_tracked_files ||= sys_exec(ruby_core? ? "git ls-files -z -- lib/bundler lib/bundler.rb" : "git ls-files -z -- lib", :dir => root).split("\x0")
end end
def man_tracked_files def man_tracked_files
skip "not in git working directory" unless git_root_dir? @man_tracked_files ||= git_ls_files(man_tracked_files_glob)
@man_tracked_files ||= sys_exec(ruby_core? ? "git ls-files -z -- man/bundler*" : "git ls-files -z -- man", :dir => root).split("\x0")
end end
def tmp(*path) def tmp(*path)
root.join("tmp", scope, *path) source_root.join("tmp", scope, *path)
end end
def scope def scope
@ -143,6 +169,10 @@ module Spec
tmp("gems/system", *path) tmp("gems/system", *path)
end end
def pristine_system_gem_path
tmp("gems/base_system")
end
def local_gem_path(*path, base: bundled_app) def local_gem_path(*path, base: bundled_app)
base.join(*[".bundle", Gem.ruby_engine, RbConfig::CONFIG["ruby_version"], *path].compact) base.join(*[".bundle", Gem.ruby_engine, RbConfig::CONFIG["ruby_version"], *path].compact)
end end
@ -151,6 +181,10 @@ module Spec
tmp("libs", *args) tmp("libs", *args)
end end
def source_lib_dir
source_root.join("lib")
end
def lib_dir def lib_dir
root.join("lib") root.join("lib")
end end
@ -167,13 +201,25 @@ module Spec
tmp "tmpdir", *args tmp "tmpdir", *args
end end
def replace_version_file(version, dir: root) def replace_version_file(version, dir: source_root)
version_file = File.expand_path("lib/bundler/version.rb", dir) version_file = File.expand_path("lib/bundler/version.rb", dir)
contents = File.read(version_file) contents = File.read(version_file)
contents.sub!(/(^\s+VERSION\s*=\s*)"#{Gem::Version::VERSION_PATTERN}"/, %(\\1"#{version}")) contents.sub!(/(^\s+VERSION\s*=\s*)"#{Gem::Version::VERSION_PATTERN}"/, %(\\1"#{version}"))
File.open(version_file, "w") {|f| f << contents } File.open(version_file, "w") {|f| f << contents }
end end
def replace_build_metadata(build_metadata, dir: source_root)
build_metadata_file = File.expand_path("lib/bundler/build_metadata.rb", dir)
ivars = build_metadata.sort.map do |k, v|
" @#{k} = #{loaded_gemspec.send(:ruby_code, v)}"
end.join("\n")
contents = File.read(build_metadata_file)
contents.sub!(/^(\s+# begin ivars).+(^\s+# end ivars)/m, "\\1\n#{ivars}\n\\2")
File.open(build_metadata_file, "w") {|f| f << contents }
end
def ruby_core? def ruby_core?
# avoid to warnings # avoid to warnings
@ruby_core ||= nil @ruby_core ||= nil
@ -185,6 +231,29 @@ module Spec
end end
end end
private
def git_ls_files(glob)
skip "not in git working directory" unless git_root_dir?
sys_exec("git ls-files -z -- #{glob}", :dir => source_root).split("\x0")
end
def tracked_files_glob
ruby_core? ? "lib/bundler lib/bundler.rb spec/bundler man/bundle*" : ""
end
def shipped_files_glob
ruby_core? ? "lib/bundler lib/bundler.rb man/bundle* man/gemfile* libexec/bundle*" : "lib man exe CHANGELOG.md LICENSE.md README.md bundler.gemspec"
end
def lib_tracked_files_glob
ruby_core? ? "lib/bundler lib/bundler.rb" : "lib"
end
def man_tracked_files_glob
ruby_core? ? "man/bundle* man/gemfile*" : "man"
end
extend self extend self
end end
end end

View file

@ -2,7 +2,7 @@
require_relative "path" require_relative "path"
$LOAD_PATH.unshift(Spec::Path.lib_dir.to_s) $LOAD_PATH.unshift(Spec::Path.source_lib_dir.to_s)
module Spec module Spec
module Rubygems module Rubygems
@ -59,7 +59,8 @@ module Spec
ENV["BUNDLE_PATH"] = nil ENV["BUNDLE_PATH"] = nil
ENV["GEM_HOME"] = ENV["GEM_PATH"] = Path.base_system_gems.to_s ENV["GEM_HOME"] = ENV["GEM_PATH"] = Path.base_system_gems.to_s
ENV["PATH"] = [Path.bindir, Path.system_gem_path.join("bin"), ENV["PATH"]].join(File::PATH_SEPARATOR) ENV["PATH"] = [Path.system_gem_path.join("bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
ENV["PATH"] = [Path.bindir, ENV["PATH"]].join(File::PATH_SEPARATOR) if Path.ruby_core?
end end
def install_test_deps def install_test_deps
@ -103,16 +104,13 @@ module Spec
require "bundler" require "bundler"
definition = Bundler::Definition.build(gemfile, lockfile, nil) definition = Bundler::Definition.build(gemfile, lockfile, nil)
definition.validate_runtime! definition.validate_runtime!
Bundler::Installer.install(Path.root, definition, :path => ENV["GEM_HOME"]) Bundler::Installer.install(Path.source_root, definition, :path => ENV["GEM_HOME"])
ensure ensure
ENV["BUNDLE_GEMFILE"] = old_gemfile ENV["BUNDLE_GEMFILE"] = old_gemfile
end end
def test_gemfile def test_gemfile
gemfile = Path.root.join("test_gems.rb") Path.test_gemfile
# for Ruby core repository
gemfile = Path.root.join("tool/bundler/test_gems.rb") unless File.exist?(gemfile)
gemfile
end end
def test_lockfile def test_lockfile
@ -120,7 +118,7 @@ module Spec
end end
def dev_gemfile def dev_gemfile
Path.root.join("dev_gems.rb") Path.dev_gemfile
end end
def dev_lockfile def dev_lockfile

View file

@ -96,7 +96,7 @@ private
def resolve_local_copy_path def resolve_local_copy_path
return expanded_source if source_is_path? return expanded_source if source_is_path?
rubygems_path = root.join("tmp/rubygems") rubygems_path = source_root.join("tmp/rubygems")
unless rubygems_path.directory? unless rubygems_path.directory?
rubygems_path.parent.mkpath rubygems_path.parent.mkpath
@ -111,7 +111,7 @@ private
end end
def expanded_source def expanded_source
@expanded_source ||= Pathname.new(@source).expand_path(root) @expanded_source ||= Pathname.new(@source).expand_path(source_root)
end end
def resolve_target_tag def resolve_target_tag

View file

@ -2,13 +2,3 @@
require_relative "rubygems_version_manager" require_relative "rubygems_version_manager"
RubygemsVersionManager.new(ENV["RGV"]).switch RubygemsVersionManager.new(ENV["RGV"]).switch
if ENV["BUNDLER_SPEC_IGNORE_DEFAULT_BUNDLER_GEM"]
module NoBundlerStubs
def default_stubs(pattern = "*.gemspec")
super(pattern).reject {|s| s.name == "bundler" }
end
end
Gem::Specification.singleton_class.prepend(NoBundlerStubs)
end