diff options
author | Kenji Okimoto <okimoto@clear-code.com> | 2018-03-06 15:40:33 +0900 |
---|---|---|
committer | Kenji Okimoto <okimoto@clear-code.com> | 2018-04-23 09:21:08 +0900 |
commit | 8695c3d56918f9f2271709ff079113db1151fa46 (patch) | |
tree | 69423960f857c44aab5b7f78e4182bb94472f3e7 /spec/bundler/bundler_spec.rb | |
parent | 0ac78cf19badcefd4883383d9bf340ae78442d4a (diff) | |
download | bundler-8695c3d56918f9f2271709ff079113db1151fa46.tar.gz |
Add test for Bundler.requires_sudo?
Diffstat (limited to 'spec/bundler/bundler_spec.rb')
-rw-r--r-- | spec/bundler/bundler_spec.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/spec/bundler/bundler_spec.rb b/spec/bundler/bundler_spec.rb index 131146119e..6bfddedf33 100644 --- a/spec/bundler/bundler_spec.rb +++ b/spec/bundler/bundler_spec.rb @@ -295,6 +295,37 @@ 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") + Bundler.remove_instance_variable(:@requires_sudo_ran) + Bundler.remove_instance_variable(:@requires_sudo) + 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/unwritable.txt") + FileUtils.chmod(0400, "tmp/vendor/bundle/unwritable.txt") + end + it "should return true and display warn message" do + allow(Bundler).to receive(:bundle_path).and_return(Pathname("tmp/vendor/bundle")) + message = "Following files may not be writable, so sudo is needed: tmp/vendor/bundle/unwritable.txt" + 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"]) } |