Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Update check and spec
Browse files Browse the repository at this point in the history
Signed-off-by: Zehan Zhao <[email protected]>
  • Loading branch information
allenzhao committed Aug 28, 2016
1 parent e85acda commit 6defc8d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 6 additions & 1 deletion lib/bundler/shared_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true
require "pathname"
require "rubygems"
require "etc"

require "bundler/constants"
require "bundler/rubygems_integration"
Expand Down Expand Up @@ -137,7 +138,11 @@ def print_major_deprecations!
end

def check_home_dir_permissions
raise PathError, "There was an error while trying to use your home path #{Dir.home}" unless File.writable?(Dir.home)
message = "There was error while trying to use your home path:"
home_path = File.expand_path(Dir.home(Etc.getlogin))
message += "\n * Your home directory #{home_path} is not writable" unless File.writable?(home_path)
message += "\n * Your home directory #{home_path} is not a directory" unless File.directory?(home_path)
raise PathError, message unless File.writable?(home_path) && File.directory?(home_path)
end

private
Expand Down
11 changes: 8 additions & 3 deletions spec/bundler/shared_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,14 @@ module TargetNamespace
end

describe "#check_home_dir_permissions" do
it "raises a PathError" do
allow(File).to receive(:writable?).with(Dir.home).and_return(false)
expect { subject.check_home_dir_permissions }.to raise_error(Bundler::PathError, /There was an error while trying to use your home path/)
it "raises a PathError when directory is not writable" do
allow(File).to receive(:writable?).with(File.expand_path(Dir.home(Etc.getlogin))).and_return(false)
expect { subject.check_home_dir_permissions }.to raise_error(Bundler::PathError, /is not writable/)
end

it "raise a PathError when directory doesn't exists" do
allow(File).to receive(:directory?).with(File.expand_path(Dir.home(Etc.getlogin))).and_return(false)
expect { subject.check_home_dir_permissions }.to raise_error(Bundler::PathError, /is not a directory/)
end
end
end

0 comments on commit 6defc8d

Please sign in to comment.