Skip to content
Snippets Groups Projects
Commit df635c82 authored by Kaito Udagawa's avatar Kaito Udagawa
Browse files

cask: compact the code

parent 0c22cc45
No related branches found
No related tags found
No related merge requests found
......@@ -54,24 +54,23 @@ module Hbc
]
args << "-verboseR" if Hbc.verbose
args << "-allowUntrusted" if pkg_install_opts :allow_untrusted
with_choices_file pkg_install_opts(:choices) do |choices_path|
with_choices_file do |choices_path|
args << "-applyChoiceChangesXML" << choices_path if choices_path
@command.run!("/usr/sbin/installer", sudo: true, args: args, print_stdout: true)
end
end
def with_choices_file(choices)
unless choices
yield nil
return
end
def with_choices_file
return yield nil unless pkg_install_opts(:choices)
begin
file = Tempfile.new(["choices", ".xml"])
file.write Plist::Emit.dump(choices)
yield file.path
ensure
file.close(true)
Tempfile.open(["choices", ".xml"]) do |file|
begin
file.write Plist::Emit.dump(pkg_install_opts(:choices))
file.close
yield file.path
ensure
file.unlink
end
end
end
end
......
......@@ -60,8 +60,9 @@ describe Hbc::Artifact::Pkg do
</plist>
EOS
file.stubs path: Pathname.new("/tmp/choices.xml")
file.expects(:close).with true
Tempfile.expects(:new).returns file
file.expects(:close)
file.expects(:unlink)
Tempfile.expects(:open).yields file
Hbc::FakeSystemCommand.expects_command(["/usr/bin/sudo", "-E", "--", "/usr/sbin/installer", "-pkg", @cask.staged_path.join("MyFancyPkg", "Fancy.pkg"), "-target", "/", "-applyChoiceChangesXML", @cask.staged_path.join("/tmp/choices.xml")])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment