summaryrefslogtreecommitdiff
path: root/spec/commands
diff options
context:
space:
mode:
Diffstat (limited to 'spec/commands')
-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
13 files changed, 92 insertions, 109 deletions
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