diff --git a/lib/bundler.rb b/lib/bundler.rb index 9944ebd0513..8ed5b0861f0 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 + bundle_home = home ? File.join(home, ".bundle") : nil 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) && (!File.directory?(bundle_home) || !File.writable?(bundle_home)) "`#{home}` is not writable." end diff --git a/spec/bundler/bundler_spec.rb b/spec/bundler/bundler_spec.rb index 131146119e1..c483701d6e8 100644 --- a/spec/bundler/bundler_spec.rb +++ b/spec/bundler/bundler_spec.rb @@ -199,6 +199,57 @@ 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 = <