From 05725a9bacc56ef5ff811dabadecce016383a886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Tue, 10 Mar 2020 15:39:37 +0100 Subject: Use thread safe method to find cwd And stub that in plugin's specs. --- lib/bundler/shared_helpers.rb | 2 +- spec/bundler/plugin/index_spec.rb | 2 +- spec/bundler/plugin_spec.rb | 5 +++-- spec/plugins/install_spec.rb | 4 ++-- spec/plugins/source_spec.rb | 6 +++--- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index 960a935cd3..327de0d835 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -23,7 +23,7 @@ module Bundler def config_root bundle_dir = default_bundle_dir - bundle_dir ? bundle_dir.parent : Pathname.pwd + bundle_dir ? bundle_dir.parent : pwd end def default_gemfile diff --git a/spec/bundler/plugin/index_spec.rb b/spec/bundler/plugin/index_spec.rb index 925dc558ac..ae64756298 100644 --- a/spec/bundler/plugin/index_spec.rb +++ b/spec/bundler/plugin/index_spec.rb @@ -4,7 +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) + allow(Bundler::SharedHelpers).to receive(:pwd).and_return(bundled_app) gemfile "" path = lib_path(plugin_name) index.register_plugin("new-plugin", path.to_s, [path.join("lib").to_s], commands, sources, hooks) diff --git a/spec/bundler/plugin_spec.rb b/spec/bundler/plugin_spec.rb index 8c95723bcc..9341b4ada3 100644 --- a/spec/bundler/plugin_spec.rb +++ b/spec/bundler/plugin_spec.rb @@ -237,7 +237,8 @@ RSpec.describe Bundler::Plugin do describe "#root" do context "in app dir" do before do - allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) + allow(Bundler::SharedHelpers).to receive(:pwd).and_return(bundled_app) + FileUtils.touch(bundled_app.join("Gemfile")) end it "returns plugin dir in app .bundle path" do @@ -247,7 +248,7 @@ RSpec.describe Bundler::Plugin do context "outside app dir" do before do - allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(nil) + allow(Bundler::SharedHelpers).to receive(:pwd).and_return(root) end it "returns plugin dir in global bundle path" do diff --git a/spec/plugins/install_spec.rb b/spec/plugins/install_spec.rb index 663363ca21..804a3828e5 100644 --- a/spec/plugins/install_spec.rb +++ b/spec/plugins/install_spec.rb @@ -156,7 +156,7 @@ RSpec.describe "bundler plugin install" do context "Gemfile eval" do before do - allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) + allow(Bundler::SharedHelpers).to receive(:pwd).and_return(bundled_app) end it "installs plugins listed in gemfile" do @@ -249,7 +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) + allow(Bundler::SharedHelpers).to receive(:pwd).and_return(bundled_app) gemfile "" bundle "plugin install foo --source #{file_uri_for(gem_repo2)}" diff --git a/spec/plugins/source_spec.rb b/spec/plugins/source_spec.rb index 14643e5c81..921ce738c5 100644 --- a/spec/plugins/source_spec.rb +++ b/spec/plugins/source_spec.rb @@ -21,7 +21,7 @@ RSpec.describe "bundler source plugin" do end G - allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) + allow(Bundler::SharedHelpers).to receive(:pwd).and_return(bundled_app) plugin_should_be_installed("bundler-source-psource") end @@ -76,7 +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) + allow(Bundler::SharedHelpers).to receive(:pwd).and_return(bundled_app) plugin_should_be_installed("another-psource") end @@ -102,7 +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) + allow(Bundler::SharedHelpers).to receive(:pwd).and_return(bundled_app) plugin_should_be_installed("bundler-source-psource") end end -- cgit v1.2.1