cask: compact the code

This commit is contained in:
Kaito Udagawa 2016-11-21 04:13:29 +09:00
parent 0c22cc45e6
commit df635c8259
2 changed files with 14 additions and 14 deletions

View File

@ -54,24 +54,23 @@ module Hbc
] ]
args << "-verboseR" if Hbc.verbose args << "-verboseR" if Hbc.verbose
args << "-allowUntrusted" if pkg_install_opts :allow_untrusted 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 args << "-applyChoiceChangesXML" << choices_path if choices_path
@command.run!("/usr/sbin/installer", sudo: true, args: args, print_stdout: true) @command.run!("/usr/sbin/installer", sudo: true, args: args, print_stdout: true)
end end
end end
def with_choices_file(choices) def with_choices_file
unless choices return yield nil unless pkg_install_opts(:choices)
yield nil
return
end
begin Tempfile.open(["choices", ".xml"]) do |file|
file = Tempfile.new(["choices", ".xml"]) begin
file.write Plist::Emit.dump(choices) file.write Plist::Emit.dump(pkg_install_opts(:choices))
yield file.path file.close
ensure yield file.path
file.close(true) ensure
file.unlink
end
end end
end end
end end

View File

@ -60,8 +60,9 @@ describe Hbc::Artifact::Pkg do
</plist> </plist>
EOS EOS
file.stubs path: Pathname.new("/tmp/choices.xml") file.stubs path: Pathname.new("/tmp/choices.xml")
file.expects(:close).with true file.expects(:close)
Tempfile.expects(:new).returns file 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")]) 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")])