diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2020-10-15 13:20:25 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2020-10-15 17:19:02 +0900 |
commit | d386a58f6f1865aaa35eda5af55cff3ff3cca4ca (patch) | |
tree | 0665fe806540deae7f8e52095af6dba70f940aa3 /spec/bundler | |
parent | 7ffd14a18c341565afaf80d259f9fe5df8a13d29 (diff) | |
download | ruby-d386a58f6f1865aaa35eda5af55cff3ff3cca4ca.tar.gz |
Merge bundler-2.2.0.rc.2
Diffstat (limited to 'spec/bundler')
45 files changed, 583 insertions, 119 deletions
diff --git a/spec/bundler/bundler/cli_spec.rb b/spec/bundler/bundler/cli_spec.rb index 50e2a698eb..8e4f9e6d36 100644 --- a/spec/bundler/bundler/cli_spec.rb +++ b/spec/bundler/bundler/cli_spec.rb @@ -32,49 +32,49 @@ RSpec.describe "bundle executable" do it "aliases e to exec" do bundle "e --help" - expect(out).to include("BUNDLE-EXEC") + expect(out).to include("bundle-exec") end it "aliases ex to exec" do bundle "ex --help" - expect(out).to include("BUNDLE-EXEC") + expect(out).to include("bundle-exec") end it "aliases exe to exec" do bundle "exe --help" - expect(out).to include("BUNDLE-EXEC") + expect(out).to include("bundle-exec") end it "aliases c to check" do bundle "c --help" - expect(out).to include("BUNDLE-CHECK") + expect(out).to include("bundle-check") end it "aliases i to install" do bundle "i --help" - expect(out).to include("BUNDLE-INSTALL") + expect(out).to include("bundle-install") end it "aliases ls to list" do bundle "ls --help" - expect(out).to include("BUNDLE-LIST") + expect(out).to include("bundle-list") end it "aliases package to cache" do bundle "package --help" - expect(out).to include("BUNDLE-CACHE") + expect(out).to include("bundle-cache") end it "aliases pack to cache" do bundle "pack --help" - expect(out).to include("BUNDLE-CACHE") + expect(out).to include("bundle-cache") end end diff --git a/spec/bundler/bundler/env_spec.rb b/spec/bundler/bundler/env_spec.rb index fb593639bd..e900963350 100644 --- a/spec/bundler/bundler/env_spec.rb +++ b/spec/bundler/bundler/env_spec.rb @@ -60,7 +60,7 @@ RSpec.describe Bundler::Env do end end - private + private def with_clear_paths(env_var, env_value) old_env_var = ENV[env_var] diff --git a/spec/bundler/bundler/friendly_errors_spec.rb b/spec/bundler/bundler/friendly_errors_spec.rb index d6496db6ae..496191f891 100644 --- a/spec/bundler/bundler/friendly_errors_spec.rb +++ b/spec/bundler/bundler/friendly_errors_spec.rb @@ -193,9 +193,9 @@ RSpec.describe Bundler, "friendly errors" do describe "#request_issue_report_for" do it "calls relevant methods for Bundler.ui" do - expect(Bundler.ui).to receive(:info) - expect(Bundler.ui).to receive(:error) - expect(Bundler.ui).to receive(:warn) + expect(Bundler.ui).not_to receive(:info) + expect(Bundler.ui).to receive(:error).exactly(3).times + expect(Bundler.ui).not_to receive(:warn) Bundler::FriendlyErrors.request_issue_report_for(StandardError.new) end diff --git a/spec/bundler/bundler/gem_helper_spec.rb b/spec/bundler/bundler/gem_helper_spec.rb index b91a2c26cc..48af7867b4 100644 --- a/spec/bundler/bundler/gem_helper_spec.rb +++ b/spec/bundler/bundler/gem_helper_spec.rb @@ -239,7 +239,7 @@ RSpec.describe Bundler::GemHelper do before do mock_build_message app_name, app_version mock_confirm_message "Tagged v#{app_version}." - mock_confirm_message "Pushed git commits and tags." + mock_confirm_message "Pushed git commits and release tag." sys_exec("git push -u origin master", :dir => app_path) end @@ -262,7 +262,7 @@ RSpec.describe Bundler::GemHelper do before do Bundler::GemHelper.tag_prefix = "foo-" mock_build_message app_name, app_version - mock_confirm_message "Pushed git commits and tags." + mock_confirm_message "Pushed git commits and release tag." sys_exec("git push -u origin master", :dir => app_path) expect(subject).to receive(:rubygem_push).with(app_gem_path.to_s) diff --git a/spec/bundler/bundler/source_list_spec.rb b/spec/bundler/bundler/source_list_spec.rb index 93159998c6..3a0691b959 100644 --- a/spec/bundler/bundler/source_list_spec.rb +++ b/spec/bundler/bundler/source_list_spec.rb @@ -75,7 +75,7 @@ RSpec.describe Bundler::SourceList do let(:msg) do "The git source `git://existing-git.org/path.git` " \ "uses the `git` protocol, which transmits data without encryption. " \ - "Disable this warning with `bundle config set git.allow_insecure true`, " \ + "Disable this warning with `bundle config set --local git.allow_insecure true`, " \ "or switch to the `https` protocol to keep your data secure." end diff --git a/spec/bundler/bundler/source_spec.rb b/spec/bundler/bundler/source_spec.rb index 0c35c27fdf..af370bb45c 100644 --- a/spec/bundler/bundler/source_spec.rb +++ b/spec/bundler/bundler/source_spec.rb @@ -188,7 +188,7 @@ RSpec.describe Bundler::Source do end end -private + private def with_ui(ui) old_ui = Bundler.ui diff --git a/spec/bundler/cache/git_spec.rb b/spec/bundler/cache/git_spec.rb index d481e00666..97d73907db 100644 --- a/spec/bundler/cache/git_spec.rb +++ b/spec/bundler/cache/git_spec.rb @@ -174,32 +174,6 @@ RSpec.describe "bundle cache with git" do expect(the_bundle).to include_gems "has_submodule 1.0" end - it "displays warning message when detecting git repo in Gemfile", :bundler => "< 3" do - build_git "foo" - - install_gemfile <<-G - gem "foo", :git => '#{lib_path("foo-1.0")}' - G - - bundle :cache - - expect(err).to include("Your Gemfile contains path and git dependencies.") - end - - it "does not display warning message if cache_all is set in bundle config" do - build_git "foo" - - install_gemfile <<-G - gem "foo", :git => '#{lib_path("foo-1.0")}' - G - - bundle "config set cache_all true" - bundle :cache - bundle :cache - - expect(err).not_to include("Your Gemfile contains path and git dependencies.") - end - it "caches pre-evaluated gemspecs" do git = build_git "foo" diff --git a/spec/bundler/cache/path_spec.rb b/spec/bundler/cache/path_spec.rb index 0c84d242b5..c81dda7405 100644 --- a/spec/bundler/cache/path_spec.rb +++ b/spec/bundler/cache/path_spec.rb @@ -91,7 +91,7 @@ RSpec.describe "bundle cache with path" do expect(bundled_app("vendor/cache/foo-1.0")).not_to exist end - it "raises a warning without --all", :bundler => "< 3" do + it "does not cache path gems by default", :bundler => "< 3" do build_lib "foo" install_gemfile <<-G @@ -99,10 +99,22 @@ RSpec.describe "bundle cache with path" do G bundle :cache - expect(err).to match(/please pass the \-\-all flag/) + expect(err).to be_empty expect(bundled_app("vendor/cache/foo-1.0")).not_to exist end + it "caches path gems by default", :bundler => "3" do + build_lib "foo" + + install_gemfile <<-G + gem "foo", :path => '#{lib_path("foo-1.0")}' + G + + bundle :cache + expect(err).to be_empty + expect(bundled_app("vendor/cache/foo-1.0")).to exist + end + it "stores the given flag" do build_lib "foo" diff --git a/spec/bundler/commands/clean_spec.rb b/spec/bundler/commands/clean_spec.rb index 0ecdf230f9..bd8e7f16c7 100644 --- a/spec/bundler/commands/clean_spec.rb +++ b/spec/bundler/commands/clean_spec.rb @@ -625,6 +625,32 @@ RSpec.describe "bundle clean" do expect(out).to eq("1.0") end + it "when using --force, it doesn't remove default gem binaries" do + skip "does not work on ruby 3.0 because it changes the path to look for default gems, tsort is a default gem there, and we can't install it either like we do with fiddle because it doesn't yet exist" unless RUBY_VERSION < "3.0.0" + + skip "does not work on rubygems versions where `--install_dir` doesn't respect --default" unless Gem::Installer.for_spec(loaded_gemspec, :install_dir => "/foo").default_spec_file == "/foo/specifications/default/bundler-#{Bundler::VERSION}.gemspec" # Since rubygems 3.2.0.rc.2 + + default_irb_version = ruby "gem 'irb', '< 999999'; require 'irb'; puts IRB::VERSION", :raise_on_error => false + skip "irb isn't a default gem" if default_irb_version.empty? + + build_repo2 do + # simulate executable for default gem + build_gem "irb", default_irb_version, :to_system => true, :default => true do |s| + s.executables = "irb" + end + end + + realworld_system_gems "fiddle" + + install_gemfile <<-G + source "#{file_uri_for(gem_repo2)}" + G + + bundle "clean --force", :env => { "BUNDLER_GEM_DEFAULT_DIR" => system_gem_path.to_s } + + expect(out).not_to include("Removing irb") + end + it "doesn't blow up on path gems without a .gemspec" do relative_path = "vendor/private_gems/bar-1.0" absolute_path = bundled_app(relative_path) diff --git a/spec/bundler/commands/fund_spec.rb b/spec/bundler/commands/fund_spec.rb new file mode 100644 index 0000000000..ee3aff3a29 --- /dev/null +++ b/spec/bundler/commands/fund_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +RSpec.describe "bundle fund" do + it "prints fund information for all gems in the bundle" do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem 'has_metadata' + gem 'has_funding' + gem 'rack-obama' + G + + bundle "fund" + + expect(out).to include("* has_metadata (1.0)\n Funding: https://example.com/has_metadata/funding") + expect(out).to include("* has_funding (1.2.3)\n Funding: https://example.com/has_funding/funding") + expect(out).to_not include("rack-obama") + end + + it "does not consider fund information for gem dependencies" do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem 'gem_with_dependent_funding' + G + + bundle "fund" + + expect(out).to_not include("* has_funding (1.2.3)\n Funding: https://example.com/has_funding/funding") + expect(out).to_not include("gem_with_dependent_funding") + end + + it "prints message if none of the gems have fund information" do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem 'rack-obama' + G + + bundle "fund" + + expect(out).to include("None of the installed gems you directly depend on are looking for funding.") + end + + describe "with --group option" do + it "prints fund message for only specified group gems" do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem 'has_metadata', :group => :development + gem 'has_funding' + G + + bundle "fund --group development" + expect(out).to include("* has_metadata (1.0)\n Funding: https://example.com/has_metadata/funding") + expect(out).to_not include("* has_funding (1.2.3)\n Funding: https://example.com/has_funding/funding") + end + end +end diff --git a/spec/bundler/commands/help_spec.rb b/spec/bundler/commands/help_spec.rb index 788c1b8d29..03d34ef692 100644 --- a/spec/bundler/commands/help_spec.rb +++ b/spec/bundler/commands/help_spec.rb @@ -1,25 +1,25 @@ # frozen_string_literal: true RSpec.describe "bundle help" do - it "uses mann when available" do + it "uses man when available" do with_fake_man do bundle "help gemfile" end expect(out).to eq(%(["#{root}/man/gemfile.5"])) end - it "prefixes bundle commands with bundle- when finding the groff files" do + it "prefixes bundle commands with bundle- when finding the man files" do with_fake_man do bundle "help install" end expect(out).to eq(%(["#{root}/man/bundle-install.1"])) end - it "simply outputs the txt file when there is no man on the path" do + it "simply outputs the human readable file when there is no man on the path" do with_path_as("") do bundle "help install" end - expect(out).to match(/BUNDLE-INSTALL/) + expect(out).to match(/bundle-install/) end it "still outputs the old help for commands that do not have man pages yet" do diff --git a/spec/bundler/commands/info_spec.rb b/spec/bundler/commands/info_spec.rb index 9286e6824a..eec9c773bc 100644 --- a/spec/bundler/commands/info_spec.rb +++ b/spec/bundler/commands/info_spec.rb @@ -66,6 +66,7 @@ RSpec.describe "bundle info" do \tHomepage: http://example.com \tDocumentation: https://www.example.info/gems/bestgemever/0.0.1 \tSource Code: https://example.com/user/bestgemever +\tFunding: https://example.com/has_metadata/funding \tWiki: https://example.com/user/bestgemever/wiki \tChangelog: https://example.com/user/bestgemever/CHANGELOG.md \tBug Tracker: https://example.com/user/bestgemever/issues diff --git a/spec/bundler/commands/install_spec.rb b/spec/bundler/commands/install_spec.rb index 98290bbc9e..d1b8585114 100644 --- a/spec/bundler/commands/install_spec.rb +++ b/spec/bundler/commands/install_spec.rb @@ -497,11 +497,21 @@ RSpec.describe "bundle install with gem sources" do #{Bundler::VERSION} L end + + it "does not crash when unlocking" do + gemfile <<-G + ruby '>= 2.1.0' + G + + bundle "update" + + expect(err).not_to include("Could not find gem 'Ruby") + end end end describe "when Bundler root contains regex chars" do - it "doesn't blow up" do + it "doesn't blow up when using the `gem` DSL" do root_dir = tmp("foo[]bar") FileUtils.mkdir_p(root_dir) @@ -516,6 +526,22 @@ RSpec.describe "bundle install with gem sources" do bundle :install, :dir => root_dir end + + it "doesn't blow up when using the `gemspec` DSL" do + root_dir = tmp("foo[]bar") + + FileUtils.mkdir_p(root_dir) + + build_lib "foo", :path => root_dir + gemfile = <<-G + gemspec + G + File.open("#{root_dir}/Gemfile", "w") do |file| + file.puts gemfile + end + + bundle :install, :dir => root_dir + end end describe "when requesting a quiet install via --quiet" do diff --git a/spec/bundler/commands/newgem_spec.rb b/spec/bundler/commands/newgem_spec.rb index 70419f612d..beee2b0fdc 100644 --- a/spec/bundler/commands/newgem_spec.rb +++ b/spec/bundler/commands/newgem_spec.rb @@ -12,11 +12,12 @@ RSpec.describe "bundle gem" do def bundle_exec_rubocop prepare_gemspec(bundled_app(gem_name, "#{gem_name}.gemspec")) - rubocop_version = RUBY_VERSION > "2.4" ? "0.85.1" : "0.80.1" + rubocop_version = RUBY_VERSION > "2.4" ? "0.90.0" : "0.80.1" gems = ["minitest", "rake", "rake-compiler", "rspec", "rubocop -v #{rubocop_version}", "test-unit"] + gems += ["rubocop-ast -v 0.4.0"] if rubocop_version == "0.90.0" path = Bundler.feature_flag.default_install_uses_path? ? local_gem_path(:base => bundled_app(gem_name)) : system_gem_path realworld_system_gems gems, :path => path - bundle "exec rubocop --config .rubocop.yml", :dir => bundled_app(gem_name) + bundle "exec rubocop --debug --config .rubocop.yml", :dir => bundled_app(gem_name) end let(:generated_gemspec) { Bundler.load_gemspec_uncached(bundled_app(gem_name).join("#{gem_name}.gemspec")) } diff --git a/spec/bundler/commands/outdated_spec.rb b/spec/bundler/commands/outdated_spec.rb index 2a07f1c784..1faee23f26 100644 --- a/spec/bundler/commands/outdated_spec.rb +++ b/spec/bundler/commands/outdated_spec.rb @@ -555,7 +555,7 @@ RSpec.describe "bundle outdated" do end end - context "after bundle config set deployment true" do + context "after bundle config set --local deployment true" do before do install_gemfile <<-G source "#{file_uri_for(gem_repo2)}" @@ -563,7 +563,7 @@ RSpec.describe "bundle outdated" do gem "rack" gem "foo" G - bundle "config set deployment true" + bundle "config set --local deployment true" end it "outputs a helpful message about being in deployment mode" do diff --git a/spec/bundler/install/deploy_spec.rb b/spec/bundler/install/deploy_spec.rb index 357f4512f1..441daabe72 100644 --- a/spec/bundler/install/deploy_spec.rb +++ b/spec/bundler/install/deploy_spec.rb @@ -361,7 +361,10 @@ RSpec.describe "install in deployment or frozen mode" do bundle "config --local deployment true" bundle :install, :raise_on_error => false expect(err).to include("deployment mode") - expect(err).to include("You have deleted from the Gemfile:\n* source: #{lib_path("rack-1.0")} (at master@#{revision_for(lib_path("rack-1.0"))[0..6]}") + # The drive letter of the Windows environment is fragile value in GitHub Actions + unless Gem.win_platform? + expect(err).to include("You have deleted from the Gemfile:\n* source: #{lib_path("rack-1.0")} (at master@#{revision_for(lib_path("rack-1.0"))[0..6]}") + end expect(err).not_to include("You have added to the Gemfile") expect(err).not_to include("You have changed in the Gemfile") end @@ -385,7 +388,10 @@ RSpec.describe "install in deployment or frozen mode" do bundle "config --local deployment true" bundle :install, :raise_on_error => false expect(err).to include("deployment mode") - expect(err).to include("You have changed in the Gemfile:\n* rack from `no specified source` to `#{lib_path("rack")} (at master@#{revision_for(lib_path("rack"))[0..6]})`") + # The drive letter of the Windows environment is fragile value in GitHub Actions + unless Gem.win_platform? + expect(err).to include("You have changed in the Gemfile:\n* rack from `no specified source` to `#{lib_path("rack")} (at master@#{revision_for(lib_path("rack"))[0..6]})`") + end expect(err).not_to include("You have added to the Gemfile") expect(err).not_to include("You have deleted from the Gemfile") end diff --git a/spec/bundler/install/gemfile/git_spec.rb b/spec/bundler/install/gemfile/git_spec.rb index c0e2510acd..a70fb18c45 100644 --- a/spec/bundler/install/gemfile/git_spec.rb +++ b/spec/bundler/install/gemfile/git_spec.rb @@ -864,6 +864,24 @@ RSpec.describe "bundle install with git sources" do expect(the_bundle).to include_gems "has_submodule 1.0" end + it "does not warn when deiniting submodules" do + build_git "submodule", "1.0" + build_git "has_submodule", "1.0" + + sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0", :dir => lib_path("has_submodule-1.0") + sys_exec "git commit -m \"submodulator\"", :dir => lib_path("has_submodule-1.0") + + install_gemfile <<-G + git "#{lib_path("has_submodule-1.0")}" do + gem "has_submodule" + end + G + expect(err).to be_empty + + expect(the_bundle).to include_gems "has_submodule 1.0" + expect(the_bundle).to_not include_gems "submodule 1.0" + end + it "handles implicit updates when modifying the source info" do git = build_git "foo" diff --git a/spec/bundler/install/gemfile/platform_spec.rb b/spec/bundler/install/gemfile/platform_spec.rb index dd58aef29b..41b95481cb 100644 --- a/spec/bundler/install/gemfile/platform_spec.rb +++ b/spec/bundler/install/gemfile/platform_spec.rb @@ -50,6 +50,31 @@ RSpec.describe "bundle install across platforms" do expect(the_bundle).to include_gems "platform_specific 1.0 JAVA" end + it "pulls the pure ruby version on jruby if the java platform is not present in the lockfile and bundler is run in frozen mode", :jruby do + lockfile <<-G + GEM + remote: #{file_uri_for(gem_repo1)} + specs: + platform_specific (1.0) + + PLATFORMS + ruby + + DEPENDENCIES + platform_specific + G + + bundle "config set --local frozen true" + + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + + gem "platform_specific" + G + + expect(the_bundle).to include_gems "platform_specific 1.0 RUBY" + end + it "works with gems that have different dependencies" do simulate_platform "java" install_gemfile <<-G @@ -250,12 +275,41 @@ RSpec.describe "bundle install across platforms" do expect(err).to include "Unable to use the platform-specific (universal-darwin) version of facter (2.4.6) " \ "because it has different dependencies from the ruby version. " \ - "To use the platform-specific version of the gem, run `bundle config set specific_platform true` and install again." + "To use the platform-specific version of the gem, run `bundle config set --local specific_platform true` and install again." expect(the_bundle).to include_gem "facter 2.4.6" expect(the_bundle).not_to include_gem "CFPropertyList" end + it "works with gems with platform-specific dependency having different requirements order" do + simulate_platform x64_mac + + update_repo2 do + build_gem "fspath", "3" + build_gem "image_optim_pack", "1.2.3" do |s| + s.add_runtime_dependency "fspath", ">= 2.1", "< 4" + end + build_gem "image_optim_pack", "1.2.3" do |s| + s.platform = "universal-darwin" + s.add_runtime_dependency "fspath", "< 4", ">= 2.1" + end + end + + install_gemfile <<-G + source "#{file_uri_for(gem_repo2)}" + G + + install_gemfile <<-G + source "#{file_uri_for(gem_repo2)}" + + gem "image_optim_pack" + G + + expect(err).not_to include "Unable to use the platform-specific" + + expect(the_bundle).to include_gem "image_optim_pack 1.2.3 universal-darwin" + end + it "fetches gems again after changing the version of Ruby" do gemfile <<-G source "#{file_uri_for(gem_repo1)}" diff --git a/spec/bundler/install/gems/compact_index_spec.rb b/spec/bundler/install/gems/compact_index_spec.rb index 6e5177c60d..5ef3f38fe7 100644 --- a/spec/bundler/install/gems/compact_index_spec.rb +++ b/spec/bundler/install/gems/compact_index_spec.rb @@ -690,7 +690,7 @@ The checksum of /versions does not match the checksum provided by the server! So it "shows instructions if auth is not provided for the source" do bundle :install, :artifice => "compact_index_strict_basic_authentication", :raise_on_error => false - expect(err).to include("bundle config set #{source_hostname} username:password") + expect(err).to include("bundle config set --global #{source_hostname} username:password") end it "fails if authentication has already been provided, but failed" do @@ -878,7 +878,7 @@ The checksum of /versions does not match the checksum provided by the server! So and include("1. delete the downloaded gem located at: `#{default_bundle_path}/gems/rack-1.0.0/rack-1.0.0.gem`"). and include("2. run `bundle install`"). and include("If you wish to continue installing the downloaded gem, and are certain it does not pose a security issue despite the mismatching checksum, do the following:"). - and include("1. run `bundle config set disable_checksum_validation true` to turn off checksum verification"). + and include("1. run `bundle config set --local disable_checksum_validation true` to turn off checksum verification"). and include("2. run `bundle install`"). and match(/\(More info: The expected SHA256 checksum was "#{"ab" * 22}", but the checksum for the downloaded gem was ".+?"\.\)/) end diff --git a/spec/bundler/install/gems/dependency_api_spec.rb b/spec/bundler/install/gems/dependency_api_spec.rb index 765b5e5195..e92669e97c 100644 --- a/spec/bundler/install/gems/dependency_api_spec.rb +++ b/spec/bundler/install/gems/dependency_api_spec.rb @@ -664,7 +664,7 @@ RSpec.describe "gemcutter's dependency API" do it "shows instructions if auth is not provided for the source" do bundle :install, :artifice => "endpoint_strict_basic_authentication", :raise_on_error => false - expect(err).to include("bundle config set #{source_hostname} username:password") + expect(err).to include("bundle config set --global #{source_hostname} username:password") end it "fails if authentication has already been provided, but failed" do diff --git a/spec/bundler/install/gems/fund_spec.rb b/spec/bundler/install/gems/fund_spec.rb new file mode 100644 index 0000000000..57e7c3aed3 --- /dev/null +++ b/spec/bundler/install/gems/fund_spec.rb @@ -0,0 +1,110 @@ +# frozen_string_literal: true + +RSpec.describe "bundle install" do + context "with gem sources" do + context "when gems include a fund URI" do + it "displays the plural fund message after installing" do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem 'has_metadata' + gem 'has_funding' + gem 'rack-obama' + G + + expect(out).to include("2 installed gems you directly depend on are looking for funding.") + end + + it "displays the singular fund message after installing" do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem 'has_funding' + gem 'rack-obama' + G + + expect(out).to include("1 installed gem you directly depend on is looking for funding.") + end + end + + context "when gems do not include fund messages" do + it "does not display any fund messages" do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "activesupport" + G + + expect(out).not_to include("gem you depend on") + end + end + + context "when a dependency includes a fund message" do + it "does not display the fund message" do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem 'gem_with_dependent_funding' + G + + expect(out).not_to include("gem you depend on") + end + end + end + + context "with git sources" do + context "when gems include fund URI" do + it "displays the fund message after installing" do + build_git "also_has_funding" do |s| + s.metadata = { + "funding_uri" => "https://example.com/also_has_funding/funding", + } + end + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem 'also_has_funding', :git => '#{lib_path("also_has_funding-1.0")}' + G + + expect(out).to include("1 installed gem you directly depend on is looking for funding.") + end + + it "displays the fund message if repo is updated" do + build_git "also_has_funding" do |s| + s.metadata = { + "funding_uri" => "https://example.com/also_has_funding/funding", + } + end + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem 'also_has_funding', :git => '#{lib_path("also_has_funding-1.0")}' + G + + build_git "also_has_funding", "1.1" do |s| + s.metadata = { + "funding_uri" => "https://example.com/also_has_funding/funding", + } + end + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem 'also_has_funding', :git => '#{lib_path("also_has_funding-1.1")}' + G + + expect(out).to include("1 installed gem you directly depend on is looking for funding.") + end + + it "displays the fund message if repo is not updated" do + build_git "also_has_funding" do |s| + s.metadata = { + "funding_uri" => "https://example.com/also_has_funding/funding", + } + end + gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem 'also_has_funding', :git => '#{lib_path("also_has_funding-1.0")}' + G + + bundle :install + expect(out).to include("1 installed gem you directly depend on is looking for funding.") + + bundle :install + expect(out).to include("1 installed gem you directly depend on is looking for funding.") + end + end + end +end diff --git a/spec/bundler/install/gems/resolving_spec.rb b/spec/bundler/install/gems/resolving_spec.rb index f72220ef21..f621b01366 100644 --- a/spec/bundler/install/gems/resolving_spec.rb +++ b/spec/bundler/install/gems/resolving_spec.rb @@ -107,10 +107,13 @@ RSpec.describe "bundle install with install-time dependencies" do bundle :install, :env => { "DEBUG_RESOLVER_TREE" => "1" } + activated_groups = "net_b (1.0) (ruby)" + activated_groups += ", net_b (1.0) (#{local_platforms.join(", ")})" if local_platforms.any? && local_platforms != ["ruby"] + expect(err).to include(" net_b"). and include("BUNDLER: Starting resolution"). and include("BUNDLER: Finished resolution"). - and include("Attempting to activate") + and include("Attempting to activate [#{activated_groups}]") end end end @@ -233,7 +236,7 @@ RSpec.describe "bundle install with install-time dependencies" do describe "with a < requirement" do let(:ruby_requirement) { %("< 5000") } - let(:error_message_requirement) { Gem::Requirement.new(["< 5000", "= #{Bundler::RubyVersion.system.to_gem_version_with_patchlevel}"]).to_s } + let(:error_message_requirement) { "< 5000" } it_behaves_like "ruby version conflicts" end @@ -241,7 +244,7 @@ RSpec.describe "bundle install with install-time dependencies" do describe "with a compound requirement" do let(:reqs) { ["> 0.1", "< 5000"] } let(:ruby_requirement) { reqs.map(&:dump).join(", ") } - let(:error_message_requirement) { Gem::Requirement.new(reqs + ["= #{Bundler::RubyVersion.system.to_gem_version_with_patchlevel}"]).to_s } + let(:error_message_requirement) { Gem::Requirement.new(reqs).to_s } it_behaves_like "ruby version conflicts" end diff --git a/spec/bundler/install/gems/standalone_spec.rb b/spec/bundler/install/gems/standalone_spec.rb index 503cc4a4f0..02452f1ef6 100644 --- a/spec/bundler/install/gems/standalone_spec.rb +++ b/spec/bundler/install/gems/standalone_spec.rb @@ -81,8 +81,8 @@ RSpec.shared_examples "bundle install --standalone" do it "generates a bundle/bundler/setup.rb with the proper paths" do expected_path = bundled_app("bundle/bundler/setup.rb") extension_line = File.read(expected_path).each_line.find {|line| line.include? "/extensions/" }.strip - expect(extension_line).to start_with '$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/' - expect(extension_line).to end_with '/very_simple_binary-1.0"' + expect(extension_line).to start_with '$:.unshift File.expand_path("#{path}/../#{ruby_engine}/#{ruby_version}/extensions/' + expect(extension_line).to end_with '/very_simple_binary-1.0")' end end diff --git a/spec/bundler/install/path_spec.rb b/spec/bundler/install/path_spec.rb index 2239706020..a05467db12 100644 --- a/spec/bundler/install/path_spec.rb +++ b/spec/bundler/install/path_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe "bundle install" do - describe "with --path" do + describe "with path configured" do before :each do build_gem "rack", "1.0.0", :to_system => true do |s| s.write "lib/rack.rb", "puts 'FAIL'" @@ -13,12 +13,20 @@ RSpec.describe "bundle install" do G end - it "does not use available system gems with bundle --path vendor/bundle", :bundler => "< 3" do + it "does not use available system gems with `vendor/bundle" do bundle "config --local path vendor/bundle" bundle :install expect(the_bundle).to include_gems "rack 1.0.0" end + it "uses system gems with `path.system` configured with more priority than `path`" do + bundle "config --local path.system true" + bundle "config --global path vendor/bundle" + bundle :install + run "require 'rack'", :raise_on_error => false + expect(out).to include("FAIL") + end + it "handles paths with regex characters in them" do dir = bundled_app("bun++dle") dir.mkpath @@ -30,7 +38,7 @@ RSpec.describe "bundle install" do dir.rmtree end - it "prints a warning to let the user know what has happened with bundle --path vendor/bundle" do + it "prints a message to let the user know where gems where installed" do bundle "config --local path vendor/bundle" bundle :install expect(out).to include("gems are installed into `./vendor/bundle`") diff --git a/spec/bundler/lock/lockfile_spec.rb b/spec/bundler/lock/lockfile_spec.rb index 6eaa6f05cf..d26dc789cc 100644 --- a/spec/bundler/lock/lockfile_spec.rb +++ b/spec/bundler/lock/lockfile_spec.rb @@ -1476,7 +1476,7 @@ RSpec.describe "the lockfile format" do expect(err).to match(/git checkout HEAD -- Gemfile.lock/i) end -private + private def prerelease?(version) Gem::Version.new(version).prerelease? diff --git a/spec/bundler/other/major_deprecation_spec.rb b/spec/bundler/other/major_deprecation_spec.rb index 2ca6717827..d061ca7064 100644 --- a/spec/bundler/other/major_deprecation_spec.rb +++ b/spec/bundler/other/major_deprecation_spec.rb @@ -113,7 +113,7 @@ RSpec.describe "major deprecations" do expect(deprecations).to include( "The `--path` flag is deprecated because it relies on being " \ "remembered across bundler invocations, which bundler will no " \ - "longer do in future versions. Instead please use `bundle config set " \ + "longer do in future versions. Instead please use `bundle config set --local " \ "path 'vendor/bundle'`, and stop using this flag" ) end @@ -135,7 +135,7 @@ RSpec.describe "major deprecations" do expect(deprecations).to include( "The `--path` flag is deprecated because it relies on being " \ "remembered across bundler invocations, which bundler will no " \ - "longer do in future versions. Instead please use `bundle config set " \ + "longer do in future versions. Instead please use `bundle config set --local " \ "path 'vendor/bundle'`, and stop using this flag" ) end @@ -143,6 +143,28 @@ RSpec.describe "major deprecations" do pending "should fail with a helpful error", :bundler => "3" end + context "bundle cache --all" do + before do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack" + G + + bundle "cache --all", :raise_on_error => false + end + + it "should print a deprecation warning", :bundler => "2" do + expect(deprecations).to include( + "The `--all` flag is deprecated because it relies on being " \ + "remembered across bundler invocations, which bundler will no " \ + "longer do in future versions. Instead please use `bundle config set " \ + "cache_all true`, and stop using this flag" + ) + end + + pending "should fail with a helpful error", :bundler => "3" + end + describe "bundle config" do describe "old list interface" do before do @@ -271,7 +293,7 @@ RSpec.describe "major deprecations" do end it "should output a deprecation warning", :bundler => "2" do - expect(deprecations).to include("The --binstubs option will be removed in favor of `bundle binstubs`") + expect(deprecations).to include("The --binstubs option will be removed in favor of `bundle binstubs --all`") end pending "fails with a helpful error", :bundler => "3" @@ -339,7 +361,7 @@ RSpec.describe "major deprecations" do "The `#{flag_name}` flag is deprecated because it relies on " \ "being remembered across bundler invocations, which bundler " \ "will no longer do in future versions. Instead please use " \ - "`bundle config set #{option_name} '#{value}'`, and stop using this flag" + "`bundle config set --local #{option_name} '#{value}'`, and stop using this flag" ) end @@ -362,7 +384,7 @@ RSpec.describe "major deprecations" do "Using `source` more than once without a block is a security risk, and " \ "may result in installing unexpected gems. To resolve this warning, use " \ "a block to indicate which gems should come from the secondary source. " \ - "To upgrade this warning to an error, run `bundle config set " \ + "To upgrade this warning to an error, run `bundle config set --local " \ "disable_multisource true`." ) end diff --git a/spec/bundler/plugins/command_spec.rb b/spec/bundler/plugins/command_spec.rb index 4728f66f5f..4567a39081 100644 --- a/spec/bundler/plugins/command_spec.rb +++ b/spec/bundler/plugins/command_spec.rb @@ -73,7 +73,7 @@ RSpec.describe "command plugins" do expect(out).not_to include("Installed plugin copycat") - expect(err).to include("Failed to install plugin") + expect(err).to include("Failed to install the following plugins: `copycat`") expect(err).to include("Command(s) `mahcommand` declared by copycat are already registered.") end diff --git a/spec/bundler/plugins/install_spec.rb b/spec/bundler/plugins/install_spec.rb index ac5a28891b..a91175c616 100644 --- a/spec/bundler/plugins/install_spec.rb +++ b/spec/bundler/plugins/install_spec.rb @@ -98,7 +98,7 @@ RSpec.describe "bundler plugin install" do bundle "plugin install charlie --source #{file_uri_for(gem_repo2)}" - expect(err).to include("plugins.rb was not found") + expect(err).to include("Failed to install the following plugins: `charlie`. The underlying error was: plugins.rb was not found") expect(global_plugin_gem("charlie-1.0")).not_to be_directory diff --git a/spec/bundler/quality_spec.rb b/spec/bundler/quality_spec.rb index d57098be47..b0647b7663 100644 --- a/spec/bundler/quality_spec.rb +++ b/spec/bundler/quality_spec.rb @@ -105,7 +105,7 @@ RSpec.describe "The library itself" do end it "has no malformed whitespace" do - exempt = /\.gitmodules|fixtures|vendor|LICENSE|vcr_cassettes|rbreadline\.diff|\.txt$/ + exempt = /\.gitmodules|fixtures|vendor|LICENSE|vcr_cassettes|rbreadline\.diff|index\.txt$/ error_messages = [] tracked_files.each do |filename| next if filename =~ exempt @@ -126,7 +126,7 @@ RSpec.describe "The library itself" do end it "does not include any leftover debugging or development mechanisms" do - exempt = %r{quality_spec.rb|support/helpers|vcr_cassettes|\.md|\.ronn|\.txt|\.5|\.1} + exempt = %r{quality_spec.rb|support/helpers|vcr_cassettes|\.md|\.ronn|index\.txt|\.5|\.1} error_messages = [] tracked_files.each do |filename| next if filename =~ exempt @@ -190,7 +190,7 @@ RSpec.describe "The library itself" do line.scan(/Bundler\.settings\[:#{key_pattern}\]/).flatten.each {|s| all_settings[s] << "referenced at `#{filename}:#{number.succ}`" } end end - documented_settings = File.read("man/bundle-config.ronn")[/LIST OF AVAILABLE KEYS.*/m].scan(/^\* `#{key_pattern}`/).flatten + documented_settings = File.read("man/bundle-config.1.ronn")[/LIST OF AVAILABLE KEYS.*/m].scan(/^\* `#{key_pattern}`/).flatten documented_settings.each do |s| all_settings.delete(s) @@ -261,7 +261,7 @@ RSpec.describe "The library itself" do expect(all_bad_requires).to be_empty, "#{all_bad_requires.size} internal requires that should use `require_relative`: #{all_bad_requires}" end -private + private def each_line(filename, &block) File.readlines(filename, :encoding => "UTF-8").each_with_index(&block) diff --git a/spec/bundler/realworld/fixtures/warbler/Gemfile.lock b/spec/bundler/realworld/fixtures/warbler/Gemfile.lock index a524f6ef30..bcf0799494 100644 --- a/spec/bundler/realworld/fixtures/warbler/Gemfile.lock +++ b/spec/bundler/realworld/fixtures/warbler/Gemfile.lock @@ -6,7 +6,7 @@ PATH GEM remote: https://rubygems.org/ specs: - jruby-jars (9.2.9.0) + jruby-jars (9.2.11.1) jruby-rack (1.1.21) rake (13.0.1) rubyzip (1.3.0) @@ -26,4 +26,4 @@ DEPENDENCIES warbler (~> 2.0) BUNDLED WITH - 2.2.0.rc.1 + 2.2.0.rc.2 diff --git a/spec/bundler/realworld/gemfile_source_header_spec.rb b/spec/bundler/realworld/gemfile_source_header_spec.rb index 3f507b056a..ada2fc92ee 100644 --- a/spec/bundler/realworld/gemfile_source_header_spec.rb +++ b/spec/bundler/realworld/gemfile_source_header_spec.rb @@ -30,7 +30,7 @@ RSpec.describe "fetching dependencies with a mirrored source", :realworld => tru expect(the_bundle).to include_gems "weakling 0.0.3" end -private + private def setup_server require_rack diff --git a/spec/bundler/runtime/gem_tasks_spec.rb b/spec/bundler/runtime/gem_tasks_spec.rb index b2f9ae725e..b0ef0cc144 100644 --- a/spec/bundler/runtime/gem_tasks_spec.rb +++ b/spec/bundler/runtime/gem_tasks_spec.rb @@ -67,6 +67,18 @@ RSpec.describe "require 'bundler/gem_tasks'" do end end + context "rake build when path has brackets", :ruby_repo do + before do + bracketed_bundled_app = tmp.join("bundled[app") + FileUtils.cp_r bundled_app, bracketed_bundled_app + bundle "exec rake build", :dir => bracketed_bundled_app + end + + it "still runs successfully" do + expect(err).to be_empty + end + end + context "bundle path configured locally" do before do bundle "config set path vendor/bundle" diff --git a/spec/bundler/runtime/inline_spec.rb b/spec/bundler/runtime/inline_spec.rb index 86ac3f4bb6..1ba50c0e97 100644 --- a/spec/bundler/runtime/inline_spec.rb +++ b/spec/bundler/runtime/inline_spec.rb @@ -339,4 +339,34 @@ RSpec.describe "bundler/inline#gemfile" do expect(last_command).to be_success expect(out).to include("BUNDLE_GEMFILE is empty") end + + it "does not error out if library requires optional dependencies" do + Dir.mkdir tmp("path_without_gemfile") + + foo_code = <<~RUBY + begin + gem "bar" + rescue LoadError + end + + puts "WIN" + RUBY + + build_lib "foo", "1.0.0" do |s| + s.write "lib/foo.rb", foo_code + end + + script <<-RUBY, :dir => tmp("path_without_gemfile") + gemfile do + path "#{lib_path}" do + gem "foo", require: false + end + end + + require "foo" + RUBY + + expect(out).to eq("WIN") + expect(err).to be_empty + end end diff --git a/spec/bundler/runtime/setup_spec.rb b/spec/bundler/runtime/setup_spec.rb index 22c07f0be0..ffa909e269 100644 --- a/spec/bundler/runtime/setup_spec.rb +++ b/spec/bundler/runtime/setup_spec.rb @@ -623,6 +623,26 @@ RSpec.describe "Bundler.setup" do expect(the_bundle).to include_gems "activesupport 2.3.2" end + it "remembers --without and does not bail on bare Bundler.setup, even in the case of path gems no longer available" do + bundle "config --local without development" + + path = bundled_app(File.join("vendor", "foo")) + build_lib "foo", :path => path + + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "activesupport", "2.3.2" + gem 'foo', :path => 'vendor/foo', :group => :development + G + + FileUtils.rm_rf(path) + + ruby "require 'bundler'; Bundler.setup", :env => { "DEBUG" => "1" } + expect(out).to include("Assuming that source at `vendor/foo` has not changed since fetching its specs errored") + expect(out).to include("Found no changes, using resolution from the lockfile") + expect(err).to be_empty + end + it "remembers --without and does not include groups passed to Bundler.setup" do bundle "config --local without rails" install_gemfile <<-G diff --git a/spec/bundler/runtime/with_unbundled_env_spec.rb b/spec/bundler/runtime/with_unbundled_env_spec.rb index 67a25f6ff2..03de830ea0 100644 --- a/spec/bundler/runtime/with_unbundled_env_spec.rb +++ b/spec/bundler/runtime/with_unbundled_env_spec.rb @@ -84,11 +84,23 @@ RSpec.describe "Bundler.with_env helpers" do expect(last_command.stdboth).to include "false" end - it "should remove '-rbundler/setup' from RUBYOPT" do + it "should remove absolute path to 'bundler/setup' from RUBYOPT even if it was present in original env" do create_file("source.rb", <<-RUBY) print #{modified_env}['RUBYOPT'] RUBY - ENV["RUBYOPT"] = "-W2 -rbundler/setup #{ENV["RUBYOPT"]}" + setup_require = "-r#{lib_dir}/bundler/setup" + ENV["BUNDLER_ORIG_RUBYOPT"] = "-W2 #{setup_require} #{ENV["RUBYOPT"]}" + 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(setup_require) + end + + it "should remove relative path to 'bundler/setup' from RUBYOPT even if it was present in original env" do + create_file("source.rb", <<-RUBY) + print #{modified_env}['RUBYOPT'] + RUBY + ENV["BUNDLER_ORIG_RUBYOPT"] = "-W2 -rbundler/setup #{ENV["RUBYOPT"]}" simulate_bundler_version_when_missing_prerelease_default_gem_activation do bundle_exec_ruby bundled_app("source.rb") end diff --git a/spec/bundler/spec_helper.rb b/spec/bundler/spec_helper.rb index 7ed5bda8e6..a259100b2a 100644 --- a/spec/bundler/spec_helper.rb +++ b/spec/bundler/spec_helper.rb @@ -15,6 +15,7 @@ require "rspec/expectations" require "rspec/mocks" require_relative "support/builders" +require_relative "support/build_metadata" require_relative "support/filters" require_relative "support/helpers" require_relative "support/indexes" diff --git a/spec/bundler/support/build_metadata.rb b/spec/bundler/support/build_metadata.rb new file mode 100644 index 0000000000..98d8ac23c8 --- /dev/null +++ b/spec/bundler/support/build_metadata.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require_relative "path" +require_relative "helpers" + +module Spec + module BuildMetadata + include Spec::Path + include Spec::Helpers + + def write_build_metadata(dir: source_root) + build_metadata = { + :git_commit_sha => git_commit_sha, + :built_at => loaded_gemspec.date.utc.strftime("%Y-%m-%d"), + :release => true, + } + + replace_build_metadata(build_metadata, dir: dir) # rubocop:disable Style/HashSyntax + end + + def reset_build_metadata(dir: source_root) + build_metadata = { + :release => false, + } + + replace_build_metadata(build_metadata, dir: dir) # rubocop:disable Style/HashSyntax + end + + private + + def replace_build_metadata(build_metadata, dir:) + 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 git_commit_sha + ruby_core_tarball? ? "unknown" : sys_exec("git rev-parse --short HEAD", :dir => source_root).strip + end + + extend self + end +end diff --git a/spec/bundler/support/builders.rb b/spec/bundler/support/builders.rb index 65f30d1f38..a1770759a9 100644 --- a/spec/bundler/support/builders.rb +++ b/spec/bundler/support/builders.rb @@ -322,10 +322,21 @@ module Spec "documentation_uri" => "https://www.example.info/gems/bestgemever/0.0.1", "homepage_uri" => "https://bestgemever.example.io", "mailing_list_uri" => "https://groups.example.com/bestgemever", + "funding_uri" => "https://example.com/has_metadata/funding", "source_code_uri" => "https://example.com/user/bestgemever", "wiki_uri" => "https://example.com/user/bestgemever/wiki", } end + + build_gem "has_funding", "1.2.3" do |s| + s.metadata = { + "funding_uri" => "https://example.com/has_funding/funding", + } + end + + build_gem "gem_with_dependent_funding", "1.0" do |s| + s.add_dependency "has_funding" + end end end @@ -461,7 +472,7 @@ module Spec build_with(PluginBuilder, name, args, &blk) end - private + private def build_with(builder, name, args, &blk) @_build_path ||= nil @@ -758,7 +769,7 @@ module Spec gem_path = File.expand_path("#{@spec.full_name}.gem", lib_path) if opts[:to_system] - @context.system_gems gem_path + @context.system_gems gem_path, :default => opts[:default] elsif opts[:to_bundle] @context.system_gems gem_path, :path => @context.default_bundle_path else diff --git a/spec/bundler/support/filters.rb b/spec/bundler/support/filters.rb index 6322efda8b..b1978e44e6 100644 --- a/spec/bundler/support/filters.rb +++ b/spec/bundler/support/filters.rb @@ -26,7 +26,6 @@ RSpec.configure do |config| git_version = Bundler::Source::Git::GitProxy.new(nil, nil, nil).version - config.filter_run_excluding :rubygems => RequirementChecker.against(Gem::VERSION) config.filter_run_excluding :git => RequirementChecker.against(git_version) config.filter_run_excluding :bundler => RequirementChecker.against(Bundler::VERSION.split(".")[0]) config.filter_run_excluding :ruby_repo => !ENV["GEM_COMMAND"].nil? diff --git a/spec/bundler/support/hax.rb b/spec/bundler/support/hax.rb index 7529dc460a..fc8e0ad55d 100644 --- a/spec/bundler/support/hax.rb +++ b/spec/bundler/support/hax.rb @@ -9,6 +9,8 @@ module Gem Gem.ruby = ENV["RUBY"] end + @default_dir = ENV["BUNDLER_GEM_DEFAULT_DIR"] if ENV["BUNDLER_GEM_DEFAULT_DIR"] + if ENV["BUNDLER_SPEC_PLATFORM"] class Platform @local = new(ENV["BUNDLER_SPEC_PLATFORM"]) diff --git a/spec/bundler/support/helpers.rb b/spec/bundler/support/helpers.rb index b5648b84a8..c4018eb818 100644 --- a/spec/bundler/support/helpers.rb +++ b/spec/bundler/support/helpers.rb @@ -290,26 +290,30 @@ module Spec gems = gems.flatten options = gems.last.is_a?(Hash) ? gems.pop : {} path = options.fetch(:path, system_gem_path) + default = options.fetch(:default, false) with_gem_path_as(path) do gem_repo = options.fetch(:gem_repo, gem_repo1) gems.each do |g| gem_name = g.to_s if gem_name.start_with?("bundler") version = gem_name.match(/\Abundler-(?<version>.*)\z/)[:version] if gem_name != "bundler" - with_built_bundler(version) {|gem_path| install_gem(gem_path) } + with_built_bundler(version) {|gem_path| install_gem(gem_path, default) } elsif gem_name =~ %r{\A(?:[a-zA-Z]:)?/.*\.gem\z} - install_gem(gem_name) + install_gem(gem_name, default) else - install_gem("#{gem_repo}/gems/#{gem_name}.gem") + install_gem("#{gem_repo}/gems/#{gem_name}.gem", default) end end end end - def install_gem(path) + def install_gem(path, default = false) raise "OMG `#{path}` does not exist!" unless File.exist?(path) - gem_command "install --no-document --ignore-dependencies '#{path}'" + args = "--no-document --ignore-dependencies" + args += " --default --install-dir #{system_gem_path}" if default + + gem_command "install #{args} '#{path}'" end def with_built_bundler(version = nil) @@ -330,12 +334,7 @@ module Spec replace_version_file(version, dir: build_path) # rubocop:disable Style/HashSyntax - build_metadata = { - :built_at => loaded_gemspec.date.utc.strftime("%Y-%m-%d"), - :git_commit_sha => git_commit_sha, - } - - replace_build_metadata(build_metadata, dir: build_path) # rubocop:disable Style/HashSyntax + Spec::BuildMetadata.write_build_metadata(dir: build_path) # rubocop:disable Style/HashSyntax gem_command "build #{relative_gemspec}", :dir => build_path @@ -570,7 +569,7 @@ module Spec port end - private + private def git_root_dir? root.to_s == `git rev-parse --show-toplevel`.chomp diff --git a/spec/bundler/support/path.rb b/spec/bundler/support/path.rb index 042aae92fd..305ea0a876 100644 --- a/spec/bundler/support/path.rb +++ b/spec/bundler/support/path.rb @@ -34,7 +34,7 @@ module Spec end def dev_gemfile - @dev_gemfile ||= source_root.join("dev_gems.rb") + @dev_gemfile ||= git_root.join("dev_gems.rb") end def bindir @@ -208,18 +208,6 @@ module Spec File.open(version_file, "w") {|f| f << contents } 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? # avoid to warnings @ruby_core ||= nil @@ -231,11 +219,7 @@ module Spec end end - def git_commit_sha - ruby_core_tarball? ? "unknown" : sys_exec("git rev-parse --short HEAD", :dir => source_root).strip - end - - private + private def git_ls_files(glob) skip "Not running on a git context, since running tests from a tarball" if ruby_core_tarball? diff --git a/spec/bundler/support/rubygems_ext.rb b/spec/bundler/support/rubygems_ext.rb index d13567d7af..d743a76391 100644 --- a/spec/bundler/support/rubygems_ext.rb +++ b/spec/bundler/support/rubygems_ext.rb @@ -71,7 +71,7 @@ module Spec install_gems(test_gemfile, test_lockfile) end - private + private # Some rubygems versions include loaded specs when loading gemspec stubs # from the file system. In this situation, that makes bundler incorrectly diff --git a/spec/bundler/support/rubygems_version_manager.rb b/spec/bundler/support/rubygems_version_manager.rb index 66dcdc7ad3..ac02021cff 100644 --- a/spec/bundler/support/rubygems_version_manager.rb +++ b/spec/bundler/support/rubygems_version_manager.rb @@ -51,7 +51,7 @@ class RubygemsVersionManager end end -private + private def use_system? @source.nil? diff --git a/spec/bundler/update/gems/fund_spec.rb b/spec/bundler/update/gems/fund_spec.rb new file mode 100644 index 0000000000..6d7075b424 --- /dev/null +++ b/spec/bundler/update/gems/fund_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +RSpec.describe "bundle update" do + before do + gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem 'has_metadata' + gem 'has_funding', '< 2.0' + G + + bundle :install + end + + context "when listed gems are updated" do + before do + gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem 'has_metadata' + gem 'has_funding' + G + + bundle :update, :all => true + end + + it "displays fund message" do + expect(out).to include("2 installed gems you directly depend on are looking for funding.") + end + end +end |