aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorKaito Udagawa2016-11-19 13:05:55 +0900
committerKaito Udagawa2016-11-19 14:52:38 +0900
commit28072021031836937a01e9fd995b03995fe49443 (patch)
tree316860378cfa0c5a5f5936d4b1f592d458a22d8a /Library
parentf4a3bc100b4b98a3d06222c15934abb36bf16594 (diff)
downloadbrew-28072021031836937a01e9fd995b03995fe49443.tar.bz2
cask: use Tempfile and some style fixes
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cask/lib/hbc/artifact/pkg.rb13
-rw-r--r--Library/Homebrew/cask/test/cask/artifact/pkg_test.rb35
2 files changed, 23 insertions, 25 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb b/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb
index 2f34814ab..cede9f4d5 100644
--- a/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb
+++ b/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb
@@ -55,19 +55,16 @@ module Hbc
args << "-verboseR" if Hbc.verbose
args << "-allowUntrusted" if pkg_install_opts :allow_untrusted
if pkg_install_opts :choices
- args << "-applyChoiceChangesXML"
- args << choices_xml
+ choices_file = choices_xml
+ args << "-applyChoiceChangesXML" << choices_file.path
end
@command.run!("/usr/sbin/installer", sudo: true, args: args, print_stdout: true)
end
def choices_xml
- path = @cask.staged_path.join("Choices.xml")
- unless File.exist? path
- choices = pkg_install_opts :choices
- IO.write path, Plist::Emit.dump(choices)
- end
- path
+ file = Tempfile.open(["", ".xml"])
+ file.write Plist::Emit.dump(pkg_install_opts(:choices))
+ file
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 8ee4e0a3c..cb30c4a0a 100644
--- a/Library/Homebrew/cask/test/cask/artifact/pkg_test.rb
+++ b/Library/Homebrew/cask/test/cask/artifact/pkg_test.rb
@@ -40,31 +40,32 @@ describe Hbc::Artifact::Pkg do
end
it "passes the choice changes xml to the system installer" do
- pkg = Hbc::Artifact::Pkg.new(@cask,
- command: Hbc::FakeSystemCommand)
-
- 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("Choices.xml")])
+ pkg = Hbc::Artifact::Pkg.new(@cask, command: Hbc::FakeSystemCommand)
- shutup do
- pkg.install_phase
- end
-
- IO.read(@cask.staged_path.join("Choices.xml")).must_equal <<-EOS.undent
+ file = mock
+ file.expects(:write).with <<-EOS.undent
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
- <dict>
- <key>attributeSetting</key>
- <integer>1</integer>
- <key>choiceAttribute</key>
- <string>selected</string>
- <key>choiceIdentifier</key>
- <string>choice1</string>
- </dict>
+ \t<dict>
+ \t\t<key>attributeSetting</key>
+ \t\t<integer>1</integer>
+ \t\t<key>choiceAttribute</key>
+ \t\t<string>selected</string>
+ \t\t<key>choiceIdentifier</key>
+ \t\t<string>choice1</string>
+ \t</dict>
</array>
</plist>
EOS
+ file.stubs path: Pathname.new("/tmp/choices.xml")
+ Tempfile.expects(:open).returns(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")])
+
+ shutup do
+ pkg.install_phase
+ end
end
end
end