diff options
Diffstat (limited to 'spec/bundler/install/gems/standalone_spec.rb')
-rw-r--r-- | spec/bundler/install/gems/standalone_spec.rb | 173 |
1 files changed, 135 insertions, 38 deletions
diff --git a/spec/bundler/install/gems/standalone_spec.rb b/spec/bundler/install/gems/standalone_spec.rb index db16a1b0e1..46cab2dfeb 100644 --- a/spec/bundler/install/gems/standalone_spec.rb +++ b/spec/bundler/install/gems/standalone_spec.rb @@ -32,6 +32,21 @@ RSpec.shared_examples "bundle install --standalone" do expect(out).to eq(expected_gems.values.join("\n")) end + it "makes the gems available without bundler nor rubygems" do + testrb = String.new <<-RUBY + $:.unshift File.expand_path("bundle") + require "bundler/setup" + + RUBY + expected_gems.each do |k, _| + testrb << "\nrequire \"#{k}\"" + testrb << "\nputs #{k.upcase}" + end + sys_exec %(#{Gem.ruby} --disable-gems -w -e #{testrb.shellescape}) + + expect(out).to eq(expected_gems.values.join("\n")) + end + it "makes the gems available without bundler via Kernel.require" do testrb = String.new <<-RUBY $:.unshift File.expand_path("bundle") @@ -82,7 +97,23 @@ RSpec.shared_examples "bundle install --standalone" do testrb << "\nrequire \"#{k}\"" testrb << "\nputs #{k.upcase}" end - ruby testrb, :dir => "#{bundled_app}2" + ruby testrb, dir: "#{bundled_app}2" + + expect(out).to eq(expected_gems.values.join("\n")) + end + + it "skips activating gems" do + testrb = String.new <<-RUBY + $:.unshift File.expand_path("bundle") + require "bundler/setup" + + gem "do_not_activate_me" + RUBY + expected_gems.each do |k, _| + testrb << "\nrequire \"#{k}\"" + testrb << "\nputs #{k.upcase}" + end + sys_exec %(#{Gem.ruby} -w -e #{testrb.shellescape}) expect(out).to eq(expected_gems.values.join("\n")) end @@ -95,7 +126,7 @@ RSpec.shared_examples "bundle install --standalone" do gem "rails" G bundle "config set --local path #{bundled_app("bundle")}" - bundle :install, :standalone => true, :dir => cwd + bundle :install, standalone: true, dir: cwd end let(:expected_gems) do @@ -110,20 +141,18 @@ RSpec.shared_examples "bundle install --standalone" do describe "with default gems and a lockfile", :ruby_repo do before do - 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 - skip "does not work on old rubies because the realworld gems that need to be installed don't support them" if RUBY_VERSION < "2.7.0" + realworld_system_gems "tsort --version 0.1.0" - realworld_system_gems "fiddle --version 1.0.6", "tsort --version 0.1.0" + necessary_system_gems = ["optparse --version 0.1.1", "psych --version 3.3.2", "logger --version 1.4.3", "etc --version 1.2.0", "stringio --version 3.1.0"] + necessary_system_gems += ["shellwords --version 0.1.0", "base64 --version 0.1.0", "resolv --version 0.2.1"] if Gem.rubygems_version < Gem::Version.new("3.3.a") + necessary_system_gems += ["yaml --version 0.1.1"] if Gem.rubygems_version < Gem::Version.new("3.4.a") + realworld_system_gems(*necessary_system_gems, path: scoped_gem_path(bundled_app("bundle"))) - necessary_system_gems = ["optparse --version 0.1.1", "psych --version 3.3.2", "yaml --version 0.1.1", "logger --version 1.4.3", "etc --version 1.2.0", "stringio --version 3.0.0"] - necessary_system_gems += ["shellwords --version 0.1.0", "base64 --version 0.1.0", "resolv --version 0.2.1"] if Gem.rubygems_version < Gem::Version.new("3.3.3.a") - realworld_system_gems(*necessary_system_gems, :path => scoped_gem_path(bundled_app("bundle"))) - - build_gem "foo", "1.0.0", :to_system => true, :default => true do |s| + build_gem "foo", "1.0.0", to_system: true, default: true do |s| s.add_dependency "bar" end - build_gem "bar", "1.0.0", :to_system => true, :default => true + build_gem "bar", "1.0.0", to_system: true, default: true build_repo4 do build_gem "foo", "1.0.0" do |s| @@ -138,18 +167,25 @@ RSpec.shared_examples "bundle install --standalone" do gem "foo" G - bundle "lock", :dir => cwd, :artifice => "compact_index" + bundle "lock", dir: cwd, artifice: "compact_index" end - it "works" do + it "works and points to the vendored copies, not to the default copies", :realworld do bundle "config set --local path #{bundled_app("bundle")}" - bundle :install, :standalone => true, :dir => cwd, :artifice => "compact_index", :env => { "BUNDLER_GEM_DEFAULT_DIR" => system_gem_path.to_s } + bundle :install, standalone: true, dir: cwd, artifice: "compact_index", env: { "BUNDLER_GEM_DEFAULT_DIR" => system_gem_path.to_s } + + load_path_lines = bundled_app("bundle/bundler/setup.rb").read.split("\n").select {|line| line.start_with?("$:.unshift") } + + expect(load_path_lines).to eq [ + '$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/bar-1.0.0/lib")', + '$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/foo-1.0.0/lib")', + ] end end - describe "with Gemfiles using path sources and resulting bundle moved to a folder hierarchy with different nesting" do + describe "with Gemfiles using absolute path sources and resulting bundle moved to a folder hierarchy with different nesting" do before do - build_lib "minitest", "1.0.0", :path => lib_path("minitest") + build_lib "minitest", "1.0.0", path: lib_path("minitest") Dir.mkdir bundled_app("app") @@ -158,14 +194,14 @@ RSpec.shared_examples "bundle install --standalone" do gem "minitest", :path => "#{lib_path("minitest")}" G - bundle "install", :standalone => true, :dir => bundled_app("app") + bundle "install", standalone: true, dir: bundled_app("app") Dir.mkdir tmp("one_more_level") FileUtils.mv bundled_app, tmp("one_more_level") end it "also works" do - ruby <<-RUBY, :dir => tmp("one_more_level/bundled_app/app") + ruby <<-RUBY, dir: tmp("one_more_level/bundled_app/app") require "./bundle/bundler/setup" require "minitest" @@ -177,10 +213,39 @@ RSpec.shared_examples "bundle install --standalone" do end end - describe "with gems with native extension", :ruby_repo do + describe "with Gemfiles using relative path sources and app moved to a different root" do + before do + FileUtils.mkdir_p bundled_app("app/vendor") + + build_lib "minitest", "1.0.0", path: bundled_app("app/vendor/minitest") + + gemfile bundled_app("app/Gemfile"), <<-G + source "#{file_uri_for(gem_repo1)}" + gem "minitest", :path => "vendor/minitest" + G + + bundle "install", standalone: true, dir: bundled_app("app") + + FileUtils.mv(bundled_app("app"), bundled_app2("app")) + end + + it "also works" do + ruby <<-RUBY, dir: bundled_app2("app") + require "./bundle/bundler/setup" + + require "minitest" + puts MINITEST + RUBY + + expect(out).to eq("1.0.0") + expect(err).to be_empty + end + end + + describe "with gems with native extension" do before do bundle "config set --local path #{bundled_app("bundle")}" - install_gemfile <<-G, :standalone => true, :dir => cwd + install_gemfile <<-G, standalone: true, dir: cwd source "#{file_uri_for(gem_repo1)}" gem "very_simple_binary" G @@ -188,18 +253,22 @@ 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 File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{RbConfig::CONFIG["ruby_version"]}/extensions/' - expect(extension_line).to end_with '/very_simple_binary-1.0")' + script_content = File.read(expected_path) + expect(script_content).to include("def self.ruby_api_version") + expect(script_content).to include("def self.extension_api_version") + extension_line = script_content.each_line.find {|line| line.include? "/extensions/" }.strip + platform = Gem::Platform.local + expect(extension_line).to start_with '$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/extensions/' + expect(extension_line).to end_with platform.to_s + '/#{Gem.extension_api_version}/very_simple_binary-1.0")' end end describe "with gem that has an invalid gemspec" do before do - build_git "bar", :gemspec => false do |s| + build_git "bar", gemspec: false do |s| s.write "lib/bar/version.rb", %(BAR_VERSION = '1.0') s.write "bar.gemspec", <<-G - lib = File.expand_path('../lib/', __FILE__) + lib = File.expand_path('lib/', __dir__) $:.unshift lib unless $:.include?(lib) require 'bar/version' @@ -214,7 +283,7 @@ RSpec.shared_examples "bundle install --standalone" do G end bundle "config set --local path #{bundled_app("bundle")}" - install_gemfile <<-G, :standalone => true, :dir => cwd, :raise_on_error => false + install_gemfile <<-G, standalone: true, dir: cwd, raise_on_error: false source "#{file_uri_for(gem_repo1)}" gem "bar", :git => "#{lib_path("bar-1.0")}" G @@ -236,7 +305,7 @@ RSpec.shared_examples "bundle install --standalone" do gem "devise", :git => "#{lib_path("devise-1.0")}" G bundle "config set --local path #{bundled_app("bundle")}" - bundle :install, :standalone => true, :dir => cwd + bundle :install, standalone: true, dir: cwd end let(:expected_gems) do @@ -264,7 +333,7 @@ RSpec.shared_examples "bundle install --standalone" do end G bundle "config set --local path #{bundled_app("bundle")}" - bundle :install, :standalone => true, :dir => cwd + bundle :install, standalone: true, dir: cwd end let(:expected_gems) do @@ -278,7 +347,7 @@ RSpec.shared_examples "bundle install --standalone" do it "allows creating a standalone file with limited groups" do bundle "config set --local path #{bundled_app("bundle")}" - bundle :install, :standalone => "default", :dir => cwd + bundle :install, standalone: "default", dir: cwd load_error_ruby <<-RUBY, "spec" $:.unshift File.expand_path("bundle") @@ -296,7 +365,7 @@ RSpec.shared_examples "bundle install --standalone" do it "allows `without` configuration to limit the groups used in a standalone" do bundle "config set --local path #{bundled_app("bundle")}" bundle "config set --local without test" - bundle :install, :standalone => true, :dir => cwd + bundle :install, standalone: true, dir: cwd load_error_ruby <<-RUBY, "spec" $:.unshift File.expand_path("bundle") @@ -313,7 +382,7 @@ RSpec.shared_examples "bundle install --standalone" do it "allows `path` configuration to change the location of the standalone bundle" do bundle "config set --local path path/to/bundle" - bundle "install", :standalone => true, :dir => cwd + bundle "install", standalone: true, dir: cwd ruby <<-RUBY $:.unshift File.expand_path("path/to/bundle") @@ -328,9 +397,9 @@ RSpec.shared_examples "bundle install --standalone" do it "allows `without` to limit the groups used in a standalone" do bundle "config set --local without test" - bundle :install, :dir => cwd + bundle :install, dir: cwd bundle "config set --local path #{bundled_app("bundle")}" - bundle :install, :standalone => true, :dir => cwd + bundle :install, standalone: true, dir: cwd load_error_ruby <<-RUBY, "spec" $:.unshift File.expand_path("bundle") @@ -356,7 +425,7 @@ RSpec.shared_examples "bundle install --standalone" do gem "rails" G bundle "config set --local path #{bundled_app("bundle")}" - bundle :install, :standalone => true, :artifice => "endpoint", :dir => cwd + bundle :install, standalone: true, artifice: "endpoint", dir: cwd end let(:expected_gems) do @@ -370,14 +439,14 @@ RSpec.shared_examples "bundle install --standalone" do end end - describe "with --binstubs", :bundler => "< 3" do + describe "with --binstubs", bundler: "< 3" do before do gemfile <<-G source "#{file_uri_for(gem_repo1)}" gem "rails" G bundle "config set --local path #{bundled_app("bundle")}" - bundle :install, :standalone => true, :binstubs => true, :dir => cwd + bundle :install, standalone: true, binstubs: true, dir: cwd end let(:expected_gems) do @@ -395,7 +464,7 @@ RSpec.shared_examples "bundle install --standalone" do it "creates stubs that can be executed from anywhere" do require "tmpdir" - sys_exec(%(#{bundled_app("bin/rails")} -v), :dir => Dir.tmpdir) + sys_exec(%(#{bundled_app("bin/rails")} -v), dir: Dir.tmpdir) expect(out).to eq("2.3.2") end @@ -413,7 +482,7 @@ RSpec.shared_examples "bundle install --standalone" do it "creates stubs with the correct load path" do extension_line = File.read(bundled_app("bin/rails")).each_line.find {|line| line.include? "$:.unshift" }.strip - expect(extension_line).to eq %($:.unshift File.expand_path "../../bundle", path.realpath) + expect(extension_line).to eq %($:.unshift File.expand_path "../bundle", __dir__) end end end @@ -429,3 +498,31 @@ RSpec.describe "bundle install --standalone run in a subdirectory" do include_examples("bundle install --standalone") end + +RSpec.describe "bundle install --standalone --local" do + before do + gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack" + G + + system_gems "rack-1.0.0", path: default_bundle_path + end + + it "generates script pointing to system gems" do + bundle "install --standalone --local --verbose" + + expect(out).to include("Using rack 1.0.0") + + load_error_ruby <<-RUBY, "spec" + require "./bundler/setup" + + require "rack" + puts RACK + require "spec" + RUBY + + expect(out).to eq("1.0.0") + expect(err).to eq("ZOMG LOAD ERROR") + end +end |