aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/cask/artifact/pkg_spec.rb
blob: c6a45c49aba02cb5e2e5b5a4b08961da49831de2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
describe Hbc::Artifact::Pkg, :cask do
  let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-installable.rb") }
  let(:fake_system_command) { class_double(Hbc::SystemCommand) }

  before(:each) do
    InstallHelper.install_without_artifacts(cask)
  end

  describe "install_phase" do
    it "runs the system installer on the specified pkgs" do
      pkg = described_class.for_cask(cask).first

      expect(fake_system_command).to receive(:run!).with(
        "/usr/sbin/installer",
        args: ["-pkg", cask.staged_path.join("MyFancyPkg", "Fancy.pkg"), "-target", "/"],
        sudo: true,
        print_stdout: true,
      )

      pkg.install_phase(command: fake_system_command)
    end
  end

  describe "choices" do
    let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-choices.rb") }

    it "passes the choice changes xml to the system installer" do
      pkg = described_class.for_cask(cask).first

      file = double(path: Pathname.new("/tmp/choices.xml"))

      expect(file).to receive(: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>
        \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

      expect(file).to receive(:close)
      expect(file).to receive(:unlink)
      expect(Tempfile).to receive(:open).and_yield(file)

      expect(fake_system_command).to receive(:run!).with(
        "/usr/sbin/installer",
        args: ["-pkg", cask.staged_path.join("MyFancyPkg", "Fancy.pkg"), "-target", "/", "-applyChoiceChangesXML", cask.staged_path.join("/tmp/choices.xml")],
        sudo: true,
        print_stdout: true,
      )

      pkg.install_phase(command: fake_system_command)
    end
  end
end