diff options
author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2019-04-26 11:24:26 +0200 |
---|---|---|
committer | David RodrÃguez <deivid.rodriguez@riseup.net> | 2019-05-27 13:03:20 +0200 |
commit | e3ade9ee5eaa512b81f3aa272dc7fa71c307c4ae (patch) | |
tree | ba4269ab0206142e3ccf93f47fc73ef1ed9cf8b0 | |
parent | ee866a7df9efc18d72bd305d43e072cc54d45733 (diff) | |
download | bundler-e3ade9ee5eaa512b81f3aa272dc7fa71c307c4ae.tar.gz |
Fix another flaky
When `requires_sudo` would not properly reset state.
-rw-r--r-- | spec/bundler/bundler_spec.rb | 73 |
1 files changed, 35 insertions, 38 deletions
diff --git a/spec/bundler/bundler_spec.rb b/spec/bundler/bundler_spec.rb index 9b772bffef..f74c1780bd 100644 --- a/spec/bundler/bundler_spec.rb +++ b/spec/bundler/bundler_spec.rb @@ -370,54 +370,51 @@ EOF it { should be true } end 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") - FileUtils.mkdir_p("tmp/vendor/bin_dir") - end - after do - FileUtils.rm_rf("tmp/vendor/bundle") - FileUtils.rm_rf("tmp/vendor/bin_dir") - 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 + context "path writability" do before do - FileUtils.touch("tmp/vendor/bundle/unwritable1.txt") - FileUtils.touch("tmp/vendor/bundle/unwritable2.txt") - FileUtils.touch("tmp/vendor/bin_dir/unwritable3.txt") - FileUtils.chmod(0o400, "tmp/vendor/bundle/unwritable1.txt") - FileUtils.chmod(0o400, "tmp/vendor/bundle/unwritable2.txt") - FileUtils.chmod(0o400, "tmp/vendor/bin_dir/unwritable3.txt") + FileUtils.mkdir_p("tmp/vendor/bundle") + FileUtils.mkdir_p("tmp/vendor/bin_dir") + end + after do + FileUtils.rm_rf("tmp/vendor/bundle") + FileUtils.rm_rf("tmp/vendor/bin_dir") end - it "should return true and display warn message" do - allow(Bundler).to receive(:bundle_path).and_return(Pathname("tmp/vendor/bundle")) - bin_dir = Pathname("tmp/vendor/bin_dir/") + 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.touch("tmp/vendor/bin_dir/unwritable3.txt") + FileUtils.chmod(0o400, "tmp/vendor/bundle/unwritable1.txt") + FileUtils.chmod(0o400, "tmp/vendor/bundle/unwritable2.txt") + FileUtils.chmod(0o400, "tmp/vendor/bin_dir/unwritable3.txt") + end + it "should return true and display warn message" do + allow(Bundler).to receive(:bundle_path).and_return(Pathname("tmp/vendor/bundle")) + bin_dir = Pathname("tmp/vendor/bin_dir/") - # allow File#writable? to be called with args other than the stubbed on below - allow(File).to receive(:writable?).and_call_original + # allow File#writable? to be called with args other than the stubbed on below + allow(File).to receive(:writable?).and_call_original - # fake make the directory unwritable - allow(File).to receive(:writable?).with(bin_dir).and_return(false) - allow(Bundler).to receive(:system_bindir).and_return(Pathname("tmp/vendor/bin_dir/")) - message = <<-MESSAGE.chomp + # fake make the directory unwritable + allow(File).to receive(:writable?).with(bin_dir).and_return(false) + allow(Bundler).to receive(:system_bindir).and_return(Pathname("tmp/vendor/bin_dir/")) + message = <<-MESSAGE.chomp Following files may not be writable, so sudo is needed: tmp/vendor/bin_dir/ 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) + expect(Bundler.ui).to receive(:warn).with(message) + expect(Bundler.requires_sudo?).to eq(true) + end end end end |