Skip to content

Commit

Permalink
Add test for Cask::Utils::gain_permissions_mkpath.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed May 13, 2023
1 parent 1d4192a commit a3542e0
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Library/Homebrew/test/cask/utils_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

describe Cask::Utils do
let(:command) { NeverSudoSystemCommand }

describe "::gain_permissions_mkpath" do
let(:dir) { mktmpdir }
let(:path) { dir/"a/b/c" }

it "creates a directory" do
expect(path).not_to exist
described_class.gain_permissions_mkpath path, command: command
expect(path).to be_a_directory
described_class.gain_permissions_mkpath path, command: command
expect(path).to be_a_directory
end

context "when parent directory is not writable" do
it "creates a directory with `sudo`" do
FileUtils.chmod "-w", dir
expect(dir).not_to be_writable

expect(command).to receive(:run!).exactly(:once).and_wrap_original do |original, *args, **options|
FileUtils.chmod "+w", dir
original.call(*args, **options)
FileUtils.chmod "-w", dir
end

expect(path).not_to exist
described_class.gain_permissions_mkpath path, command: command
expect(path).to be_a_directory
described_class.gain_permissions_mkpath path, command: command
expect(path).to be_a_directory

expect(dir).not_to be_writable
FileUtils.chmod "+w", dir
end
end
end
end

0 comments on commit a3542e0

Please sign in to comment.