summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2020-01-10 09:56:42 +0100
committerDavid Rodríguez <deivid.rodriguez@riseup.net>2020-01-12 20:46:33 +0100
commit7dc38a75680f991bf32320cca850c32d1dcd90ca (patch)
treee532f1f4eb42a0b9f438ef40380a1ab9ae810975
parent55630c23f4e0683e820116af917888cf23569020 (diff)
downloadbundler-tests/less_flakyness.tar.gz
Remove global directory switching from specstests/less_flakyness
`Dir.chdir` is not thread safe, so it makes our parallel specs flaky. Instead, use the following alternatives: * Use `:chdir` parameter to `Open3` methods for specs that shell out. * Stub `find_gemfile` or other relevant helpers for unit tests.
-rw-r--r--spec/bundler/bundler_spec.rb2
-rw-r--r--spec/bundler/definition_spec.rb4
-rw-r--r--spec/bundler/dsl_spec.rb6
-rw-r--r--spec/bundler/env_spec.rb16
-rw-r--r--spec/bundler/gem_helper_spec.rb38
-rw-r--r--spec/bundler/plugin/index_spec.rb11
-rw-r--r--spec/bundler/plugin_spec.rb7
-rw-r--r--spec/bundler/settings_spec.rb2
-rw-r--r--spec/bundler/shared_helpers_spec.rb39
-rw-r--r--spec/cache/git_spec.rb6
-rw-r--r--spec/commands/binstubs_spec.rb4
-rw-r--r--spec/commands/check_spec.rb7
-rw-r--r--spec/commands/config_spec.rb11
-rw-r--r--spec/commands/doctor_spec.rb2
-rw-r--r--spec/commands/exec_spec.rb36
-rw-r--r--spec/commands/info_spec.rb2
-rw-r--r--spec/commands/init_spec.rb12
-rw-r--r--spec/commands/install_spec.rb9
-rw-r--r--spec/commands/lock_spec.rb6
-rw-r--r--spec/commands/newgem_spec.rb98
-rw-r--r--spec/commands/pristine_spec.rb2
-rw-r--r--spec/commands/show_spec.rb11
-rw-r--r--spec/commands/update_spec.rb1
-rw-r--r--spec/install/deploy_spec.rb13
-rw-r--r--spec/install/gemfile/eval_gemfile_spec.rb4
-rw-r--r--spec/install/gemfile/gemspec_spec.rb24
-rw-r--r--spec/install/gemfile/git_spec.rb83
-rw-r--r--spec/install/gemfile/path_spec.rb59
-rw-r--r--spec/install/gemfile/ruby_spec.rb4
-rw-r--r--spec/install/gemfile/specific_platform_spec.rb6
-rw-r--r--spec/install/gemfile_spec.rb8
-rw-r--r--spec/install/gems/standalone_spec.rb132
-rw-r--r--spec/install/global_cache_spec.rb42
-rw-r--r--spec/install/path_spec.rb42
-rw-r--r--spec/plugins/install_spec.rb14
-rw-r--r--spec/plugins/source/example_spec.rb11
-rw-r--r--spec/plugins/source_spec.rb3
-rw-r--r--spec/quality_es_spec.rb20
-rw-r--r--spec/quality_spec.rb130
-rw-r--r--spec/runtime/executable_spec.rb10
-rw-r--r--spec/runtime/gem_tasks_spec.rb5
-rw-r--r--spec/runtime/inline_spec.rb32
-rw-r--r--spec/runtime/load_spec.rb4
-rw-r--r--spec/runtime/platform_spec.rb2
-rw-r--r--spec/runtime/setup_spec.rb21
-rw-r--r--spec/spec_helper.rb5
-rw-r--r--spec/support/builders.rb76
-rw-r--r--spec/support/helpers.rb28
-rw-r--r--spec/support/path.rb12
-rw-r--r--spec/support/rubygems_version_manager.rb10
-rw-r--r--spec/update/gemfile_spec.rb8
-rw-r--r--spec/update/git_spec.rb18
52 files changed, 511 insertions, 647 deletions
diff --git a/spec/bundler/bundler_spec.rb b/spec/bundler/bundler_spec.rb
index 27477465bb..7237f644e2 100644
--- a/spec/bundler/bundler_spec.rb
+++ b/spec/bundler/bundler_spec.rb
@@ -210,6 +210,8 @@ EOF
gem "rack"
G
+ allow(Bundler).to receive(:root).and_return(bundled_app)
+
Bundler.mkdir_p(bundled_app.join("foo", "bar"))
expect(bundled_app.join("foo", "bar")).to exist
end
diff --git a/spec/bundler/definition_spec.rb b/spec/bundler/definition_spec.rb
index ad6d4e433e..d0ebb37933 100644
--- a/spec/bundler/definition_spec.rb
+++ b/spec/bundler/definition_spec.rb
@@ -210,6 +210,8 @@ RSpec.describe Bundler::Definition do
source "#{file_uri_for(gem_repo1)}"
gem "foo"
G
+
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
end
it "should get a locked specs list when updating all" do
@@ -267,6 +269,8 @@ RSpec.describe Bundler::Definition do
BUNDLED WITH
1.13.0
L
+
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
end
it "should not eagerly unlock shared dependency with bundle install conservative updating behavior" do
diff --git a/spec/bundler/dsl_spec.rb b/spec/bundler/dsl_spec.rb
index 56a5bfdb48..319472d4b0 100644
--- a/spec/bundler/dsl_spec.rb
+++ b/spec/bundler/dsl_spec.rb
@@ -72,7 +72,7 @@ RSpec.describe Bundler::Dsl do
describe "#method_missing" do
it "raises an error for unknown DSL methods" do
- expect(Bundler).to receive(:read_file).with(bundled_app("Gemfile").to_s).
+ expect(Bundler).to receive(:read_file).with(root.join("Gemfile").to_s).
and_return("unknown")
error_msg = "There was an error parsing `Gemfile`: Undefined local variable or method `unknown' for Gemfile. Bundler cannot continue."
@@ -83,13 +83,13 @@ RSpec.describe Bundler::Dsl do
describe "#eval_gemfile" do
it "handles syntax errors with a useful message" do
- expect(Bundler).to receive(:read_file).with(bundled_app("Gemfile").to_s).and_return("}")
+ expect(Bundler).to receive(:read_file).with(root.join("Gemfile").to_s).and_return("}")
expect { subject.eval_gemfile("Gemfile") }.
to raise_error(Bundler::GemfileError, /There was an error parsing `Gemfile`: (syntax error, unexpected tSTRING_DEND|(compile error - )?syntax error, unexpected '\}'). Bundler cannot continue./)
end
it "distinguishes syntax errors from evaluation errors" do
- expect(Bundler).to receive(:read_file).with(bundled_app("Gemfile").to_s).and_return(
+ expect(Bundler).to receive(:read_file).with(root.join("Gemfile").to_s).and_return(
"ruby '2.1.5', :engine => 'ruby', :engine_version => '1.2.4'"
)
expect { subject.eval_gemfile("Gemfile") }.
diff --git a/spec/bundler/env_spec.rb b/spec/bundler/env_spec.rb
index aefedebf13..8ff5ddada6 100644
--- a/spec/bundler/env_spec.rb
+++ b/spec/bundler/env_spec.rb
@@ -86,6 +86,8 @@ RSpec.describe Bundler::Env do
BUNDLED WITH
1.10.0
L
+
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
end
let(:output) { described_class.report(:print_gemfile => true) }
@@ -125,6 +127,8 @@ RSpec.describe Bundler::Env do
File.open(bundled_app.join("foo.gemspec"), "wb") do |f|
f.write(gemspec)
end
+
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
end
it "prints the gemspec" do
@@ -137,13 +141,15 @@ RSpec.describe Bundler::Env do
context "when eval_gemfile is used" do
it "prints all gemfiles" do
- create_file "other/Gemfile-other", "gem 'rack'"
- create_file "other/Gemfile", "eval_gemfile 'Gemfile-other'"
- create_file "Gemfile-alt", <<-G
+ create_file bundled_app("other/Gemfile-other"), "gem 'rack'"
+ create_file bundled_app("other/Gemfile"), "eval_gemfile 'Gemfile-other'"
+ create_file bundled_app("Gemfile-alt"), <<-G
source "#{file_uri_for(gem_repo1)}"
eval_gemfile "other/Gemfile"
G
- gemfile "eval_gemfile #{File.expand_path("Gemfile-alt").dump}"
+ gemfile "eval_gemfile #{bundled_app("Gemfile-alt").to_s.dump}"
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
+ allow(Bundler::SharedHelpers).to receive(:pwd).and_return(bundled_app)
output = described_class.report(:print_gemspecs => true)
expect(output).to include(strip_whitespace(<<-ENV))
@@ -152,7 +158,7 @@ RSpec.describe Bundler::Env do
### Gemfile
```ruby
- eval_gemfile #{File.expand_path("Gemfile-alt").dump}
+ eval_gemfile #{bundled_app("Gemfile-alt").to_s.dump}
```
### Gemfile-alt
diff --git a/spec/bundler/gem_helper_spec.rb b/spec/bundler/gem_helper_spec.rb
index b27c96b9a5..6af78e00be 100644
--- a/spec/bundler/gem_helper_spec.rb
+++ b/spec/bundler/gem_helper_spec.rb
@@ -178,13 +178,11 @@ RSpec.describe Bundler::GemHelper do
end
before do
- Dir.chdir(app_path) do
- `git init`
- `git config user.email "you@example.com"`
- `git config user.name "name"`
- `git config commit.gpgsign false`
- `git config push.default simple`
- end
+ sys_exec("git init", :dir => app_path)
+ sys_exec("git config user.email \"you@example.com\"", :dir => app_path)
+ sys_exec("git config user.name \"name\"", :dir => app_path)
+ sys_exec("git config commit.gpgsign false", :dir => app_path)
+ sys_exec("git config push.default simple", :dir => app_path)
# silence messages
allow(Bundler.ui).to receive(:confirm)
@@ -198,13 +196,13 @@ RSpec.describe Bundler::GemHelper do
end
it "when there are uncommitted files" do
- Dir.chdir(app_path) { `git add .` }
+ sys_exec("git add .", :dir => app_path)
expect { Rake.application["release"].invoke }.
to raise_error("There are files that need to be committed first.")
end
it "when there is no git remote" do
- Dir.chdir(app_path) { `git commit -a -m "initial commit"` }
+ sys_exec("git commit -a -m \"initial commit\"", :dir => app_path)
expect { Rake.application["release"].invoke }.to raise_error(RuntimeError)
end
end
@@ -213,10 +211,8 @@ RSpec.describe Bundler::GemHelper do
let(:repo) { build_git("foo", :bare => true) }
before do
- Dir.chdir(app_path) do
- sys_exec("git remote add origin #{file_uri_for(repo.path)}")
- sys_exec('git commit -a -m "initial commit"')
- end
+ sys_exec("git remote add origin #{file_uri_for(repo.path)}", :dir => app_path)
+ sys_exec('git commit -a -m "initial commit"', :dir => app_path)
end
context "on releasing" do
@@ -225,7 +221,7 @@ RSpec.describe Bundler::GemHelper do
mock_confirm_message "Tagged v#{app_version}."
mock_confirm_message "Pushed git commits and tags."
- Dir.chdir(app_path) { sys_exec("git push -u origin master") }
+ sys_exec("git push -u origin master", :dir => app_path)
end
it "calls rubygem_push with proper arguments" do
@@ -246,9 +242,7 @@ RSpec.describe Bundler::GemHelper do
mock_confirm_message "Tag v#{app_version} has already been created."
expect(subject).to receive(:rubygem_push).with(app_gem_path.to_s)
- Dir.chdir(app_path) do
- `git tag -a -m \"Version #{app_version}\" v#{app_version}`
- end
+ sys_exec("git tag -a -m \"Version #{app_version}\" v#{app_version}", :dir => app_path)
Rake.application["release"].invoke
end
@@ -269,12 +263,10 @@ RSpec.describe Bundler::GemHelper do
end
before do
- Dir.chdir(app_path) do
- `git init`
- `git config user.email "you@example.com"`
- `git config user.name "name"`
- `git config push.default simple`
- end
+ sys_exec("git init", :dir => app_path)
+ sys_exec("git config user.email \"you@example.com\"", :dir => app_path)
+ sys_exec("git config user.name \"name\"", :dir => app_path)
+ sys_exec("git config push.gpgsign simple", :dir => app_path)
# silence messages
allow(Bundler.ui).to receive(:confirm)
diff --git a/spec/bundler/plugin/index_spec.rb b/spec/bundler/plugin/index_spec.rb
index e18e960fb8..925dc558ac 100644
--- a/spec/bundler/plugin/index_spec.rb
+++ b/spec/bundler/plugin/index_spec.rb
@@ -4,6 +4,7 @@ RSpec.describe Bundler::Plugin::Index do
Index = Bundler::Plugin::Index
before do
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
gemfile ""
path = lib_path(plugin_name)
index.register_plugin("new-plugin", path.to_s, [path.join("lib").to_s], commands, sources, hooks)
@@ -117,11 +118,11 @@ RSpec.describe Bundler::Plugin::Index do
describe "global index" do
before do
- Dir.chdir(tmp) do
- Bundler::Plugin.reset!
- path = lib_path("gplugin")
- index.register_plugin("gplugin", path.to_s, [path.join("lib").to_s], [], ["glb_source"], [])
- end
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(nil)
+
+ Bundler::Plugin.reset!
+ path = lib_path("gplugin")
+ index.register_plugin("gplugin", path.to_s, [path.join("lib").to_s], [], ["glb_source"], [])
end
it "skips sources" do
diff --git a/spec/bundler/plugin_spec.rb b/spec/bundler/plugin_spec.rb
index cb6012da45..8c95723bcc 100644
--- a/spec/bundler/plugin_spec.rb
+++ b/spec/bundler/plugin_spec.rb
@@ -237,7 +237,7 @@ RSpec.describe Bundler::Plugin do
describe "#root" do
context "in app dir" do
before do
- gemfile ""
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
end
it "returns plugin dir in app .bundle path" do
@@ -246,8 +246,11 @@ RSpec.describe Bundler::Plugin do
end
context "outside app dir" do
+ before do
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(nil)
+ end
+
it "returns plugin dir in global bundle path" do
- Dir.chdir tmp
expect(subject.root).to eq(home.join(".bundle/plugin"))
end
end
diff --git a/spec/bundler/settings_spec.rb b/spec/bundler/settings_spec.rb
index b83d768477..116a038445 100644
--- a/spec/bundler/settings_spec.rb
+++ b/spec/bundler/settings_spec.rb
@@ -130,6 +130,8 @@ that would suck --ehhh=oh geez it looks like i might have broken bundler somehow
describe "#temporary" do
it "reset after used" do
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
+
Bundler.settings.set_command_option :no_install, true
Bundler.settings.temporary(:no_install => false) do
diff --git a/spec/bundler/shared_helpers_spec.rb b/spec/bundler/shared_helpers_spec.rb
index 5c91cb7bd1..4b4d5f33f6 100644
--- a/spec/bundler/shared_helpers_spec.rb
+++ b/spec/bundler/shared_helpers_spec.rb
@@ -4,10 +4,13 @@ RSpec.describe Bundler::SharedHelpers do
let(:ext_lock_double) { double(:ext_lock) }
before do
+ pwd_stub
allow(Bundler.rubygems).to receive(:ext_lock).and_return(ext_lock_double)
allow(ext_lock_double).to receive(:synchronize) {|&block| block.call }
end
+ let(:pwd_stub) { allow(subject).to receive(:pwd).and_return(bundled_app) }
+
subject { Bundler::SharedHelpers }
describe "#default_gemfile" do
@@ -77,7 +80,7 @@ RSpec.describe Bundler::SharedHelpers do
let(:global_rubygems_dir) { Pathname.new(bundled_app) }
before do
- Dir.mkdir ".bundle"
+ Dir.mkdir bundled_app(".bundle")
allow(Bundler.rubygems).to receive(:user_home).and_return(global_rubygems_dir)
end
@@ -91,7 +94,7 @@ RSpec.describe Bundler::SharedHelpers do
let(:expected_bundle_dir_path) { Pathname.new("#{bundled_app}/.bundle") }
before do
- Dir.mkdir ".bundle"
+ Dir.mkdir bundled_app(".bundle")
allow(Bundler.rubygems).to receive(:user_home).and_return(global_rubygems_dir)
end
@@ -109,8 +112,8 @@ RSpec.describe Bundler::SharedHelpers do
shared_examples_for "correctly determines whether to return a Gemfile path" do
context "currently in directory with a Gemfile" do
- before { FileUtils.touch("Gemfile") }
- after { FileUtils.rm("Gemfile") }
+ before { FileUtils.touch(bundled_app_gemfile) }
+ after { FileUtils.rm(bundled_app_gemfile) }
it "returns path of the bundle Gemfile" do
expect(subject.in_bundle?).to eq("#{bundled_app}/Gemfile")
@@ -148,22 +151,24 @@ RSpec.describe Bundler::SharedHelpers do
describe "#chdir" do
let(:op_block) { proc { Dir.mkdir "nested_dir" } }
- before { Dir.mkdir "chdir_test_dir" }
+ before { Dir.mkdir bundled_app("chdir_test_dir") }
it "executes the passed block while in the specified directory" do
- subject.chdir("chdir_test_dir", &op_block)
- expect(Pathname.new("chdir_test_dir/nested_dir")).to exist
+ subject.chdir(bundled_app("chdir_test_dir"), &op_block)
+ expect(bundled_app("chdir_test_dir/nested_dir")).to exist
end
end
describe "#pwd" do
+ let(:pwd_stub) { nil }
+
it "returns the current absolute path" do
- expect(subject.pwd).to eq(bundled_app)
+ expect(subject.pwd).to eq(root)
end
end
describe "#with_clean_git_env" do
- let(:with_clean_git_env_block) { proc { Dir.mkdir "with_clean_git_env_test_dir" } }
+ let(:with_clean_git_env_block) { proc { Dir.mkdir bundled_app("with_clean_git_env_test_dir") } }
before do
ENV["GIT_DIR"] = "ORIGINAL_ENV_GIT_DIR"
@@ -172,20 +177,20 @@ RSpec.describe Bundler::SharedHelpers do
it "executes the passed block" do
subject.with_clean_git_env(&with_clean_git_env_block)
- expect(Pathname.new("with_clean_git_env_test_dir")).to exist
+ expect(bundled_app("with_clean_git_env_test_dir")).to exist
end
context "when a block is passed" do
let(:with_clean_git_env_block) do
proc do
- Dir.mkdir "git_dir_test_dir" unless ENV["GIT_DIR"].nil?
- Dir.mkdir "git_work_tree_test_dir" unless ENV["GIT_WORK_TREE"].nil?
+ Dir.mkdir bundled_app("git_dir_test_dir") unless ENV["GIT_DIR"].nil?
+ Dir.mkdir bundled_app("git_work_tree_test_dir") unless ENV["GIT_WORK_TREE"].nil?
end end
it "uses a fresh git env for execution" do
subject.with_clean_git_env(&with_clean_git_env_block)
- expect(Pathname.new("git_dir_test_dir")).to_not exist
- expect(Pathname.new("git_work_tree_test_dir")).to_not exist
+ expect(bundled_app("git_dir_test_dir")).to_not exist
+ expect(bundled_app("git_work_tree_test_dir")).to_not exist
end
end
@@ -225,7 +230,7 @@ RSpec.describe Bundler::SharedHelpers do
end
shared_examples_for "ENV['PATH'] gets set correctly" do
- before { Dir.mkdir ".bundle" }
+ before { Dir.mkdir bundled_app(".bundle") }
it "ensures bundle bin path is in ENV['PATH']" do
subject.set_bundle_environment
@@ -245,7 +250,7 @@ RSpec.describe Bundler::SharedHelpers do
let(:ruby_lib_path) { "stubbed_ruby_lib_dir" }
before do
- allow(Bundler::SharedHelpers).to receive(:bundler_ruby_lib).and_return(ruby_lib_path)
+ allow(subject).to receive(:bundler_ruby_lib).and_return(ruby_lib_path)
end
it "ensures bundler's ruby version lib path is in ENV['RUBYLIB']" do
@@ -264,7 +269,7 @@ RSpec.describe Bundler::SharedHelpers do
end
it "ignores if bundler_ruby_lib is same as rubylibdir" do
- allow(Bundler::SharedHelpers).to receive(:bundler_ruby_lib).and_return(RbConfig::CONFIG["rubylibdir"])
+ allow(subject).to receive(:bundler_ruby_lib).and_return(RbConfig::CONFIG["rubylibdir"])
subject.set_bundle_environment
diff --git a/spec/cache/git_spec.rb b/spec/cache/git_spec.rb
index 75525d405b..ecdc97f837 100644
--- a/spec/cache/git_spec.rb
+++ b/spec/cache/git_spec.rb
@@ -155,10 +155,8 @@ RSpec.describe "bundle cache with git" do
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
diff --git a/spec/commands/binstubs_spec.rb b/spec/commands/binstubs_spec.rb
index 1d84b16524..f77e1772bb 100644
--- a/spec/commands/binstubs_spec.rb
+++ b/spec/commands/binstubs_spec.rb
@@ -86,7 +86,7 @@ RSpec.describe "bundle binstubs <gem>" do
bundle "binstubs rack"
- File.open("bin/bundle", "wb") do |file|
+ File.open(bundled_app("bin/bundle"), "wb") do |file|
file.print "OMG"
end
@@ -301,7 +301,7 @@ RSpec.describe "bundle binstubs <gem>" do
bundle "binstubs rack --shebang jruby"
- expect(File.open("bin/rackup").gets).to eq("#!/usr/bin/env jruby\n")
+ expect(File.open(bundled_app("bin/rackup")).gets).to eq("#!/usr/bin/env jruby\n")
end
end
end
diff --git a/spec/commands/check_spec.rb b/spec/commands/check_spec.rb
index 46a5aaa75a..0b5eae5d0b 100644
--- a/spec/commands/check_spec.rb
+++ b/spec/commands/check_spec.rb
@@ -18,8 +18,7 @@ RSpec.describe "bundle check" do
gem "rails"
G
- Dir.chdir tmp
- bundle "check --gemfile bundled_app/Gemfile"
+ bundle "check --gemfile bundled_app/Gemfile", :dir => tmp
expect(out).to include("The Gemfile's dependencies are satisfied")
end
@@ -29,7 +28,7 @@ RSpec.describe "bundle check" do
gem "rails"
G
- FileUtils.rm("Gemfile.lock")
+ FileUtils.rm(bundled_app_lock)
bundle "check"
@@ -42,7 +41,7 @@ RSpec.describe "bundle check" do
gem "rails"
G
- FileUtils.rm("Gemfile.lock")
+ FileUtils.rm(bundled_app_lock)
bundle "check --dry-run"
diff --git a/spec/commands/config_spec.rb b/spec/commands/config_spec.rb
index ef580463e5..7a45dd0dd7 100644
--- a/spec/commands/config_spec.rb
+++ b/spec/commands/config_spec.rb
@@ -54,14 +54,13 @@ RSpec.describe ".bundle/config" do
it "can provide a relative path with the environment variable" do
FileUtils.mkdir_p bundled_app("omg")
- Dir.chdir bundled_app("omg")
ENV["BUNDLE_APP_CONFIG"] = "../foo"
- bundle "install", forgotten_command_line_options(:path => "vendor/bundle")
+ bundle "install", forgotten_command_line_options(:path => "vendor/bundle").merge(:dir => bundled_app("omg"))
expect(bundled_app(".bundle")).not_to exist
expect(bundled_app("../foo/config")).to exist
- expect(the_bundle).to include_gems "rack 1.0.0"
+ expect(the_bundle).to include_gems "rack 1.0.0", :dir => bundled_app("omg")
end
end
@@ -138,7 +137,7 @@ RSpec.describe ".bundle/config" do
it "expands the path at time of setting" do
bundle "config set --global local.foo .."
run "puts Bundler.settings['local.foo']"
- expect(out).to eq(File.expand_path(Dir.pwd + "/.."))
+ expect(out).to eq(File.expand_path(bundled_app.to_s + "/.."))
end
it "saves with parseable option" do
@@ -205,7 +204,7 @@ RSpec.describe ".bundle/config" do
it "expands the path at time of setting" do
bundle "config set --local local.foo .."
run "puts Bundler.settings['local.foo']"
- expect(out).to eq(File.expand_path(Dir.pwd + "/.."))
+ expect(out).to eq(File.expand_path(bundled_app.to_s + "/.."))
end
it "can be deleted with parseable option" do
@@ -484,7 +483,7 @@ RSpec.describe "setting gemfile via config" do
G
bundle "config set --local gemfile #{bundled_app("NotGemfile")}"
- expect(File.exist?(".bundle/config")).to eq(true)
+ expect(File.exist?(bundled_app(".bundle/config"))).to eq(true)
bundle "config list"
expect(out).to include("NotGemfile")
diff --git a/spec/commands/doctor_spec.rb b/spec/commands/doctor_spec.rb
index e62430d215..0731bb08db 100644
--- a/spec/commands/doctor_spec.rb
+++ b/spec/commands/doctor_spec.rb
@@ -32,6 +32,7 @@ RSpec.describe "bundle doctor" do
before(:each) do
stat = double("stat")
unwritable_file = double("file")
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
allow(Find).to receive(:find).with(Bundler.bundle_path.to_s) { [unwritable_file] }
allow(File).to receive(:stat).with(unwritable_file) { stat }
allow(stat).to receive(:uid) { Process.uid }
@@ -72,6 +73,7 @@ RSpec.describe "bundle doctor" do
before(:each) do
@stat = double("stat")
@unwritable_file = double("file")
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
allow(Find).to receive(:find).with(Bundler.bundle_path.to_s) { [@unwritable_file] }
allow(File).to receive(:stat).with(@unwritable_file) { @stat }
end
diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb
index 69a0b33859..f27eb5ca42 100644
--- a/spec/commands/exec_spec.rb
+++ b/spec/commands/exec_spec.rb
@@ -129,11 +129,11 @@ RSpec.describe "bundle exec" do
skip "https://github.com/bundler/bundler/issues/6898" if Gem.win_platform?
install_gemfile 'gem "rack"'
- File.open("--verbose", "w") do |f|
+ File.open(bundled_app("--verbose"), "w") do |f|
f.puts "#!/bin/sh"
f.puts "echo foobar"
end
- File.chmod(0o744, "--verbose")
+ File.chmod(0o744, bundled_app("--verbose"))
with_path_as(".") do
bundle "exec -- --verbose"
end
@@ -152,21 +152,17 @@ RSpec.describe "bundle exec" do
gem "rack", "0.9.1"
G
- in_app_root2 do
- install_gemfile bundled_app2("Gemfile"), <<-G
- source "#{file_uri_for(gem_repo2)}"
- gem "rack_two", "1.0.0"
- G
- end
+ install_gemfile bundled_app2("Gemfile"), <<-G, :dir => bundled_app2
+ source "#{file_uri_for(gem_repo2)}"
+ gem "rack_two", "1.0.0"
+ G
bundle! "exec rackup"
expect(out).to eq("0.9.1")
- in_app_root2 do
- bundle! "exec rackup"
- expect(out).to eq("1.0.0")
- end
+ bundle! "exec rackup", :dir => bundled_app2
+ expect(out).to eq("1.0.0")
end
context "with default gems" do
@@ -260,12 +256,10 @@ RSpec.describe "bundle exec" do
gem "rack", "0.9.1"
G
- in_app_root2 do
- install_gemfile bundled_app2("Gemfile"), <<-G
- source "#{file_uri_for(gem_repo2)}"
- gem "rack_two", "1.0.0"
- G
- end
+ install_gemfile bundled_app2("Gemfile"), <<-G, :dir => bundled_app2
+ source "#{file_uri_for(gem_repo2)}"
+ gem "rack_two", "1.0.0"
+ G
bundle! "exec rackup"
@@ -624,8 +618,8 @@ RSpec.describe "bundle exec" do
RUBY
before do
- path.open("w") {|f| f << executable }
- path.chmod(0o755)
+ bundled_app(path).open("w") {|f| f << executable }
+ bundled_app(path).chmod(0o755)
install_gemfile <<-G
gem "rack"
@@ -798,7 +792,7 @@ __FILE__: #{path.to_s.inspect}
end
context "when the path is relative with a leading ./" do
- let(:path) { Pathname.new("./#{super().relative_path_from(Pathname.pwd)}") }
+ let(:path) { Pathname.new("./#{super().relative_path_from(bundled_app)}") }
pending "relative paths with ./ have absolute __FILE__"
end
diff --git a/spec/commands/info_spec.rb b/spec/commands/info_spec.rb
index a01360a023..b70b711127 100644
--- a/spec/commands/info_spec.rb
+++ b/spec/commands/info_spec.rb
@@ -11,7 +11,7 @@ RSpec.describe "bundle info" do
end
it "creates a Gemfile.lock when invoked with a gem name" do
- FileUtils.rm("Gemfile.lock")
+ FileUtils.rm(bundled_app_lock)
bundle! "info rails"
diff --git a/spec/commands/init_spec.rb b/spec/commands/init_spec.rb
index 1fb83827c2..ed52187115 100644
--- a/spec/commands/init_spec.rb
+++ b/spec/commands/init_spec.rb
@@ -32,9 +32,7 @@ RSpec.describe "bundle init" do
FileUtils.mkdir bundled_app(subdir)
- Dir.chdir bundled_app(subdir) do
- bundle! :init
- end
+ bundle! :init, :dir => bundled_app(subdir)
expect(out).to include("Writing new Gemfile")
expect(bundled_app("#{subdir}/Gemfile")).to be_file
@@ -50,9 +48,7 @@ RSpec.describe "bundle init" do
mode = File.stat(bundled_app(subdir)).mode ^ 0o222
FileUtils.chmod mode, bundled_app(subdir)
- Dir.chdir bundled_app(subdir) do
- bundle :init
- end
+ bundle :init, :dir => bundled_app(subdir)
expect(err).to include("directory is not writable")
expect(Dir[bundled_app("#{subdir}/*")]).to be_empty
@@ -133,9 +129,7 @@ RSpec.describe "bundle init" do
FileUtils.mkdir bundled_app(subdir)
- Dir.chdir bundled_app(subdir) do
- bundle! :init
- end
+ bundle! :init, :dir => bundled_app(subdir)
expect(out).to include("Writing new gems.rb")
expect(bundled_app("#{subdir}/gems.rb")).to be_file
diff --git a/spec/commands/install_spec.rb b/spec/commands/install_spec.rb
index 8acf2202bb..9a4ce33a26 100644
--- a/spec/commands/install_spec.rb
+++ b/spec/commands/install_spec.rb
@@ -504,23 +504,20 @@ RSpec.describe "bundle install with gem sources" do
end
describe "when Bundler root contains regex chars" do
- before do
+ it "doesn't blow up" do
root_dir = tmp("foo[]bar")
FileUtils.mkdir_p(root_dir)
- Dir.chdir(root_dir)
- end
- it "doesn't blow up" do
build_lib "foo"
gemfile = <<-G
gem 'foo', :path => "#{lib_path("foo-1.0")}"
G
- File.open("Gemfile", "w") do |file|
+ File.open("#{root_dir}/Gemfile", "w") do |file|
file.puts gemfile
end
- bundle :install
+ bundle :install, :dir => root_dir
expect(exitstatus).to eq(0) if exitstatus
end
diff --git a/spec/commands/lock_spec.rb b/spec/commands/lock_spec.rb
index 1d9813a835..ceafeb1d7b 100644
--- a/spec/commands/lock_spec.rb
+++ b/spec/commands/lock_spec.rb
@@ -195,6 +195,8 @@ RSpec.describe "bundle lock" do
gem 'foo'
gem 'qux'
G
+
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
end
it "single gem updates dependent gem to minor" do
@@ -213,12 +215,15 @@ RSpec.describe "bundle lock" do
it "supports adding new platforms" do
bundle! "lock --add-platform java x86-mingw32"
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
lockfile = Bundler::LockfileParser.new(read_lockfile)
expect(lockfile.platforms).to match_array(local_platforms.unshift(java, mingw).uniq)
end
it "supports adding the `ruby` platform" do
bundle! "lock --add-platform ruby"
+
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
lockfile = Bundler::LockfileParser.new(read_lockfile)
expect(lockfile.platforms).to match_array(local_platforms.unshift("ruby").uniq)
end
@@ -231,6 +236,7 @@ RSpec.describe "bundle lock" do
it "allows removing platforms" do
bundle! "lock --add-platform java x86-mingw32"
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
lockfile = Bundler::LockfileParser.new(read_lockfile)
expect(lockfile.platforms).to match_array(local_platforms.unshift(java, mingw).uniq)
diff --git a/spec/commands/newgem_spec.rb b/spec/commands/newgem_spec.rb
index 13d1e7abd7..b8fbf8806a 100644
--- a/spec/commands/newgem_spec.rb
+++ b/spec/commands/newgem_spec.rb
@@ -162,13 +162,12 @@ RSpec.describe "bundle gem" do
end
it "includes rubocop in generated Gemfile" do
- Dir.chdir(bundled_app(gem_name)) do
- builder = Bundler::Dsl.new
- builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile"))
- builder.dependencies
- rubocop_dep = builder.dependencies.find {|d| d.name == "rubocop" }
- expect(rubocop_dep).not_to be_nil
- end
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
+ builder = Bundler::Dsl.new
+ builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile"))
+ builder.dependencies
+ rubocop_dep = builder.dependencies.find {|d| d.name == "rubocop" }
+ expect(rubocop_dep).not_to be_nil
end
end
@@ -186,13 +185,12 @@ RSpec.describe "bundle gem" do
end
it "does not include rubocop in generated Gemfile" do
- Dir.chdir(bundled_app(gem_name)) do
- builder = Bundler::Dsl.new
- builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile"))
- builder.dependencies
- rubocop_dep = builder.dependencies.find {|d| d.name == "rubocop" }
- expect(rubocop_dep).to be_nil
- end
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
+ builder = Bundler::Dsl.new
+ builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile"))
+ builder.dependencies
+ rubocop_dep = builder.dependencies.find {|d| d.name == "rubocop" }
+ expect(rubocop_dep).to be_nil
end
end
@@ -253,11 +251,9 @@ RSpec.describe "bundle gem" do
prepare_gemspec(bundled_app("newgem", "newgem.gemspec"))
- Dir.chdir(bundled_app("newgem")) do
- gems = ["rake-12.3.2"]
- system_gems gems, :path => :bundle_path
- bundle! "exec rake build"
- end
+ gems = ["rake-12.3.2"]
+ system_gems gems, :path => :bundle_path, :bundle_dir => bundled_app("newgem")
+ bundle! "exec rake build", :dir => bundled_app("newgem")
expect(last_command.stdboth).not_to include("ERROR")
end
@@ -266,7 +262,7 @@ RSpec.describe "bundle gem" do
it "resolves ." do
create_temporary_dir("tmp")
- bundle! "gem ."
+ bundle! "gem .", :dir => bundled_app("tmp")
expect(bundled_app("tmp/lib/tmp.rb")).to exist
end
@@ -274,7 +270,7 @@ RSpec.describe "bundle gem" do
it "resolves .." do
create_temporary_dir("temp/empty_dir")
- bundle! "gem .."
+ bundle! "gem ..", :dir => bundled_app("temp/empty_dir")
expect(bundled_app("temp/lib/temp.rb")).to exist
end
@@ -282,14 +278,13 @@ RSpec.describe "bundle gem" do
it "resolves relative directory" do
create_temporary_dir("tmp/empty/tmp")
- bundle! "gem ../../empty"
+ bundle! "gem ../../empty", :dir => bundled_app("tmp/empty/tmp")
expect(bundled_app("tmp/empty/lib/empty.rb")).to exist
end
def create_temporary_dir(dir)
- FileUtils.mkdir_p(dir)
- Dir.chdir(dir)
+ FileUtils.mkdir_p(bundled_app(dir))
end
end
@@ -326,8 +321,8 @@ RSpec.describe "bundle gem" do
context "git config user.{name,email} is not set" do
before do
- `git config --unset user.name`
- `git config --unset user.email`
+ sys_exec("git config --unset user.name", :dir => bundled_app)
+ sys_exec("git config --unset user.email", :dir => bundled_app)
bundle! "gem #{gem_name}"
end
@@ -375,10 +370,8 @@ RSpec.describe "bundle gem" do
file.puts rakefile
end
- Dir.chdir(bundled_app(gem_name)) do
- sys_exec(rake)
- expect(out).to include("SUCCESS")
- end
+ sys_exec(rake, :dir => bundled_app(gem_name))
+ expect(out).to include("SUCCESS")
end
context "--exe parameter set" do
@@ -435,13 +428,12 @@ RSpec.describe "bundle gem" do
end
it "depends on a specific version of rspec in generated Gemfile" do
- Dir.chdir(bundled_app(gem_name)) do
- builder = Bundler::Dsl.new
- builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile"))
- builder.dependencies
- rspec_dep = builder.dependencies.find {|d| d.name == "rspec" }
- expect(rspec_dep).to be_specific
- end
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
+ builder = Bundler::Dsl.new
+ builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile"))
+ builder.dependencies
+ rspec_dep = builder.dependencies.find {|d| d.name == "rspec" }
+ expect(rspec_dep).to be_specific
end
it "requires the main file" do
@@ -484,13 +476,12 @@ RSpec.describe "bundle gem" do
end
it "depends on a specific version of minitest" do
- Dir.chdir(bundled_app(gem_name)) do
- builder = Bundler::Dsl.new
- builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile"))
- builder.dependencies
- minitest_dep = builder.dependencies.find {|d| d.name == "minitest" }
- expect(minitest_dep).to be_specific
- end
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
+ builder = Bundler::Dsl.new
+ builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile"))
+ builder.dependencies
+ minitest_dep = builder.dependencies.find {|d| d.name == "minitest" }
+ expect(minitest_dep).to be_specific
end
it "builds spec skeleton" do
@@ -541,13 +532,12 @@ RSpec.describe "bundle gem" do
end
it "depends on a specific version of test-unit" do
- Dir.chdir(bundled_app(gem_name)) do
- builder = Bundler::Dsl.new
- builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile"))
- builder.dependencies
- test_unit_dep = builder.dependencies.find {|d| d.name == "test-unit" }
- expect(test_unit_dep).to be_specific
- end
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
+ builder = Bundler::Dsl.new
+ builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile"))
+ builder.dependencies
+ test_unit_dep = builder.dependencies.find {|d| d.name == "test-unit" }
+ expect(test_unit_dep).to be_specific
end
it "builds spec skeleton" do
@@ -610,7 +600,7 @@ RSpec.describe "bundle gem" do
context "--edit option" do
it "opens the generated gemspec in the user's text editor" do
output = bundle "gem #{gem_name} --edit=echo"
- gemspec_path = File.join(Dir.pwd, gem_name, "#{gem_name}.gemspec")
+ gemspec_path = File.join(bundled_app, gem_name, "#{gem_name}.gemspec")
expect(output).to include("echo \"#{gemspec_path}\"")
end
end
@@ -841,7 +831,7 @@ Usage: "bundle gem NAME [OPTIONS]"
context "on conflicts with a previously created file", :readline do
it "should fail gracefully" do
- FileUtils.touch("conflict-foobar")
+ FileUtils.touch(bundled_app("conflict-foobar"))
bundle "gem conflict-foobar"
expect(err).to include("Errno::ENOTDIR")
expect(exitstatus).to eql(32) if exitstatus
@@ -850,7 +840,7 @@ Usage: "bundle gem NAME [OPTIONS]"
context "on conflicts with a previously created directory", :readline do
it "should succeed" do
- FileUtils.mkdir_p("conflict-foobar/Gemfile")
+ FileUtils.mkdir_p(bundled_app("conflict-foobar/Gemfile"))
bundle! "gem conflict-foobar"
expect(out).to include("file_clash conflict-foobar/Gemfile").
and include "Initializing git repo in #{bundled_app("conflict-foobar")}"
diff --git a/spec/commands/pristine_spec.rb b/spec/commands/pristine_spec.rb
index 1c267ab78f..15336137b6 100644
--- a/spec/commands/pristine_spec.rb
+++ b/spec/commands/pristine_spec.rb
@@ -28,6 +28,8 @@ RSpec.describe "bundle pristine", :ruby_repo do
gemspec
G
+
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
end
context "when sourced from RubyGems" do
diff --git a/spec/commands/show_spec.rb b/spec/commands/show_spec.rb
index 3a1fcc1a7a..7b329c8e7f 100644
--- a/spec/commands/show_spec.rb
+++ b/spec/commands/show_spec.rb
@@ -10,7 +10,7 @@ RSpec.describe "bundle show", :bundler => "< 3" do
end
it "creates a Gemfile.lock if one did not exist" do
- FileUtils.rm("Gemfile.lock")
+ FileUtils.rm(bundled_app_lock)
bundle! "show"
@@ -18,7 +18,7 @@ RSpec.describe "bundle show", :bundler => "< 3" do
end
it "creates a Gemfile.lock when invoked with a gem name" do
- FileUtils.rm("Gemfile.lock")
+ FileUtils.rm(bundled_app_lock)
bundle! "show rails"
@@ -143,13 +143,12 @@ RSpec.describe "bundle show", :bundler => "< 3" do
context "in a fresh gem in a blank git repo" do
before :each do
build_git "foo", :path => lib_path("foo")
- Dir.chdir lib_path("foo")
- File.open("Gemfile", "w") {|f| f.puts "gemspec" }
- sys_exec "rm -rf .git && git init"
+ File.open(lib_path("foo/Gemfile"), "w") {|f| f.puts "gemspec" }
+ sys_exec "rm -rf .git && git init", :dir => lib_path("foo")
end
it "does not output git errors" do
- bundle :show
+ bundle :show, :dir => lib_path("foo")
expect(err_without_deprecations).to be_empty
end
end
diff --git a/spec/commands/update_spec.rb b/spec/commands/update_spec.rb
index 8455d140fe..5a7d26353c 100644
--- a/spec/commands/update_spec.rb
+++ b/spec/commands/update_spec.rb
@@ -831,6 +831,7 @@ RSpec.describe "bundle update --bundler" do
source "#{file_uri_for(gem_repo4)}"
gem "rack"
G
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, '\11.0.0\2')
FileUtils.rm_r gem_repo4
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
diff --git a/spec/plugins/install_spec.rb b/spec/plugins/install_spec.rb
index 669ed09fb5..663363ca21 100644
--- a/spec/plugins/install_spec.rb
+++ b/spec/plugins/install_spec.rb
@@ -155,6 +155,10 @@ RSpec.describe "bundler plugin install" do
end
context "Gemfile eval" do
+ before do
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
+ end
+
it "installs plugins listed in gemfile" do
gemfile <<-G
source '#{file_uri_for(gem_repo2)}'
@@ -245,6 +249,7 @@ RSpec.describe "bundler plugin install" do
describe "local plugin" do
it "is installed when inside an app" do
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
gemfile ""
bundle "plugin install foo --source #{file_uri_for(gem_repo2)}"
@@ -287,21 +292,16 @@ RSpec.describe "bundler plugin install" do
end
# outside the app
- Dir.chdir tmp
- bundle "plugin install fubar --source #{file_uri_for(gem_repo2)}"
+ bundle "plugin install fubar --source #{file_uri_for(gem_repo2)}", :dir => tmp
end
it "inside the app takes precedence over global plugin" do
- Dir.chdir bundled_app
-
bundle "shout"
expect(out).to eq("local_one")
end
it "outside the app global plugin is used" do
- Dir.chdir tmp
-
- bundle "shout"
+ bundle "shout", :dir => tmp
expect(out).to eq("global_one")
end
end
diff --git a/spec/plugins/source/example_spec.rb b/spec/plugins/source/example_spec.rb
index f2151a5a73..aac506dc9a 100644
--- a/spec/plugins/source/example_spec.rb
+++ b/spec/plugins/source/example_spec.rb
@@ -215,6 +215,8 @@ RSpec.describe "real source plugins" do
build_repo2 do
build_plugin "bundler-source-gitp" do |s|
s.write "plugins.rb", <<-RUBY
+ require "open3"
+
class SPlugin < Bundler::Plugin::API
source "gitp"
@@ -254,9 +256,7 @@ RSpec.describe "real source plugins" do
mkdir_p(install_path.dirname)
rm_rf(install_path)
`git clone --no-checkout --quiet "\#{cache_path}" "\#{install_path}"`
- Dir.chdir install_path do
- `git reset --hard \#{revision}`
- end
+ Open3.capture2e("git reset --hard \#{revision}", :chdir => install_path)
spec_path = install_path.join("\#{spec.full_name}.gemspec")
spec_path.open("wb") {|f| f.write spec.to_ruby }
@@ -310,9 +310,8 @@ RSpec.describe "real source plugins" do
cache_repo
end
- Dir.chdir cache_path do
- `git rev-parse --verify \#{@ref}`.strip
- end
+ output, _status = Open3.capture2e("git rev-parse --verify \#{@ref}", :chdir => cache_path)
+ output.strip
end
def base_name
diff --git a/spec/plugins/source_spec.rb b/spec/plugins/source_spec.rb
index c8deee96b1..14643e5c81 100644
--- a/spec/plugins/source_spec.rb
+++ b/spec/plugins/source_spec.rb
@@ -21,6 +21,7 @@ RSpec.describe "bundler source plugin" do
end
G
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
plugin_should_be_installed("bundler-source-psource")
end
@@ -75,6 +76,7 @@ RSpec.describe "bundler source plugin" do
end
it "installs the explicit one" do
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
plugin_should_be_installed("another-psource")
end
@@ -100,6 +102,7 @@ RSpec.describe "bundler source plugin" do
end
it "installs the default one" do
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
plugin_should_be_installed("bundler-source-psource")
end
end
diff --git a/spec/quality_es_spec.rb b/spec/quality_es_spec.rb
index c1cb028ee1..ab2e2983aa 100644
--- a/spec/quality_es_spec.rb
+++ b/spec/quality_es_spec.rb
@@ -40,12 +40,10 @@ RSpec.describe "La biblioteca si misma" do
it "mantiene la calidad de lenguaje de la documentación" do
included = /ronn/
error_messages = []
- in_repo_root do
- man_tracked_files.split("\x0").each do |filename|
- next unless filename =~ included
- error_messages << check_for_expendable_words(filename)
- error_messages << check_for_specific_pronouns(filename)
- end
+ man_tracked_files.split("\x0").each do |filename|
+ next unless filename =~ included
+ error_messages << check_for_expendable_words(filename)
+ error_messages << check_for_specific_pronouns(filename)
end
expect(error_messages.compact).to be_well_formed
end
@@ -53,12 +51,10 @@ RSpec.describe "La biblioteca si misma" do
it "mantiene la calidad de lenguaje de oraciones usadas en el código fuente" do
error_messages = []
exempt = /vendor/
- in_repo_root do
- lib_tracked_files.split("\x0").each do |filename|
- next if filename =~ exempt
- error_messages << check_for_expendable_words(filename)
- error_messages << check_for_specific_pronouns(filename)
- end
+ lib_tracked_files.split("\x0").each do |filename|
+ next if filename =~ exempt
+ error_messages << check_for_expendable_words(filename)
+ error_messages << check_for_specific_pronouns(filename)
end
expect(error_messages.compact).to be_well_formed
end
diff --git a/spec/quality_spec.rb b/spec/quality_spec.rb
index 95ab31dae0..e94addae5e 100644
--- a/spec/quality_spec.rb
+++ b/spec/quality_spec.rb
@@ -107,12 +107,10 @@ RSpec.describe "The library itself" do
it "has no malformed whitespace" do
exempt = /\.gitmodules|fixtures|vendor|LICENSE|vcr_cassettes|rbreadline\.diff|\.txt$/
error_messages = []
- in_repo_root do
- tracked_files.split("\x0").each do |filename|
- next if filename =~ exempt
- error_messages << check_for_tab_characters(filename)
- error_messages << check_for_extra_spaces(filename)
- end
+ tracked_files.split("\x0").each do |filename|
+ next if filename =~ exempt
+ error_messages << check_for_tab_characters(filename)
+ error_messages << check_for_extra_spaces(filename)
end
expect(error_messages.compact).to be_well_formed
end
@@ -120,11 +118,9 @@ RSpec.describe "The library itself" do
it "has no estraneous quotes" do
exempt = /vendor|vcr_cassettes|LICENSE|rbreadline\.diff/
error_messages = []
- in_repo_root do
- tracked_files.split("\x0").each do |filename|
- next if filename =~ exempt
- error_messages << check_for_straneous_quotes(filename)
- end
+ tracked_files.split("\x0").each do |filename|
+ next if filename =~ exempt
+ error_messages << check_for_straneous_quotes(filename)
end
expect(error_messages.compact).to be_well_formed
end
@@ -132,11 +128,9 @@ RSpec.describe "The library itself" do
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}
error_messages = []
- in_repo_root do
- tracked_files.split("\x0").each do |filename|
- next if filename =~ exempt
- error_messages << check_for_debugging_mechanisms(filename)
- end
+ tracked_files.split("\x0").each do |filename|
+ next if filename =~ exempt
+ error_messages << check_for_debugging_mechanisms(filename)
end
expect(error_messages.compact).to be_well_formed
end
@@ -144,11 +138,9 @@ RSpec.describe "The library itself" do
it "does not include any unresolved merge conflicts" do
error_messages = []
exempt = %r{lock/lockfile_spec|quality_spec|vcr_cassettes|\.ronn|lockfile_parser\.rb}
- in_repo_root do
- tracked_files.split("\x0").each do |filename|
- next if filename =~ exempt
- error_messages << check_for_git_merge_conflicts(filename)
- end
+ tracked_files.split("\x0").each do |filename|
+ next if filename =~ exempt
+ error_messages << check_for_git_merge_conflicts(filename)
end
expect(error_messages.compact).to be_well_formed
end
@@ -156,12 +148,10 @@ RSpec.describe "The library itself" do
it "maintains language quality of the documentation" do
included = /ronn/
error_messages = []
- in_repo_root do
- man_tracked_files.split("\x0").each do |filename|
- next unless filename =~ included
- error_messages << check_for_expendable_words(filename)
- error_messages << check_for_specific_pronouns(filename)
- end
+ man_tracked_files.split("\x0").each do |filename|
+ next unless filename =~ included
+ error_messages << check_for_expendable_words(filename)
+ error_messages << check_for_specific_pronouns(filename)
end
expect(error_messages.compact).to be_well_formed
end
@@ -169,12 +159,10 @@ RSpec.describe "The library itself" do
it "maintains language quality of sentences used in source code" do
error_messages = []
exempt = /vendor|vcr_cassettes/
- in_repo_root do
- lib_tracked_files.split("\x0").each do |filename|
- next if filename =~ exempt
- error_messages << check_for_expendable_words(filename)
- error_messages << check_for_specific_pronouns(filename)
- end
+ lib_tracked_files.split("\x0").each do |filename|
+ next if filename =~ exempt
+ error_messages << check_for_expendable_words(filename)
+ error_messages << check_for_specific_pronouns(filename)
end
expect(error_messages.compact).to be_well_formed
end
@@ -197,15 +185,13 @@ RSpec.describe "The library itself" do
Bundler::Settings::NUMBER_KEYS.each {|k| all_settings[k] << "in Bundler::Settings::NUMBER_KEYS" }
Bundler::Settings::ARRAY_KEYS.each {|k| all_settings[k] << "in Bundler::Settings::ARRAY_KEYS" }
- in_repo_root do
- key_pattern = /([a-z\._-]+)/i
- lib_tracked_files.split("\x0").each do |filename|
- each_line(filename) do |line, number|
- line.scan(/Bundler\.settings\[:#{key_pattern}\]/).flatten.each {|s| all_settings[s] << "referenced at `#{filename}:#{number.succ}`" }
- end
+ key_pattern = /([a-z\._-]+)/i
+ lib_tracked_files.split("\x0").each do |filename|
+ each_line(filename) do |line, number|
+ line.scan(/Bundler\.settings\[:#{key_pattern}\]/).flatten.each {|s| all_settings[s] << "referenced at `#{filename}:#{number.succ}`" }
end
- documented_settings = File.read("man/bundle-config.ronn")[/LIST OF AVAILABLE KEYS.*/m].scan(/^\* `#{key_pattern}`/).flatten
end
+ documented_settings = File.read("man/bundle-config.ronn")[/LIST OF AVAILABLE KEYS.*/m].scan(/^\* `#{key_pattern}`/).flatten
documented_settings.each do |s|
all_settings.delete(s)
@@ -231,54 +217,48 @@ RSpec.describe "The library itself" do
end
it "ships the correct set of files" do
- in_repo_root do
- git_list = shipped_files.split("\x0")
+ git_list = shipped_files.split("\x0")
- gem_list = Gem::Specification.load(gemspec.to_s).files
+ gem_list = Gem::Specification.load(gemspec.to_s).files
- expect(git_list.to_set).to eq(gem_list.to_set)
- end
+ expect(git_list.to_set).to eq(gem_list.to_set)
end
it "does not contain any warnings" do
- in_repo_root do
- exclusions = %w[
- lib/bundler/capistrano.rb
- lib/bundler/deployment.rb
- lib/bundler/gem_tasks.rb
- lib/bundler/vlad.rb
- lib/bundler/templates/gems.rb
- ]
- files_to_require = lib_tracked_files.split("\x0").grep(/\.rb$/) - exclusions
- files_to_require.reject! {|f| f.start_with?("lib/bundler/vendor") }
- files_to_require.map! {|f| File.expand_path("../#{f}", __dir__) }
- sys_exec!("ruby -w") do |input, _, _|
- files_to_require.each do |f|
- input.puts "require '#{f}'"
- end
+ exclusions = %w[
+ lib/bundler/capistrano.rb
+ lib/bundler/deployment.rb
+ lib/bundler/gem_tasks.rb
+ lib/bundler/vlad.rb
+ lib/bundler/templates/gems.rb
+ ]
+ files_to_require = lib_tracked_files.split("\x0").grep(/\.rb$/) - exclusions
+ files_to_require.reject! {|f| f.start_with?("lib/bundler/vendor") }
+ files_to_require.map! {|f| File.expand_path("../#{f}", __dir__) }
+ sys_exec!("ruby -w") do |input, _, _|
+ files_to_require.each do |f|
+ input.puts "require '#{f}'"
end
+ end
- warnings = last_command.stdboth.split("\n")
- # ignore warnings around deprecated Object#=~ method in RubyGems
- warnings.reject! {|w| w =~ %r{rubygems\/version.rb.*deprecated\ Object#=~} }
+ warnings = last_command.stdboth.split("\n")
+ # ignore warnings around deprecated Object#=~ method in RubyGems
+ warnings.reject! {|w| w =~ %r{rubygems\/version.rb.*deprecated\ Object#=~} }
- expect(warnings).to be_well_formed
- end
+ expect(warnings).to be_well_formed
end
it "does not use require internally, but require_relative" do
- in_repo_root do
- exempt = %r{templates/|vendor/}
- all_bad_requires = []
- lib_tracked_files.split("\x0").each do |filename|
- next if filename =~ exempt
- each_line(filename) do |line, number|
- line.scan(/^ *require "bundler/).each { all_bad_requires << "#{filename}:#{number.succ}" }
- end
+ exempt = %r{templates/|vendor/}
+ all_bad_requires = []
+ lib_tracked_files.split("\x0").each do |filename|
+ next if filename =~ exempt
+ each_line(filename) do |line, number|
+ line.scan(/^ *require "bundler/).each { all_bad_requires << "#{filename}:#{number.succ}" }
end
-
- expect(all_bad_requires).to be_empty, "#{all_bad_requires.size} internal requires that should use `require_relative`: #{all_bad_requires}"
end
+
+ expect(all_bad_requires).to be_empty, "#{all_bad_requires.size} internal requires that should use `require_relative`: #{all_bad_requires}"
end
private
diff --git a/spec/runtime/executable_spec.rb b/spec/runtime/executable_spec.rb
index 96197a52b8..e420594f52 100644
--- a/spec/runtime/executable_spec.rb
+++ b/spec/runtime/executable_spec.rb
@@ -44,14 +44,14 @@ RSpec.describe "Running bin/* commands" do
it "uses the default ruby install name when shebang is not specified" do
bundle! "binstubs rack"
- expect(File.open("bin/rackup").gets).to eq("#!/usr/bin/env #{RbConfig::CONFIG["ruby_install_name"]}\n")
+ expect(File.open(bundled_app("bin/rackup")).gets).to eq("#!/usr/bin/env #{RbConfig::CONFIG["ruby_install_name"]}\n")
end
it "allows the name of the shebang executable to be specified" do
skip "not created with custom name :/" if Gem.win_platform?
bundle! "binstubs rack", :shebang => "ruby-foo"
- expect(File.open("bin/rackup").gets).to eq("#!/usr/bin/env ruby-foo\n")
+ expect(File.open(bundled_app("bin/rackup")).gets).to eq("#!/usr/bin/env ruby-foo\n")
end
it "runs the bundled command when out of the bundle" do
@@ -63,10 +63,8 @@ RSpec.describe "Running bin/* commands" do
s.executables = "rackup"
end
- Dir.chdir(tmp) do
- gembin "rackup"
- expect(out).to eq("1.0.0")
- end
+ gembin "rackup", :dir => tmp
+ expect(out).to eq("1.0.0")
end
it "works with gems in path" do
diff --git a/spec/runtime/gem_tasks_spec.rb b/spec/runtime/gem_tasks_spec.rb
index 91ea5cf189..4fe9d43e73 100644
--- a/spec/runtime/gem_tasks_spec.rb
+++ b/spec/runtime/gem_tasks_spec.rb
@@ -59,15 +59,12 @@ RSpec.describe "require 'bundler/gem_tasks'" do
context "rake build when path has spaces" do
before do
- Dir.chdir(root)
spaced_bundled_app = tmp.join("bundled app")
FileUtils.mv bundled_app, spaced_bundled_app
- Dir.chdir(spaced_bundled_app)
+ bundle! "exec rake build", :dir => spaced_bundled_app
end
it "still runs successfully" do
- bundle! "exec rake build"
-
expect(err).to be_empty
end
end
diff --git a/spec/runtime/inline_spec.rb b/spec/runtime/inline_spec.rb
index def258ec66..fb6c6e90ad 100644
--- a/spec/runtime/inline_spec.rb
+++ b/spec/runtime/inline_spec.rb
@@ -233,16 +233,14 @@ RSpec.describe "bundler/inline#gemfile" do
1.13.6
G
- in_app_root do
- script <<-RUBY
- gemfile do
- source "#{file_uri_for(gem_repo1)}"
- gem "rack"
- end
+ script <<-RUBY
+ gemfile do
+ source "#{file_uri_for(gem_repo1)}"
+ gem "rack"
+ end
- puts RACK
- RUBY
- end
+ puts RACK
+ RUBY
expect(err).to be_empty
expect(exitstatus).to be_zero if exitstatus
@@ -265,16 +263,14 @@ RSpec.describe "bundler/inline#gemfile" do
it "installs inline gems when BUNDLE_GEMFILE is set to an empty string" do
ENV["BUNDLE_GEMFILE"] = ""
- in_app_root do
- script <<-RUBY
- gemfile do
- source "#{file_uri_for(gem_repo1)}"
- gem "rack"
- end
+ script <<-RUBY
+ gemfile do
+ source "#{file_uri_for(gem_repo1)}"
+ gem "rack"
+ end
- puts RACK
- RUBY
- end
+ puts RACK
+ RUBY
expect(err).to be_empty
expect(exitstatus).to be_zero if exitstatus
diff --git a/spec/runtime/load_spec.rb b/spec/runtime/load_spec.rb
index 7de67e247c..a406fbaf49 100644
--- a/spec/runtime/load_spec.rb
+++ b/spec/runtime/load_spec.rb
@@ -7,6 +7,7 @@ RSpec.describe "Bundler.load" do
source "#{file_uri_for(gem_repo1)}"
gem "rack"
G
+ allow(Bundler::SharedHelpers).to receive(:pwd).and_return(bundled_app)
end
it "provides a list of the env dependencies" do
@@ -32,6 +33,7 @@ RSpec.describe "Bundler.load" do
gem "rack"
G
bundle! :install
+ allow(Bundler::SharedHelpers).to receive(:pwd).and_return(bundled_app)
end
it "provides a list of the env dependencies" do
@@ -101,7 +103,7 @@ RSpec.describe "Bundler.load" do
source "#{file_uri_for(gem_repo1)}"
gem "activerecord"
G
-
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
Bundler.load.specs.each do |spec|
expect(spec.to_yaml).not_to match(/^\s+source:/)
expect(spec.to_yaml).not_to match(/^\s+groups:/)
diff --git a/spec/runtime/platform_spec.rb b/spec/runtime/platform_spec.rb
index f7e93eacf1..ad9c56d14e 100644
--- a/spec/runtime/platform_spec.rb
+++ b/spec/runtime/platform_spec.rb
@@ -117,7 +117,7 @@ RSpec.describe "Bundler.setup with multi platform stuff" do
end
it "allows specifying only-ruby-platform on windows with gemspec dependency" do
- build_lib("foo", "1.0", :path => ".") do |s|
+ build_lib("foo", "1.0", :path => bundled_app) do |s|
s.add_dependency "rack"
end
diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb
index 8c2c55ac5b..f94efbea6a 100644
--- a/spec/runtime/setup_spec.rb
+++ b/spec/runtime/setup_spec.rb
@@ -489,15 +489,16 @@ RSpec.describe "Bundler.setup" do
it "does not randomly change the path when specifying --path and the bundle directory becomes read only" do
bundle! :install, forgotten_command_line_options(:path => "vendor/bundle")
- with_read_only("**/*") do
+ with_read_only("#{bundled_app}/**/*") do
expect(the_bundle).to include_gems "rack 1.0.0"
end
end
it "finds git gem when default bundle path becomes read only" do
+ bundle "config set --local path .bundle"
bundle "install"
- with_read_only("#{Bundler.bundle_path}/**/*") do
+ with_read_only("#{bundled_app(".bundle")}/**/*") do
expect(the_bundle).to include_gems "rack 1.0.0"
end
end
@@ -865,11 +866,9 @@ end
gem 'foo', '1.2.3', :path => 'vendor/foo'
G
- Dir.chdir(bundled_app.parent) do
- run <<-R, :env => { "BUNDLE_GEMFILE" => bundled_app_gemfile.to_s }
- require 'foo'
- R
- end
+ run <<-R, :env => { "BUNDLE_GEMFILE" => bundled_app_gemfile.to_s }, :dir => bundled_app.parent
+ require 'foo'
+ R
expect(err).to be_empty
end
@@ -889,11 +888,9 @@ end
bundle :install
- Dir.chdir(bundled_app.parent) do
- run <<-R, :env => { "BUNDLE_GEMFILE" => bundled_app_gemfile.to_s }
- require 'foo'
- R
- end
+ run <<-R, :env => { "BUNDLE_GEMFILE" => bundled_app_gemfile.to_s }, :dir => bundled_app.parent
+ require 'foo'
+ R
expect(err).to be_empty
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 2b975cf5fc..0074cb81d8 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -58,7 +58,6 @@ RSpec.configure do |config|
config.bisect_runner = :shell
- original_wd = Dir.pwd
original_env = ENV.to_hash
config.expect_with :rspec do |c|
@@ -105,8 +104,6 @@ RSpec.configure do |config|
reset!
system_gems []
- Dir.chdir(bundled_app)
-
@command_executions = []
Bundler.ui.silence { example.run }
@@ -119,8 +116,6 @@ RSpec.configure do |config|
message
end
end
-
- Dir.chdir(original_wd)
end
config.after :suite do
diff --git a/spec/support/builders.rb b/spec/support/builders.rb
index 021057cc3c..467a9f2ccd 100644
--- a/spec/support/builders.rb
+++ b/spec/support/builders.rb
@@ -394,7 +394,7 @@ module Spec
@_build_repo = File.basename(path)
yield
with_gem_path_as Path.base_system_gems do
- Dir.chdir(path) { gem_command! :generate_index }
+ gem_command! :generate_index, :dir => path
end
ensure
@_build_path = nil
@@ -551,6 +551,11 @@ module Spec
@files = {}
end
+ def capture(cmd, dir)
+ output, _status = Open3.capture2e(cmd, :chdir => dir)
+ output
+ end
+
def method_missing(*args, &blk)
@spec.send(*args, &blk)
end
@@ -660,14 +665,12 @@ module Spec
path = options[:path] || _default_path
source = options[:source] || "git@#{path}"
super(options.merge(:path => path, :source => source))
- Dir.chdir(path) do
- `git init`
- `git add *`
- `git config user.email "lol@wut.com"`
- `git config user.name "lolwut"`
- `git config commit.gpgsign false`
- `git commit -m "OMG INITIAL COMMIT"`
- end
+ capture("git init", path)
+ capture("git add *", path)
+ capture("git config user.email \"lol@wut.com\"", path)
+ capture("git config user.name \"lolwut\"", path)
+ capture("git config commit.gpgsign false", path)
+ capture("git commit -m \"OMG INITIAL COMMIT\"", path)
end
end
@@ -675,15 +678,14 @@ module Spec
def _build(options)
path = options[:path] || _default_path
super(options.merge(:path => path))
- Dir.chdir(path) do
- `git init --bare`
- end
+ capture("git init --bare", path)
end
end
class GitUpdater < LibBuilder
- def silently(str)
- `#{str} 2>#{Bundler::NULL}`
+ def silently(str, dir)
+ output, _error, _status = Open3.capture3(str, :chdir => dir)
+ output
end
def _build(options)
@@ -691,34 +693,32 @@ module Spec
update_gemspec = options[:gemspec] || false
source = options[:source] || "git@#{libpath}"
- Dir.chdir(libpath) do
- silently "git checkout master"
+ silently "git checkout master", libpath
- if branch = options[:branch]
- raise "You can't specify `master` as the branch" if branch == "master"
- escaped_branch = Shellwords.shellescape(branch)
+ if branch = options[:branch]
+ raise "You can't specify `master` as the branch" if branch == "master"
+ escaped_branch = Shellwords.shellescape(branch)
- if `git branch | grep #{escaped_branch}`.empty?
- silently("git branch #{escaped_branch}")
- end
-
- silently("git checkout #{escaped_branch}")
- elsif tag = options[:tag]
- `git tag #{Shellwords.shellescape(tag)}`
- elsif options[:remote]
- silently("git remote add origin #{options[:remote]}")
- elsif options[:push]
- silently("git push origin #{options[:push]}")
+ if capture("git branch | grep #{escaped_branch}", libpath).empty?
+ silently("git branch #{escaped_branch}", libpath)
end
- current_ref = `git rev-parse HEAD`.strip
- _default_files.keys.each do |path|
- _default_files[path] += "\n#{Builders.constantize(name)}_PREV_REF = '#{current_ref}'"
- end
- super(options.merge(:path => libpath, :gemspec => update_gemspec, :source => source))
- `git add *`
- `git commit -m "BUMP"`
+ silently("git checkout #{escaped_branch}", libpath)
+ elsif tag = options[:tag]
+ capture("git tag #{Shellwords.shellescape(tag)}", libpath)
+ elsif options[:remote]
+ silently("git remote add origin #{options[:remote]}", libpath)
+ elsif options[:push]
+ silently("git push origin #{options[:push]}", libpath)
+ end
+
+ current_ref = silently("git rev-parse HEAD", libpath).strip
+ _default_files.keys.each do |path|
+ _default_files[path] += "\n#{Builders.constantize(name)}_PREV_REF = '#{current_ref}'"
end
+ super(options.merge(:path => libpath, :gemspec => update_gemspec, :source => source))
+ capture("git add *", libpath)
+ capture("git commit -m \"BUMP\"", libpath)
end
end
@@ -739,7 +739,7 @@ module Spec
def git(cmd)
Bundler::SharedHelpers.with_clean_git_env do
- Dir.chdir(@path) { `git #{cmd}`.strip }
+ Open3.capture2e("git #{cmd}", :chdir => path)[0].strip
end
end
end
diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb
index 4180a2f1ae..dde8daaf6f 100644
--- a/spec/support/helpers.rb
+++ b/spec/support/helpers.rb
@@ -114,6 +114,8 @@ module Spec
load_path << spec_dir
load_path_str = "-I#{load_path.join(File::PATH_SEPARATOR)}"
+ dir = options.delete(:dir) || bundled_app
+
args = options.map do |k, v|
case v
when nil
@@ -128,7 +130,7 @@ module Spec
end.join
cmd = "#{sudo} #{Gem.ruby} #{load_path_str} #{requires_str} #{bundle_bin} #{cmd}#{args}"
- sys_exec(cmd, { :env => env }, &block)
+ sys_exec(cmd, { :env => env, :dir => dir }, &block)
end
bang :bundle
@@ -170,17 +172,17 @@ module Spec
R
end
- def gembin(cmd)
+ def gembin(cmd, options = {})
old = ENV["RUBYOPT"]
ENV["RUBYOPT"] = "#{ENV["RUBYOPT"]} -I#{lib_dir}"
cmd = bundled_app("bin/#{cmd}") unless cmd.to_s.include?("/")
- sys_exec(cmd.to_s)
+ sys_exec(cmd.to_s, options)
ensure
ENV["RUBYOPT"] = old
end
- def gem_command(command)
- sys_exec("#{Path.gem_bin} #{command}")
+ def gem_command(command, options = {})
+ sys_exec("#{Path.gem_bin} #{command}", options)
end
bang :gem_command
@@ -190,11 +192,12 @@ module Spec
def sys_exec(cmd, options = {})
env = options[:env] || {}
- command_execution = CommandExecution.new(cmd.to_s, Dir.pwd)
+ dir = options[:dir] || bundled_app
+ command_execution = CommandExecution.new(cmd.to_s, dir)
require "open3"
require "shellwords"
- Open3.popen3(env, *cmd.shellsplit) do |stdin, stdout, stderr, wait_thr|
+ Open3.popen3(env, *cmd.shellsplit, :chdir => dir) do |stdin, stdout, stderr, wait_thr|
yield stdin, stdout, wait_thr if block_given?
stdin.close
@@ -238,7 +241,7 @@ module Spec
contents = args.shift
if contents.nil?
- File.open("Gemfile", "r", &:read)
+ File.open(bundled_app_gemfile, "r", &:read)
else
create_file("Gemfile", contents, *args)
end
@@ -248,7 +251,7 @@ module Spec
contents = args.shift
if contents.nil?
- File.open("Gemfile.lock", "r", &:read)
+ File.open(bundled_app_lock, "r", &:read)
else
create_file("Gemfile.lock", contents, *args)
end
@@ -297,7 +300,7 @@ module Spec
def with_built_bundler
with_root_gemspec do |gemspec|
- in_repo_root { gem_command! "build #{gemspec}" }
+ gem_command! "build #{gemspec}", :dir => root
end
bundler_path = root + "bundler-#{Bundler::VERSION}.gem"
@@ -357,7 +360,8 @@ module Spec
opts = gems.last.is_a?(Hash) ? gems.last : {}
path = opts.fetch(:path, system_gem_path)
if path == :bundle_path
- path = ruby!(<<-RUBY)
+ bundle_dir = opts.fetch(:bundle_dir, bundled_app)
+ path = ruby!(<<-RUBY, :dir => bundle_dir)
require "bundler"
begin
puts Bundler.bundle_path
@@ -494,7 +498,7 @@ module Spec
end
def revision_for(path)
- Dir.chdir(path) { `git rev-parse HEAD`.strip }
+ sys_exec("git rev-parse HEAD", :dir => path).strip
end
def with_read_only(pattern)
diff --git a/spec/support/path.rb b/spec/support/path.rb
index a645aa6ffd..25206c9832 100644
--- a/spec/support/path.rb
+++ b/spec/support/path.rb
@@ -48,13 +48,13 @@ module Spec
def lib_tracked_files
skip "not in git working directory" unless git_root_dir?
- @lib_tracked_files ||= ruby_core? ? `git ls-files -z -- lib/bundler lib/bundler.rb` : `git ls-files -z -- lib`
+ @lib_tracked_files ||= ruby_core? ? sys_exec("git ls-files -z -- lib/bundler lib/bundler.rb", :dir => root) : sys_exec("git ls-files -z -- lib", :dir => root)
end
def man_tracked_files
skip "not in git working directory" unless git_root_dir?
- @man_tracked_files ||= `git ls-files -z -- man`
+ @man_tracked_files ||= sys_exec("git ls-files -z -- man", :dir => root)
end
def tmp(*path)
@@ -194,14 +194,6 @@ module Spec
end
end
- def in_app_root
- Dir.chdir(bundled_app) { yield }
- end
-
- def in_app_root2
- Dir.chdir(bundled_app2) { yield }
- end
-
def in_repo_root
Dir.chdir(root) { yield }
end
diff --git a/spec/support/rubygems_version_manager.rb b/spec/support/rubygems_version_manager.rb
index 854bce890d..8eab7749f9 100644
--- a/spec/support/rubygems_version_manager.rb
+++ b/spec/support/rubygems_version_manager.rb
@@ -44,10 +44,8 @@ private
def switch_local_copy_if_needed
return unless local_copy_switch_needed?
- Dir.chdir(local_copy_path) do
- sys_exec!("git remote update")
- sys_exec!("git checkout #{target_tag} --quiet")
- end
+ sys_exec!("git remote update", :dir => local_copy_path)
+ sys_exec!("git checkout #{target_tag} --quiet", :dir => local_copy_path)
ENV["RGV"] = local_copy_path.to_s
end
@@ -65,9 +63,7 @@ private
end
def local_copy_tag
- Dir.chdir(local_copy_path) do
- sys_exec!("git rev-parse --abbrev-ref HEAD")
- end
+ sys_exec!("git rev-parse --abbrev-ref HEAD", :dir => local_copy_path)
end
def local_copy_path
diff --git a/spec/update/gemfile_spec.rb b/spec/update/gemfile_spec.rb
index 8c2bd9ccbf..4a902e59e2 100644
--- a/spec/update/gemfile_spec.rb
+++ b/spec/update/gemfile_spec.rb
@@ -38,12 +38,10 @@ RSpec.describe "bundle update" do
it "uses the gemfile while in a subdirectory" do
bundled_app("subdir").mkpath
- Dir.chdir(bundled_app("subdir")) do
- bundle! "update", :all => true
- bundle "list"
+ bundle! "update", :all => true, :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
end
diff --git a/spec/update/git_spec.rb b/spec/update/git_spec.rb
index 752033c842..58cf18bba0 100644
--- a/spec/update/git_spec.rb
+++ b/spec/update/git_spec.rb
@@ -131,10 +131,8 @@ RSpec.describe "bundle update" do
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")
end
it "it unlocks the source when submodules are added to a git source" do
@@ -259,14 +257,12 @@ RSpec.describe "bundle update" do
bundle "update --source foo"
- in_app_root do
- run <<-RUBY
- require 'foo'
- puts "WIN" if defined?(FOO_PREV_REF)
- RUBY
+ run <<-RUBY
+ require 'foo'
+ puts "WIN" if defined?(FOO_PREV_REF)
+ RUBY
- expect(out).to eq("WIN")
- end
+ expect(out).to eq("WIN")
end
it "unlocks gems that were originally pulled in by the source" do