Don't stub all Pathnames in tests.

This commit is contained in:
Markus Reiter 2024-02-13 18:46:58 +01:00
parent 27189f4aba
commit 3472362ddd
No known key found for this signature in database
GPG Key ID: 245293B51702655B
3 changed files with 21 additions and 15 deletions

View File

@ -129,16 +129,16 @@ class Caveats
Bash completion has been installed to:
#{root_dir}/etc/bash_completion.d
EOS
when :zsh
<<~EOS
zsh #{installed.join(" and ")} have been installed to:
#{root_dir}/share/zsh/site-functions
EOS
when :fish
fish_caveats = +"fish #{installed.join(" and ")} have been installed to:"
fish_caveats << "\n #{root_dir}/share/fish/vendor_completions.d" if completion_installed
fish_caveats << "\n #{root_dir}/share/fish/vendor_functions.d" if functions_installed
fish_caveats.freeze
when :zsh
<<~EOS
zsh #{installed.join(" and ")} have been installed to:
#{root_dir}/share/zsh/site-functions
EOS
end
end

View File

@ -335,10 +335,10 @@ class Keg
def completion_installed?(shell)
dir = case shell
when :bash then path/"etc/bash_completion.d"
when :fish then path/"share/fish/vendor_completions.d"
when :zsh
dir = path/"share/zsh/site-functions"
dir if dir.directory? && dir.children.any? { |f| f.basename.to_s.start_with?("_") }
when :fish then path/"share/fish/vendor_completions.d"
end
dir&.directory? && !dir.children.empty?
end

View File

@ -301,28 +301,34 @@ describe Caveats do
let(:caveats) { described_class.new(f).caveats }
let(:path) { f.prefix.resolved_path }
let(:bash_completion_dir) { path/"etc/bash_completion.d" }
let(:fish_vendor_completions) { path/"share/fish/vendor_completions.d" }
let(:zsh_site_functions) { path/"share/zsh/site-functions" }
before do
# don't try to load/fetch gcc/glibc
allow(DevelopmentTools).to receive_messages(needs_libc_formula?: false, needs_compiler_formula?: false)
allow_any_instance_of(Pathname).to receive(:children).and_return([Pathname.new("child")])
allow_any_instance_of(Object).to receive(:which).with(any_args).and_return(Pathname.new("shell"))
allow(Utils::Shell).to receive_messages(preferred: nil, parent: nil)
end
it "gives dir where Bash completions have been installed" do
(path/"etc/bash_completion.d").mkpath
it "includes where Bash completions have been installed to" do
bash_completion_dir.mkpath
FileUtils.touch bash_completion_dir/f.name
expect(caveats).to include(HOMEBREW_PREFIX/"etc/bash_completion.d")
end
it "gives dir where zsh completions have been installed" do
(path/"share/zsh/site-functions").mkpath
expect(caveats).to include(HOMEBREW_PREFIX/"share/zsh/site-functions")
it "includes where fish completions have been installed to" do
fish_vendor_completions.mkpath
FileUtils.touch fish_vendor_completions/f.name
expect(caveats).to include(HOMEBREW_PREFIX/"share/fish/vendor_completions.d")
end
it "gives dir where fish completions have been installed" do
(path/"share/fish/vendor_completions.d").mkpath
expect(caveats).to include(HOMEBREW_PREFIX/"share/fish/vendor_completions.d")
it "includes where zsh completions have been installed to" do
zsh_site_functions.mkpath
FileUtils.touch zsh_site_functions/f.name
expect(caveats).to include(HOMEBREW_PREFIX/"share/zsh/site-functions")
end
end
end