[rubygems/rubygems] Don't break if extra calls to File.writable? happen

In https://bugs.ruby-lang.org/issues/20693, I'd like to have Dir.tmpdir
call `File.writable?` instead of `Stat#writable?`. However, that causes
this test to break in bundler because it's using RSpec to stub
`File.writable?`.

We can fix this by allowing the real `File.writable?` to be called for
all files except the directory we're trying to stub.

https://github.com/rubygems/rubygems/commit/0fa6657293
This commit is contained in:
KJ Tsanaktsidis 2024-08-23 16:21:26 +10:00 committed by git
parent 73a946c618
commit 4dae4c6858

View File

@ -267,6 +267,7 @@ RSpec.describe Bundler do
it "should issue a warning and return a temporary user home" do it "should issue a warning and return a temporary user home" do
allow(Bundler.rubygems).to receive(:user_home).and_return(path) allow(Bundler.rubygems).to receive(:user_home).and_return(path)
allow(File).to receive(:directory?).with(path).and_return true allow(File).to receive(:directory?).with(path).and_return true
allow(File).to receive(:writable?).and_call_original
allow(File).to receive(:writable?).with(path).and_return false allow(File).to receive(:writable?).with(path).and_return false
allow(File).to receive(:directory?).with(dotbundle).and_return false allow(File).to receive(:directory?).with(dotbundle).and_return false
allow(Bundler).to receive(:tmp).and_return(Pathname.new("/tmp/trulyrandom")) allow(Bundler).to receive(:tmp).and_return(Pathname.new("/tmp/trulyrandom"))