diff options
| author | Kaito Udagawa | 2016-11-21 04:13:29 +0900 |
|---|---|---|
| committer | Kaito Udagawa | 2016-11-21 04:13:29 +0900 |
| commit | df635c8259dffca891424352765088a3b88a87d2 (patch) | |
| tree | a07dcf3683057ed8256a94677b736765e86b722d | |
| parent | 0c22cc45e6fe7da64f037fc2fc1556c0e967d55f (diff) | |
| download | brew-df635c8259dffca891424352765088a3b88a87d2.tar.bz2 | |
cask: compact the code
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/artifact/pkg.rb | 23 | ||||
| -rw-r--r-- | Library/Homebrew/cask/test/cask/artifact/pkg_test.rb | 5 |
2 files changed, 14 insertions, 14 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb b/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb index fffb10cae..0569d2a86 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb @@ -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 diff --git a/Library/Homebrew/cask/test/cask/artifact/pkg_test.rb b/Library/Homebrew/cask/test/cask/artifact/pkg_test.rb index 6e10177d1..3ed427763 100644 --- a/Library/Homebrew/cask/test/cask/artifact/pkg_test.rb +++ b/Library/Homebrew/cask/test/cask/artifact/pkg_test.rb @@ -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")]) |
