diff --git a/lib/bundler.rb b/lib/bundler.rb index 9944ebd0513..3419e4f54e0 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -159,12 +159,13 @@ def ruby_scope def user_home @user_home ||= begin home = Bundler.rubygems.user_home + user_dirs = home ? %w[.bundle .gem].map {|path| File.join(home, path) } : [] warning = if home.nil? "Your home directory is not set." elsif !File.directory?(home) "`#{home}` is not a directory." - elsif !File.writable?(home) + elsif !File.writable?(home) && (user_dirs.any? {|path| !File.directory?(path) || !File.writable?(path) } || user_dirs.empty?) "`#{home}` is not writable." end diff --git a/spec/bundler/bundler_spec.rb b/spec/bundler/bundler_spec.rb index 131146119e1..5e0f9306bc7 100644 --- a/spec/bundler/bundler_spec.rb +++ b/spec/bundler/bundler_spec.rb @@ -199,6 +199,60 @@ allow(File).to receive(:writable?).with(path).and_return true expect(Bundler.user_home).to eq(Pathname(path)) end + + context "is not a directory" do + it "should issue a warning and return a temporary user home" do + path = "/home/oggy" + allow(Bundler.rubygems).to receive(:user_home).and_return(path) + allow(File).to receive(:directory?).with(path).and_return false + allow(Etc).to receive(:getlogin).and_return("USER") + allow(Dir).to receive(:tmpdir).and_return("/TMP") + allow(FileTest).to receive(:exist?).with("/TMP/bundler/home").and_return(true) + expect(FileUtils).to receive(:mkpath).with("/TMP/bundler/home/USER") + message = <