diff options
| author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2023-02-01 12:05:19 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-01 12:05:19 +0900 |
| commit | f4e6e78410136100ef5f285136a66df8d6004a61 (patch) | |
| tree | ed1f754dbe1c4b37e3736265a99122e7a12c3b5b /spec | |
| parent | 40e0b1e123503805c16a2a9aafae0a5c302c20d1 (diff) | |
Merge RubyGems 3.4.6 and Bundler 2.4.6 (#7214)
Merge RubyGems-3.4.6 and Bundler-2.4.6
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/bundler/commands/binstubs_spec.rb | 21 | ||||
| -rw-r--r-- | spec/bundler/commands/exec_spec.rb | 15 | ||||
| -rw-r--r-- | spec/bundler/install/gemfile/specific_platform_spec.rb | 58 | ||||
| -rw-r--r-- | spec/bundler/runtime/inline_spec.rb | 107 | ||||
| -rw-r--r-- | spec/bundler/runtime/setup_spec.rb | 25 |
5 files changed, 221 insertions, 5 deletions
diff --git a/spec/bundler/commands/binstubs_spec.rb b/spec/bundler/commands/binstubs_spec.rb index 61a911621f..72f4cc8e55 100644 --- a/spec/bundler/commands/binstubs_spec.rb +++ b/spec/bundler/commands/binstubs_spec.rb @@ -369,6 +369,7 @@ RSpec.describe "bundle binstubs <gem>" do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" gem "rack" + gem "rails" G end @@ -396,6 +397,26 @@ RSpec.describe "bundle binstubs <gem>" do expect(bundled_app("bin/rackup.cmd")).to exist end end + + context "when the gem is bundler" do + it "warns without generating a standalone binstub" do + bundle "binstubs bundler --standalone" + expect(bundled_app("bin/bundle")).not_to exist + expect(bundled_app("bin/bundler")).not_to exist + expect(err).to include("Sorry, Bundler can only be run via RubyGems.") + end + end + + context "when specified --all option" do + it "generates standalone binstubs for all gems except bundler" do + bundle "binstubs --standalone --all" + expect(bundled_app("bin/rackup")).to exist + expect(bundled_app("bin/rails")).to exist + expect(bundled_app("bin/bundle")).not_to exist + expect(bundled_app("bin/bundler")).not_to exist + expect(err).not_to include("Sorry, Bundler can only be run via RubyGems.") + end + end end context "when the bin already exists" do diff --git a/spec/bundler/commands/exec_spec.rb b/spec/bundler/commands/exec_spec.rb index c6947afeae..5ca11dcba2 100644 --- a/spec/bundler/commands/exec_spec.rb +++ b/spec/bundler/commands/exec_spec.rb @@ -2,11 +2,10 @@ RSpec.describe "bundle exec" do let(:system_gems_to_install) { %w[rack-1.0.0 rack-0.9.1] } - before :each do - system_gems(system_gems_to_install, :path => default_bundle_path) - end it "works with --gemfile flag" do + system_gems(system_gems_to_install, :path => default_bundle_path) + create_file "CustomGemfile", <<-G source "#{file_uri_for(gem_repo1)}" gem "rack", "1.0.0" @@ -17,6 +16,8 @@ RSpec.describe "bundle exec" do end it "activates the correct gem" do + system_gems(system_gems_to_install, :path => default_bundle_path) + gemfile <<-G source "#{file_uri_for(gem_repo1)}" gem "rack", "0.9.1" @@ -27,6 +28,8 @@ RSpec.describe "bundle exec" do end it "works and prints no warnings when HOME is not writable" do + system_gems(system_gems_to_install, :path => default_bundle_path) + gemfile <<-G source "#{file_uri_for(gem_repo1)}" gem "rack", "0.9.1" @@ -209,8 +212,6 @@ RSpec.describe "bundle exec" do end context "with default gems" do - let(:system_gems_to_install) { [] } - let(:default_irb_version) { ruby "gem 'irb', '< 999999'; require 'irb'; puts IRB::VERSION", :raise_on_error => false } context "when not specified in Gemfile" do @@ -402,6 +403,8 @@ RSpec.describe "bundle exec" do end it "raises a helpful error when exec'ing to something outside of the bundle" do + system_gems(system_gems_to_install, :path => default_bundle_path) + bundle "config set clean false" # want to keep the rackup binstub install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" @@ -706,6 +709,8 @@ RSpec.describe "bundle exec" do RUBY before do + system_gems(system_gems_to_install, :path => default_bundle_path) + bundled_app(path).open("w") {|f| f << executable } bundled_app(path).chmod(0o755) diff --git a/spec/bundler/install/gemfile/specific_platform_spec.rb b/spec/bundler/install/gemfile/specific_platform_spec.rb index c886af0d89..2f82a9f9f3 100644 --- a/spec/bundler/install/gemfile/specific_platform_spec.rb +++ b/spec/bundler/install/gemfile/specific_platform_spec.rb @@ -821,6 +821,64 @@ RSpec.describe "bundle install with specific platforms" do bundle :install end + it "automatically fixes the lockfile if the specific platform is locked and we move to a newer ruby version for which a native package is not available" do + # + # Given an existing application using native gems (e.g., nokogiri) + # And a lockfile generated with a stable ruby version + # When want test the application against ruby-head and `bundle install` + # Then bundler should fall back to the generic ruby platform gem + # + simulate_platform "x86_64-linux" do + build_repo4 do + build_gem "nokogiri", "1.14.0" + build_gem "nokogiri", "1.14.0" do |s| + s.platform = "x86_64-linux" + s.required_ruby_version = "< #{Gem.ruby_version}" + end + end + + gemfile <<~G + source "#{file_uri_for(gem_repo4)}" + + gem "nokogiri", "1.14.0" + G + + lockfile <<~L + GEM + remote: #{file_uri_for(gem_repo4)}/ + specs: + nokogiri (1.14.0-x86_64-linux) + + PLATFORMS + x86_64-linux + + DEPENDENCIES + nokogiri (= 1.14.0) + + BUNDLED WITH + #{Bundler::VERSION} + L + + bundle :install + + expect(lockfile).to eq(<<~L) + GEM + remote: #{file_uri_for(gem_repo4)}/ + specs: + nokogiri (1.14.0) + + PLATFORMS + x86_64-linux + + DEPENDENCIES + nokogiri (= 1.14.0) + + BUNDLED WITH + #{Bundler::VERSION} + L + end + end + private def setup_multiplatform_gem diff --git a/spec/bundler/runtime/inline_spec.rb b/spec/bundler/runtime/inline_spec.rb index e42cc67ec8..9567d2a3c3 100644 --- a/spec/bundler/runtime/inline_spec.rb +++ b/spec/bundler/runtime/inline_spec.rb @@ -230,6 +230,113 @@ RSpec.describe "bundler/inline#gemfile" do expect(err).to be_empty end + it "doesn't reinstall already installed gems" do + system_gems "rack-1.0.0" + + script <<-RUBY + require '#{entrypoint}' + ui = Bundler::UI::Shell.new + ui.level = "confirm" + + gemfile(true, ui: ui) do + source "#{file_uri_for(gem_repo1)}" + gem "activesupport" + gem "rack" + end + RUBY + + expect(out).to include("Installing activesupport") + expect(out).not_to include("Installing rack") + expect(err).to be_empty + end + + it "installs gems in later gemfile calls" do + system_gems "rack-1.0.0" + + script <<-RUBY + require '#{entrypoint}' + ui = Bundler::UI::Shell.new + ui.level = "confirm" + gemfile(true, ui: ui) do + source "#{file_uri_for(gem_repo1)}" + gem "rack" + end + + gemfile(true, ui: ui) do + source "#{file_uri_for(gem_repo1)}" + gem "activesupport" + end + RUBY + + expect(out).to include("Installing activesupport") + expect(out).not_to include("Installing rack") + expect(err).to be_empty + end + + it "doesn't reinstall already installed gems in later gemfile calls" do + system_gems "rack-1.0.0" + + script <<-RUBY + require '#{entrypoint}' + ui = Bundler::UI::Shell.new + ui.level = "confirm" + gemfile(true, ui: ui) do + source "#{file_uri_for(gem_repo1)}" + gem "activesupport" + end + + gemfile(true, ui: ui) do + source "#{file_uri_for(gem_repo1)}" + gem "rack" + end + RUBY + + expect(out).to include("Installing activesupport") + expect(out).not_to include("Installing rack") + expect(err).to be_empty + end + + it "installs gems with native extensions in later gemfile calls" do + system_gems "rack-1.0.0" + + build_git "foo" do |s| + s.add_dependency "rake" + s.extensions << "Rakefile" + s.write "Rakefile", <<-RUBY + task :default do + path = File.expand_path("lib", __dir__) + FileUtils.mkdir_p(path) + File.open("\#{path}/foo.rb", "w") do |f| + f.puts "FOO = 'YES'" + end + end + RUBY + end + + script <<-RUBY + require '#{entrypoint}' + ui = Bundler::UI::Shell.new + ui.level = "confirm" + gemfile(true, ui: ui) do + source "#{file_uri_for(gem_repo1)}" + gem "rack" + end + + gemfile(true, ui: ui) do + source "#{file_uri_for(gem_repo1)}" + gem "foo", :git => "#{lib_path("foo-1.0")}" + end + + require 'foo' + puts FOO + puts $:.grep(/ext/) + RUBY + + expect(out).to include("YES") + expect(out).to include(Pathname.glob(default_bundle_path("bundler/gems/extensions/**/foo-1.0-*")).first.to_s) + expect(err).to be_empty + end + it "installs inline gems when a Gemfile.lock is present" do gemfile <<-G source "https://notaserver.com" diff --git a/spec/bundler/runtime/setup_spec.rb b/spec/bundler/runtime/setup_spec.rb index f5b86433dc..9bfcbdaed8 100644 --- a/spec/bundler/runtime/setup_spec.rb +++ b/spec/bundler/runtime/setup_spec.rb @@ -1519,4 +1519,29 @@ end expect(err).to be_empty end end + + it "does not undo the Kernel.require decorations", :rubygems => ">= 3.4.6" do + install_gemfile "source \"#{file_uri_for(gem_repo1)}\"" + script = bundled_app("bin/script") + create_file(script, <<~RUBY) + module Kernel + module_function + + alias_method :require_before_extra_monkeypatches, :require + + def require(path) + puts "requiring \#{path} used the monkeypatch" + + require_before_extra_monkeypatches(path) + end + end + + require "bundler/setup" + + require "foo" + RUBY + + sys_exec "#{Gem.ruby} #{script}", :raise_on_error => false + expect(out).to include("requiring foo used the monkeypatch") + end end |
