From e5e8f545b72f4a8849a915dfba1acce5f39ef3ab Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 8 Feb 2017 14:37:40 +0100 Subject: [PATCH] Convert Artifact::Pkg test to spec. --- .../cask/spec/cask/artifact/pkg_spec.rb | 71 +++++++++++++++++++ .../cask/test/cask/artifact/pkg_test.rb | 64 ----------------- 2 files changed, 71 insertions(+), 64 deletions(-) create mode 100644 Library/Homebrew/cask/spec/cask/artifact/pkg_spec.rb delete mode 100644 Library/Homebrew/cask/test/cask/artifact/pkg_test.rb diff --git a/Library/Homebrew/cask/spec/cask/artifact/pkg_spec.rb b/Library/Homebrew/cask/spec/cask/artifact/pkg_spec.rb new file mode 100644 index 0000000000..d4d69ea663 --- /dev/null +++ b/Library/Homebrew/cask/spec/cask/artifact/pkg_spec.rb @@ -0,0 +1,71 @@ +require "spec_helper" + +describe Hbc::Artifact::Pkg 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 + shutup do + InstallHelper.install_without_artifacts(cask) + end + end + + describe "install_phase" do + it "runs the system installer on the specified pkgs" do + pkg = Hbc::Artifact::Pkg.new(cask, command: fake_system_command) + + 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 + ) + + shutup do + pkg.install_phase + end + 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 = Hbc::Artifact::Pkg.new(cask, command: fake_system_command) + + file = double(path: Pathname.new("/tmp/choices.xml")) + + expect(file).to receive(:write).with(<<-EOS.undent) + + + + + \t + \t\tattributeSetting + \t\t1 + \t\tchoiceAttribute + \t\tselected + \t\tchoiceIdentifier + \t\tchoice1 + \t + + + 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 + ) + + shutup do + pkg.install_phase + 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 deleted file mode 100644 index b054290ce3..0000000000 --- a/Library/Homebrew/cask/test/cask/artifact/pkg_test.rb +++ /dev/null @@ -1,64 +0,0 @@ -require "test_helper" - -describe Hbc::Artifact::Pkg do - before do - @cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-installable.rb") - shutup do - TestHelper.install_without_artifacts(@cask) - end - end - - describe "install_phase" do - it "runs the system installer on the specified pkgs" 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", "/"]) - - shutup do - pkg.install_phase - end - end - end - - describe "choices" do - before do - @cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-choices.rb") - shutup do - TestHelper.install_without_artifacts(@cask) - end - end - - it "passes the choice changes xml to the system installer" do - pkg = Hbc::Artifact::Pkg.new(@cask, command: Hbc::FakeSystemCommand) - - file = mock - file.expects(:write).with <<-EOS.undent - - - - - \t - \t\tattributeSetting - \t\t1 - \t\tchoiceAttribute - \t\tselected - \t\tchoiceIdentifier - \t\tchoice1 - \t - - - EOS - file.stubs path: Pathname.new("/tmp/choices.xml") - 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")]) - - shutup do - pkg.install_phase - end - end - end -end