formulary: sub home placeholder in caveats

We set a placeholder for the home directory when generating
API JSON so we should substitute the actual home directory
back in when printing caveats locally. This allows people
to use `Dir.home` in caveats and have it display correctly
no matter the platform or operating system.
This commit is contained in:
apainintheneck 2023-04-22 10:06:52 -07:00
parent 664ac04782
commit d57f291a1e
2 changed files with 3 additions and 2 deletions

View File

@ -287,6 +287,7 @@ module Formulary
def caveats
self.class.instance_variable_get(:@caveats_string)
&.gsub(HOMEBREW_PREFIX_PLACEHOLDER, HOMEBREW_PREFIX)
&.gsub(HOMEBREW_HOME_PLACEHOLDER, Dir.home)
end
@tap_git_head_string = json_formula["tap_git_head"]

View File

@ -270,7 +270,7 @@ describe Formulary do
"conflicts_with" => ["conflicting_formula"],
"conflicts_with_reasons" => ["it does"],
"link_overwrite" => ["bin/abc"],
"caveats" => "example caveat string",
"caveats" => "example caveat string\n/$HOME\n$HOMEBREW_PREFIX",
"service" => {
"run" => ["$HOMEBREW_PREFIX/opt/formula_name/bin/beanstalkd", "test"],
"run_type" => "immediate",
@ -356,7 +356,7 @@ describe Formulary do
expect(formula.conflicts.map(&:reason)).to include "it does"
expect(formula.class.link_overwrite_paths).to include "bin/abc"
expect(formula.caveats).to eq "example caveat string"
expect(formula.caveats).to eq "example caveat string\n#{Dir.home}\n#{HOMEBREW_PREFIX}"
expect(formula).to be_a_service
expect(formula.service.command).to eq(["#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd", "test"])