diff options
author | Bundlerbot <bot@bundler.io> | 2018-09-24 12:55:37 +0000 |
---|---|---|
committer | Bundlerbot <bot@bundler.io> | 2018-09-24 12:55:37 +0000 |
commit | 1bd53e3d930e4f915db5536c68b1ed7282304045 (patch) | |
tree | d58f352f456ca3a073f4f385cdcea5856d090727 /spec | |
parent | 5dc07bdeb6e5a665cf6bc797a1e6a1ddff17a524 (diff) | |
parent | 025110cef77d36ef85e01f8b03b26a4f1d2790b5 (diff) | |
download | bundler-1bd53e3d930e4f915db5536c68b1ed7282304045.tar.gz |
Merge #6316
6316: Display reason to require sudo r=colby-swandale a=okkez
This is useful for non-interactive installation with bundler.
### What was the end-user problem that led to this PR?
https://github.com/treasure-data/omnibus-td-agent/issues/166
I could not notice that bundler needs sudo privilege from logs.
So I checked bundler code.
### What was your diagnosis of the problem?
Bundler does not show the reason to need sudo privilege.
### What is your fix for the problem, implemented in this PR?
Display reason to require sudo.
### Why did you choose this fix out of the possible options?
If bundler displays reason to require sudo, we can notice permission problems as soon as possible.
Co-authored-by: Kenji Okimoto <okimoto@clear-code.com>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/bundler/bundler_spec.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/spec/bundler/bundler_spec.rb b/spec/bundler/bundler_spec.rb index 06435b9888..4759005c0c 100644 --- a/spec/bundler/bundler_spec.rb +++ b/spec/bundler/bundler_spec.rb @@ -374,6 +374,49 @@ EOF end end + describe "#requires_sudo?" do + before do + allow(Bundler).to receive(:which).with("sudo").and_return("/usr/bin/sudo") + FileUtils.mkdir_p("tmp/vendor/bundle") + end + after do + FileUtils.rm_rf("tmp/vendor/bundle") + if Bundler.respond_to?(:remove_instance_variable) + Bundler.remove_instance_variable(:@requires_sudo_ran) + Bundler.remove_instance_variable(:@requires_sudo) + else + # TODO: Remove these code when Bundler drops Ruby 1.8.7 support + Bundler.send(:remove_instance_variable, :@requires_sudo_ran) + Bundler.send(:remove_instance_variable, :@requires_sudo) + end + end + context "writable paths" do + it "should return false and display nothing" do + allow(Bundler).to receive(:bundle_path).and_return(Pathname("tmp/vendor/bundle")) + expect(Bundler.ui).to_not receive(:warn) + expect(Bundler.requires_sudo?).to eq(false) + end + end + context "unwritable paths" do + before do + FileUtils.touch("tmp/vendor/bundle/unwritable1.txt") + FileUtils.touch("tmp/vendor/bundle/unwritable2.txt") + FileUtils.chmod(0o400, "tmp/vendor/bundle/unwritable1.txt") + FileUtils.chmod(0o400, "tmp/vendor/bundle/unwritable2.txt") + end + it "should return true and display warn message" do + allow(Bundler).to receive(:bundle_path).and_return(Pathname("tmp/vendor/bundle")) + message = <<-MESSAGE.chomp +Following files may not be writable, so sudo is needed: + tmp/vendor/bundle/unwritable1.txt + tmp/vendor/bundle/unwritable2.txt +MESSAGE + expect(Bundler.ui).to receive(:warn).with(message) + expect(Bundler.requires_sudo?).to eq(true) + end + end + end + context "user cache dir" do let(:home_path) { Pathname.new(ENV["HOME"]) } |