diff options
Diffstat (limited to 'spec/install')
-rw-r--r-- | spec/install/deploy_spec.rb | 13 | ||||
-rw-r--r-- | spec/install/gemfile/eval_gemfile_spec.rb | 4 | ||||
-rw-r--r-- | spec/install/gemfile/gemspec_spec.rb | 24 | ||||
-rw-r--r-- | spec/install/gemfile/git_spec.rb | 83 | ||||
-rw-r--r-- | spec/install/gemfile/path_spec.rb | 59 | ||||
-rw-r--r-- | spec/install/gemfile/ruby_spec.rb | 4 | ||||
-rw-r--r-- | spec/install/gemfile/specific_platform_spec.rb | 6 | ||||
-rw-r--r-- | spec/install/gemfile_spec.rb | 8 | ||||
-rw-r--r-- | spec/install/gems/standalone_spec.rb | 132 | ||||
-rw-r--r-- | spec/install/global_cache_spec.rb | 42 | ||||
-rw-r--r-- | spec/install/path_spec.rb | 42 |
11 files changed, 168 insertions, 249 deletions
diff --git a/spec/install/deploy_spec.rb b/spec/install/deploy_spec.rb index ff32887c5e..5031bd9aa0 100644 --- a/spec/install/deploy_spec.rb +++ b/spec/install/deploy_spec.rb @@ -43,13 +43,12 @@ RSpec.describe "install with --deployment or --frozen" do it "still works if you are not in the app directory and specify --gemfile" do bundle! "install" - Dir.chdir tmp do - simulate_new_machine - bundle! :install, - forgotten_command_line_options(:gemfile => "#{tmp}/bundled_app/Gemfile", - :deployment => true, - :path => "vendor/bundle") - end + simulate_new_machine + bundle! :install, + forgotten_command_line_options(:gemfile => "#{tmp}/bundled_app/Gemfile", + :deployment => true, + :path => "vendor/bundle", + :dir => tmp) expect(the_bundle).to include_gems "rack 1.0" end diff --git a/spec/install/gemfile/eval_gemfile_spec.rb b/spec/install/gemfile/eval_gemfile_spec.rb index 7df94aaff5..69341250c3 100644 --- a/spec/install/gemfile/eval_gemfile_spec.rb +++ b/spec/install/gemfile/eval_gemfile_spec.rb @@ -28,8 +28,8 @@ RSpec.describe "bundle install with gemfile that uses eval_gemfile" do context "eval-ed Gemfile has relative-path gems" do before do - build_lib("a", :path => "gems/a") - create_file "nested/Gemfile-nested", <<-G + build_lib("a", :path => bundled_app("gems/a")) + create_file bundled_app("nested/Gemfile-nested"), <<-G gem "a", :path => "../gems/a" G diff --git a/spec/install/gemfile/gemspec_spec.rb b/spec/install/gemfile/gemspec_spec.rb index 2da53a5c13..bf1b84cf28 100644 --- a/spec/install/gemfile/gemspec_spec.rb +++ b/spec/install/gemfile/gemspec_spec.rb @@ -120,18 +120,16 @@ RSpec.describe "bundle install from an existing gemspec" do s.add_development_dependency "rake", "=12.3.2" end - Dir.chdir(tmp.join("foo")) do - bundle "install" - # This should really be able to rely on $stderr, but, it's not written - # right, so we can't. In fact, this is a bug negation test, and so it'll - # ghost pass in future, and will only catch a regression if the message - # doesn't change. Exit codes should be used correctly (they can be more - # than just 0 and 1). - output = bundle("install --deployment") - expect(output).not_to match(/You have added to the Gemfile/) - expect(output).not_to match(/You have deleted from the Gemfile/) - expect(output).not_to match(/install in deployment mode after changing/) - end + bundle "install", :dir => tmp.join("foo") + # This should really be able to rely on $stderr, but, it's not written + # right, so we can't. In fact, this is a bug negation test, and so it'll + # ghost pass in future, and will only catch a regression if the message + # doesn't change. Exit codes should be used correctly (they can be more + # than just 0 and 1). + output = bundle("install --deployment", :dir => tmp.join("foo")) + expect(output).not_to match(/You have added to the Gemfile/) + expect(output).not_to match(/You have deleted from the Gemfile/) + expect(output).not_to match(/install in deployment mode after changing/) end it "should match a lockfile without needing to re-resolve" do @@ -427,7 +425,7 @@ RSpec.describe "bundle install from an existing gemspec" do end end - build_lib "foo", :path => "." do |s| + build_lib "foo", :path => bundled_app do |s| if platform_specific_type == :runtime s.add_runtime_dependency dependency elsif platform_specific_type == :development diff --git a/spec/install/gemfile/git_spec.rb b/spec/install/gemfile/git_spec.rb index 249ed48eab..067de1777d 100644 --- a/spec/install/gemfile/git_spec.rb +++ b/spec/install/gemfile/git_spec.rb @@ -57,22 +57,18 @@ RSpec.describe "bundle install with git sources" do it "does not update the git source implicitly" do update_git "foo" - in_app_root2 do - install_gemfile bundled_app2("Gemfile"), <<-G - git "#{lib_path("foo-1.0")}" do - gem 'foo' - end - G - end + install_gemfile bundled_app2("Gemfile"), <<-G, :dir => bundled_app2 + git "#{lib_path("foo-1.0")}" do + gem 'foo' + end + G - in_app_root do - run <<-RUBY - require 'foo' - puts "fail" if defined?(FOO_PREV_REF) - RUBY + run <<-RUBY + require 'foo' + puts "fail" if defined?(FOO_PREV_REF) + RUBY - expect(out).to be_empty - end + expect(out).to be_empty end it "sets up git gem executables on the path" do @@ -130,22 +126,18 @@ RSpec.describe "bundle install with git sources" do it "still works after moving the application directory" do bundle "install --path vendor/bundle" - Dir.chdir root FileUtils.mv bundled_app, tmp("bundled_app.bck") - Dir.chdir tmp("bundled_app.bck") - expect(the_bundle).to include_gems "foo 1.0" + expect(the_bundle).to include_gems "foo 1.0", :dir => tmp("bundled_app.bck") end it "can still install after moving the application directory" do bundle "install --path vendor/bundle" - Dir.chdir root FileUtils.mv bundled_app, tmp("bundled_app.bck") update_git "foo", "1.1", :path => lib_path("foo-1.0") - Dir.chdir tmp("bundled_app.bck") gemfile tmp("bundled_app.bck/Gemfile"), <<-G source "#{file_uri_for(gem_repo1)}" git "#{lib_path("foo-1.0")}" do @@ -155,9 +147,9 @@ RSpec.describe "bundle install with git sources" do gem "rack", "1.0" G - bundle "update foo" + bundle "update foo", :dir => tmp("bundled_app.bck") - expect(the_bundle).to include_gems "foo 1.1", "rack 1.0" + expect(the_bundle).to include_gems "foo 1.1", "rack 1.0", :dir => tmp("bundled_app.bck") end end @@ -224,9 +216,7 @@ RSpec.describe "bundle install with git sources" do s.write("lib/foo.rb", "raise 'FAIL'") end - Dir.chdir(lib_path("foo-1.0")) do - `git update-ref -m "Bundler Spec!" refs/bundler/1 master~1` - end + sys_exec("git update-ref -m \"Bundler Spec!\" refs/bundler/1 master~1", :dir => lib_path("foo-1.0")) # want to ensure we don't fallback to HEAD update_git "foo", :path => lib_path("foo-1.0"), :branch => "rando" do |s| @@ -260,9 +250,7 @@ RSpec.describe "bundle install with git sources" do s.write("lib/foo.rb", "raise 'FAIL'") end - Dir.chdir(lib_path("foo-1.0")) do - `git update-ref -m "Bundler Spec!" refs/bundler/1 master~1` - end + sys_exec("git update-ref -m \"Bundler Spec!\" refs/bundler/1 master~1", :dir => lib_path("foo-1.0")) # want to ensure we don't fallback to HEAD update_git "foo", :path => lib_path("foo-1.0"), :branch => "rando" do |s| @@ -285,9 +273,7 @@ RSpec.describe "bundle install with git sources" do end it "does not download random non-head refs" do - Dir.chdir(lib_path("foo-1.0")) do - sys_exec!('git update-ref -m "Bundler Spec!" refs/bundler/1 master~1') - end + sys_exec("git update-ref -m \"Bundler Spec!\" refs/bundler/1 master~1", :dir => lib_path("foo-1.0")) bundle! "config set global_gem_cache true" @@ -300,9 +286,7 @@ RSpec.describe "bundle install with git sources" do # ensure we also git fetch after cloning bundle! :update, :all => true - Dir.chdir(Dir[home(".bundle/cache/git/foo-*")].first) do - sys_exec("git ls-remote .") - end + sys_exec("git ls-remote .", :dir => Dir[home(".bundle/cache/git/foo-*")].first) expect(out).not_to include("refs/bundler/1") end @@ -837,9 +821,7 @@ RSpec.describe "bundle install with git sources" do bundle "update", :all => true expect(the_bundle).to include_gems "forced 1.1" - Dir.chdir(lib_path("forced-1.0")) do - `git reset --hard HEAD^` - end + sys_exec("git reset --hard HEAD^", :dir => lib_path("forced-1.0")) bundle "update", :all => true expect(the_bundle).to include_gems "forced 1.0" @@ -850,10 +832,8 @@ RSpec.describe "bundle install with git sources" do build_git "has_submodule", "1.0" do |s| s.add_dependency "submodule" end - Dir.chdir(lib_path("has_submodule-1.0")) do - sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0" - `git commit -m "submodulator"` - end + 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 @@ -870,10 +850,8 @@ RSpec.describe "bundle install with git sources" do build_git "has_submodule", "1.0" do |s| s.add_dependency "submodule" end - Dir.chdir(lib_path("has_submodule-1.0")) do - sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0" - `git commit -m "submodulator"` - end + 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")}", :submodules => true do @@ -1172,16 +1150,15 @@ RSpec.describe "bundle install with git sources" do end 2.times do |i| - Dir.chdir(git_reader.path) do - File.open("ext/foo.c", "w") do |file| - file.write <<-C - #include "ruby.h" - VALUE foo() { return INT2FIX(#{i}); } - void Init_foo() { rb_define_global_function("foo", &foo, 0); } - C - end - `git commit -m "commit for iteration #{i}" ext/foo.c` + File.open(git_reader.path.join("ext/foo.c"), "w") do |file| + file.write <<-C + #include "ruby.h" + VALUE foo() { return INT2FIX(#{i}); } + void Init_foo() { rb_define_global_function("foo", &foo, 0); } + C end + sys_exec("git commit -m \"commit for iteration #{i}\" ext/foo.c", :dir => git_reader.path) + git_commit_sha = git_reader.ref_for("HEAD") install_gemfile <<-G diff --git a/spec/install/gemfile/path_spec.rb b/spec/install/gemfile/path_spec.rb index e1ca389dc4..a733c02512 100644 --- a/spec/install/gemfile/path_spec.rb +++ b/spec/install/gemfile/path_spec.rb @@ -37,7 +37,7 @@ RSpec.describe "bundle install with explicit source paths" do it "supports relative paths" do build_lib "foo" - relative_path = lib_path("foo-1.0").relative_path_from(Pathname.new(Dir.pwd)) + relative_path = lib_path("foo-1.0").relative_path_from(bundled_app) install_gemfile <<-G gem 'foo', :path => "#{relative_path}" @@ -79,10 +79,7 @@ RSpec.describe "bundle install with explicit source paths" do gem 'foo', :path => "./foo-1.0" G - bundled_app("subdir").mkpath - Dir.chdir(bundled_app("subdir")) do - expect(the_bundle).to include_gems("foo 1.0") - end + expect(the_bundle).to include_gems("foo 1.0", :dir => bundled_app("subdir").mkpath) end it "sorts paths consistently on install and update when they start with ./" do @@ -121,12 +118,10 @@ RSpec.describe "bundle install with explicit source paths" do #{Bundler::VERSION} L - Dir.chdir(lib_path("demo")) do - bundle :install - expect(lib_path("demo/Gemfile.lock")).to have_lockfile(lockfile) - bundle :update, :all => true - expect(lib_path("demo/Gemfile.lock")).to have_lockfile(lockfile) - end + bundle :install, :dir => lib_path("demo") + expect(lib_path("demo/Gemfile.lock")).to have_lockfile(lockfile) + bundle :update, :all => true, :dir => lib_path("demo") + expect(lib_path("demo/Gemfile.lock")).to have_lockfile(lockfile) end it "expands paths when comparing locked paths to Gemfile paths" do @@ -249,11 +244,9 @@ RSpec.describe "bundle install with explicit source paths" do File.open(lib_path("foo/Gemfile"), "w") {|f| f.puts gemfile } - Dir.chdir(lib_path("foo")) do - bundle "install" - expect(the_bundle).to include_gems "foo 1.0" - expect(the_bundle).to include_gems "rack 1.0" - end + bundle "install", :dir => lib_path("foo") + expect(the_bundle).to include_gems "foo 1.0", :dir => lib_path("foo") + expect(the_bundle).to include_gems "rack 1.0", :dir => lib_path("foo") end it "supports gemspec syntax with an alternative path" do @@ -275,19 +268,17 @@ RSpec.describe "bundle install with explicit source paths" do s.add_dependency "rack", ">= 1.0" end - Dir.chdir lib_path("foo") - - install_gemfile lib_path("foo/Gemfile"), <<-G + install_gemfile lib_path("foo/Gemfile"), <<-G, :dir => lib_path("foo") source "#{file_uri_for(gem_repo1)}" gemspec G build_gem "rack", "1.0.1", :to_system => true - bundle "install" + bundle "install", :dir => lib_path("foo") - expect(the_bundle).to include_gems "foo 1.0" - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "foo 1.0", :dir => lib_path("foo") + expect(the_bundle).to include_gems "rack 1.0", :dir => lib_path("foo") end it "doesn't automatically unlock dependencies when using the gemspec syntax and the gem has development dependencies" do @@ -296,19 +287,17 @@ RSpec.describe "bundle install with explicit source paths" do s.add_development_dependency "activesupport" end - Dir.chdir lib_path("foo") - - install_gemfile lib_path("foo/Gemfile"), <<-G + install_gemfile lib_path("foo/Gemfile"), <<-G, :dir => lib_path("foo") source "#{file_uri_for(gem_repo1)}" gemspec G build_gem "rack", "1.0.1", :to_system => true - bundle "install" + bundle "install", :dir => lib_path("foo") - expect(the_bundle).to include_gems "foo 1.0" - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "foo 1.0", :dir => lib_path("foo") + expect(the_bundle).to include_gems "rack 1.0", :dir => lib_path("foo") end it "raises if there are multiple gemspecs" do @@ -426,7 +415,7 @@ RSpec.describe "bundle install with explicit source paths" do remote: http://rubygems.org L - in_app_root { FileUtils.mkdir_p("vendor/bar") } + FileUtils.mkdir_p(bundled_app("vendor/bar")) install_gemfile <<-G gem "bar", "1.0.0", path: "vendor/bar", require: "bar/nyard" @@ -658,13 +647,11 @@ RSpec.describe "bundle install with explicit source paths" do G File.open(lib_path("private_lib/Gemfile"), "w") {|f| f.puts gemfile } - Dir.chdir(lib_path("private_lib")) do - bundle :install, :env => { "DEBUG" => "1" }, :artifice => "endpoint" - expect(out).to match(%r{^HTTP GET http://localgemserver\.test/api/v1/dependencies\?gems=rack$}) - expect(out).not_to match(/^HTTP GET.*private_lib/) - expect(the_bundle).to include_gems "private_lib 2.2" - expect(the_bundle).to include_gems "rack 1.0" - end + bundle :install, :env => { "DEBUG" => "1" }, :artifice => "endpoint", :dir => lib_path("private_lib") + expect(out).to match(%r{^HTTP GET http://localgemserver\.test/api/v1/dependencies\?gems=rack$}) + expect(out).not_to match(/^HTTP GET.*private_lib/) + expect(the_bundle).to include_gems "private_lib 2.2", :dir => lib_path("private_lib") + expect(the_bundle).to include_gems "rack 1.0", :dir => lib_path("private_lib") end end diff --git a/spec/install/gemfile/ruby_spec.rb b/spec/install/gemfile/ruby_spec.rb index d1e9fc7e05..d6ac4e3827 100644 --- a/spec/install/gemfile/ruby_spec.rb +++ b/spec/install/gemfile/ruby_spec.rb @@ -2,7 +2,7 @@ RSpec.describe "ruby requirement" do def locked_ruby_version - Bundler::RubyVersion.from_string(Bundler::LockfileParser.new(lockfile).ruby_version) + Bundler::RubyVersion.from_string(Bundler::LockfileParser.new(File.read(bundled_app_lock)).ruby_version) end # As discovered by https://github.com/bundler/bundler/issues/4147, there is @@ -51,6 +51,7 @@ RSpec.describe "ruby requirement" do gem "rack" G + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) expect(locked_ruby_version).to eq(Bundler::RubyVersion.system) simulate_ruby_version "5100" @@ -72,6 +73,7 @@ RSpec.describe "ruby requirement" do gem "rack" G + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) expect(locked_ruby_version).to eq(Bundler::RubyVersion.system) simulate_ruby_version "5100" diff --git a/spec/install/gemfile/specific_platform_spec.rb b/spec/install/gemfile/specific_platform_spec.rb index 24b602589f..a1cc6b3551 100644 --- a/spec/install/gemfile/specific_platform_spec.rb +++ b/spec/install/gemfile/specific_platform_spec.rb @@ -58,6 +58,7 @@ RSpec.describe "bundle install with specific_platform enabled" do it "locks to both the specific darwin platform and ruby" do install_gemfile!(google_protobuf) + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) expect(the_bundle.locked_gems.platforms).to eq([pl("ruby"), pl("x86_64-darwin-15")]) expect(the_bundle).to include_gem("google-protobuf 3.0.0.alpha.5.0.5.1 universal-darwin") expect(the_bundle.locked_gems.specs.map(&:full_name)).to eq(%w[ @@ -78,6 +79,7 @@ RSpec.describe "bundle install with specific_platform enabled" do source "#{file_uri_for(gem_repo2)}" gem "facter" G + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) expect(the_bundle.locked_gems.platforms).to eq([pl("ruby"), pl("x86_64-darwin-15")]) expect(the_bundle).to include_gems("facter 2.4.6 universal-darwin", "CFPropertyList 1.0") @@ -87,6 +89,10 @@ RSpec.describe "bundle install with specific_platform enabled" do end context "when adding a platform via lock --add_platform" do + before do + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) + end + it "adds the foreign platform" do install_gemfile!(google_protobuf) bundle! "lock --add-platform=#{x64_mingw}" diff --git a/spec/install/gemfile_spec.rb b/spec/install/gemfile_spec.rb index 76704b387d..e760f87ec1 100644 --- a/spec/install/gemfile_spec.rb +++ b/spec/install/gemfile_spec.rb @@ -44,12 +44,10 @@ RSpec.describe "bundle install" do end it "uses the gemfile while in a subdirectory" do bundled_app("subdir").mkpath - Dir.chdir(bundled_app("subdir")) do - bundle "install" - bundle "list" + bundle "install", :dir => bundled_app("subdir") + bundle "list", :dir => bundled_app("subdir") - expect(out).to include("rack (1.0.0)") - end + expect(out).to include("rack (1.0.0)") end end diff --git a/spec/install/gems/standalone_spec.rb b/spec/install/gems/standalone_spec.rb index 2745fe671c..c7c9d2a6a9 100644 --- a/spec/install/gems/standalone_spec.rb +++ b/spec/install/gems/standalone_spec.rb @@ -21,15 +21,12 @@ RSpec.shared_examples "bundle install --standalone" do testrb << "\nrequire \"#{k}\"" testrb << "\nputs #{k.upcase}" end - Dir.chdir(bundled_app) do - ruby testrb, :no_lib => true - end + ruby testrb, :no_lib => true expect(out).to eq(expected_gems.values.join("\n")) end it "works on a different system" do - Dir.chdir root FileUtils.mv(bundled_app, "#{bundled_app}2") testrb = String.new <<-RUBY @@ -41,9 +38,7 @@ RSpec.shared_examples "bundle install --standalone" do testrb << "\nrequire \"#{k}\"" testrb << "\nputs #{k.upcase}" end - in_app_root2 do - ruby testrb, :no_lib => true - end + ruby testrb, :no_lib => true, :dir => "#{bundled_app}2" expect(out).to eq(expected_gems.values.join("\n")) end @@ -55,7 +50,7 @@ RSpec.shared_examples "bundle install --standalone" do source "#{file_uri_for(gem_repo1)}" gem "rails" G - bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true) + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :dir => cwd) end let(:expected_gems) do @@ -70,7 +65,7 @@ RSpec.shared_examples "bundle install --standalone" do describe "with gems with native extension", :ruby_repo do before do - install_gemfile <<-G, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true) + install_gemfile <<-G, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :dir => cwd) source "#{file_uri_for(gem_repo1)}" gem "very_simple_binary" G @@ -103,7 +98,7 @@ RSpec.shared_examples "bundle install --standalone" do end G end - install_gemfile <<-G, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true) + install_gemfile <<-G, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :dir => cwd) gem "bar", :git => "#{lib_path("bar-1.0")}" G end @@ -123,7 +118,7 @@ RSpec.shared_examples "bundle install --standalone" do gem "rails" gem "devise", :git => "#{lib_path("devise-1.0")}" G - bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true) + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :dir => cwd) end let(:expected_gems) do @@ -150,7 +145,7 @@ RSpec.shared_examples "bundle install --standalone" do gem "rack-test" end G - bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true) + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :dir => cwd) end let(:expected_gems) do @@ -163,88 +158,63 @@ RSpec.shared_examples "bundle install --standalone" do include_examples "common functionality" it "allows creating a standalone file with limited groups" do - bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => "default") + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => "default", :dir => cwd) - Dir.chdir(bundled_app) do - load_error_ruby <<-RUBY, "spec", :no_lib => true - $:.unshift File.expand_path("bundle") - require "bundler/setup" + load_error_ruby <<-RUBY, "spec", :no_lib => true + $:.unshift File.expand_path("bundle") + require "bundler/setup" - require "actionpack" - puts ACTIONPACK - require "spec" - RUBY - end + require "actionpack" + puts ACTIONPACK + require "spec" + RUBY expect(out).to eq("2.3.2") expect(err).to eq("ZOMG LOAD ERROR") end 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) + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle"), :without => "test").merge(:standalone => true, :dir => cwd) - Dir.chdir(bundled_app) do - load_error_ruby <<-RUBY, "spec", :no_lib => true - $:.unshift File.expand_path("bundle") - require "bundler/setup" + load_error_ruby <<-RUBY, "spec", :no_lib => true + $:.unshift File.expand_path("bundle") + require "bundler/setup" - require "actionpack" - puts ACTIONPACK - require "spec" - RUBY - end + require "actionpack" + puts ACTIONPACK + require "spec" + RUBY expect(out).to eq("2.3.2") expect(err).to eq("ZOMG LOAD ERROR") end - it "allows --path to change the location of the standalone bundle", :bundler => "< 3" do - bundle! "install", forgotten_command_line_options(:path => "path/to/bundle").merge(:standalone => true) + 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) - Dir.chdir(bundled_app) do - ruby <<-RUBY, :no_lib => true - $:.unshift File.expand_path("path/to/bundle") - require "bundler/setup" + ruby <<-RUBY, :no_lib => true + $:.unshift File.expand_path("path/to/bundle") + require "bundler/setup" - require "actionpack" - puts ACTIONPACK - RUBY - end + require "actionpack" + puts ACTIONPACK + RUBY expect(out).to eq("2.3.2") end - it "allows --path to change the location of the standalone bundle", :bundler => "3" do - bundle! "install", forgotten_command_line_options(:path => "path/to/bundle").merge(:standalone => true) - path = File.expand_path("path/to/bundle") - - Dir.chdir(bundled_app) do - ruby <<-RUBY, :no_lib => true - $:.unshift File.expand_path(#{path.dump}) - require "bundler/setup" - - require "actionpack" - puts ACTIONPACK - RUBY - end + it "allows remembered --without to limit the groups used in a standalone" do + 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) - expect(out).to eq("2.3.2") - end + load_error_ruby <<-RUBY, "spec", :no_lib => true + $:.unshift File.expand_path("bundle") + require "bundler/setup" - it "allows remembered --without to limit the groups used in a standalone" do - bundle! :install, forgotten_command_line_options(:without => "test") - bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true) - - Dir.chdir(bundled_app) do - load_error_ruby <<-RUBY, "spec", :no_lib => true - $:.unshift File.expand_path("bundle") - require "bundler/setup" - - require "actionpack" - puts ACTIONPACK - require "spec" - RUBY - end + require "actionpack" + puts ACTIONPACK + require "spec" + RUBY expect(out).to eq("2.3.2") expect(err).to eq("ZOMG LOAD ERROR") @@ -262,7 +232,7 @@ RSpec.shared_examples "bundle install --standalone" do source "#{source_uri}" gem "rails" G - bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :artifice => "endpoint") + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :artifice => "endpoint", :dir => cwd) end let(:expected_gems) do @@ -282,7 +252,7 @@ RSpec.shared_examples "bundle install --standalone" do source "#{file_uri_for(gem_repo1)}" gem "rails" G - bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :binstubs => true) + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :binstubs => true, :dir => cwd) end let(:expected_gems) do @@ -297,19 +267,15 @@ RSpec.shared_examples "bundle install --standalone" do it "creates stubs that use the standalone load path" do skip "exec format error" if Gem.win_platform? - Dir.chdir(bundled_app) do - expect(`bin/rails -v`.chomp).to eql "2.3.2" - end + expect(sys_exec("bin/rails -v").chomp).to eql "2.3.2" end it "creates stubs that can be executed from anywhere" do skip "exec format error" if Gem.win_platform? require "tmpdir" - Dir.chdir(Dir.tmpdir) do - sys_exec!(%(#{bundled_app("bin/rails")} -v)) - expect(out).to eq("2.3.2") - end + sys_exec!(%(#{bundled_app("bin/rails")} -v), :dir => Dir.tmpdir) + expect(out).to eq("2.3.2") end it "creates stubs that can be symlinked" do @@ -332,13 +298,13 @@ RSpec.shared_examples "bundle install --standalone" do end RSpec.describe "bundle install --standalone" do + let(:cwd) { bundled_app } + include_examples("bundle install --standalone") end RSpec.describe "bundle install --standalone run in a subdirectory" do - before do - Dir.chdir(bundled_app("bob").tap(&:mkpath)) - end + let(:cwd) { bundled_app("bob").tap(&:mkpath) } include_examples("bundle install --standalone") end diff --git a/spec/install/global_cache_spec.rb b/spec/install/global_cache_spec.rb index 253079a1eb..15987bdf53 100644 --- a/spec/install/global_cache_spec.rb +++ b/spec/install/global_cache_spec.rb @@ -169,28 +169,26 @@ RSpec.describe "global gem caching" do expect(source_global_cache("rack-1.0.0.gem")).to exist expect(source_global_cache("activesupport-2.3.5.gem")).to exist - in_app_root2 do - create_file bundled_app2("gems.rb"), <<-G - source "#{source}" - gem "activesupport" - G - - # Neither gem is installed and both are in the global cache - expect(the_bundle).not_to include_gems "rack 1.0.0" - expect(the_bundle).not_to include_gems "activesupport 2.3.5" - expect(source_global_cache("rack-1.0.0.gem")).to exist - expect(source_global_cache("activesupport-2.3.5.gem")).to exist - - # Install using the global cache instead of by downloading the .gem - # from the server - bundle! :install, :artifice => "compact_index_no_gem" - - # activesupport is installed and both are in the global cache - expect(the_bundle).not_to include_gems "rack 1.0.0" - 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("activesupport-2.3.5.gem")).to exist - end + create_file bundled_app2("gems.rb"), <<-G + source "#{source}" + gem "activesupport" + G + + # Neither gem is installed and both are in the global cache + expect(the_bundle).not_to include_gems "rack 1.0.0", :dir => bundled_app2 + expect(the_bundle).not_to include_gems "activesupport 2.3.5", :dir => bundled_app2 + expect(source_global_cache("rack-1.0.0.gem")).to exist + expect(source_global_cache("activesupport-2.3.5.gem")).to exist + + # Install using the global cache instead of by downloading the .gem + # from the server + bundle! :install, :artifice => "compact_index_no_gem", :dir => bundled_app2 + + # activesupport is installed and both are in the global cache + expect(the_bundle).not_to include_gems "rack 1.0.0", :dir => bundled_app2 + expect(the_bundle).to include_gems "activesupport 2.3.5", :dir => bundled_app2 + expect(source_global_cache("rack-1.0.0.gem")).to exist + expect(source_global_cache("activesupport-2.3.5.gem")).to exist end end end diff --git a/spec/install/path_spec.rb b/spec/install/path_spec.rb index 89a441d0f4..bed28ed3e2 100644 --- a/spec/install/path_spec.rb +++ b/spec/install/path_spec.rb @@ -22,10 +22,8 @@ RSpec.describe "bundle install" do dir = bundled_app("bun++dle") dir.mkpath - Dir.chdir(dir) do - bundle! :install, forgotten_command_line_options(:path => dir.join("vendor/bundle")) - expect(out).to include("installed into `./vendor/bundle`") - end + bundle! :install, forgotten_command_line_options(:path => dir.join("vendor/bundle")).merge(:dir => dir) + expect(out).to include("installed into `./vendor/bundle`") dir.rmtree end @@ -54,30 +52,24 @@ RSpec.describe "bundle install" do before { bundle! "config set path_relative_to_cwd true" } it "installs the bundle relatively to current working directory", :bundler => "< 3" do - Dir.chdir(bundled_app.parent) do - bundle! "install --gemfile='#{bundled_app}/Gemfile' --path vendor/bundle" - expect(out).to include("installed into `./vendor/bundle`") - expect(bundled_app("../vendor/bundle")).to be_directory - end + bundle! "install --gemfile='#{bundled_app}/Gemfile' --path vendor/bundle", :dir => bundled_app.parent + expect(out).to include("installed into `./vendor/bundle`") + expect(bundled_app("../vendor/bundle")).to be_directory expect(the_bundle).to include_gems "rack 1.0.0" end it "installs the standalone bundle relative to the cwd" do - Dir.chdir(bundled_app.parent) do - bundle! :install, :gemfile => bundled_app_gemfile, :standalone => true - expect(out).to include("installed into `./bundled_app/bundle`") - expect(bundled_app("bundle")).to be_directory - expect(bundled_app("bundle/ruby")).to be_directory - end + bundle! :install, :gemfile => bundled_app_gemfile, :standalone => true, :dir => bundled_app.parent + expect(out).to include("installed into `./bundled_app/bundle`") + expect(bundled_app("bundle")).to be_directory + expect(bundled_app("bundle/ruby")).to be_directory bundle! "config unset path" - Dir.chdir(bundled_app("subdir").tap(&:mkpath)) do - bundle! :install, :gemfile => bundled_app_gemfile, :standalone => true - expect(out).to include("installed into `../bundle`") - expect(bundled_app("bundle")).to be_directory - expect(bundled_app("bundle/ruby")).to be_directory - end + bundle! :install, :gemfile => bundled_app_gemfile, :standalone => true, :dir => bundled_app("subdir").tap(&:mkpath) + expect(out).to include("installed into `../bundle`") + expect(bundled_app("bundle")).to be_directory + expect(bundled_app("bundle/ruby")).to be_directory end end end @@ -137,9 +129,7 @@ RSpec.describe "bundle install" do set_bundle_path(type, "vendor") FileUtils.mkdir_p bundled_app("lol") - Dir.chdir(bundled_app("lol")) do - bundle! :install - end + bundle! :install, :dir => bundled_app("lol") expect(bundled_app("vendor", Bundler.ruby_scope, "gems/rack-1.0.0")).to be_directory expect(the_bundle).to include_gems "rack 1.0.0" @@ -203,9 +193,7 @@ RSpec.describe "bundle install" do describe "to a file" do before do - in_app_root do - FileUtils.touch "bundle" - end + FileUtils.touch bundled_app("bundle") end it "reports the file exists" do |