From 1647b9d97a744de066ff87cccf59fbb6fe278680 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Thu, 9 Feb 2017 03:26:28 +0100 Subject: Convert two apps correct test to spec. --- .../spec/cask/artifact/two_apps_correct_spec.rb | 93 +++++++++++++++++++++ .../test/cask/artifact/two_apps_correct_test.rb | 97 ---------------------- 2 files changed, 93 insertions(+), 97 deletions(-) create mode 100644 Library/Homebrew/cask/spec/cask/artifact/two_apps_correct_spec.rb delete mode 100644 Library/Homebrew/cask/test/cask/artifact/two_apps_correct_test.rb (limited to 'Library/Homebrew') diff --git a/Library/Homebrew/cask/spec/cask/artifact/two_apps_correct_spec.rb b/Library/Homebrew/cask/spec/cask/artifact/two_apps_correct_spec.rb new file mode 100644 index 000000000..7fa44dbce --- /dev/null +++ b/Library/Homebrew/cask/spec/cask/artifact/two_apps_correct_spec.rb @@ -0,0 +1,93 @@ +require "spec_helper" + +describe Hbc::Artifact::App do + describe "multiple apps" do + let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-two-apps-correct.rb") } + + let(:install_phase) { + -> { Hbc::Artifact::App.new(cask).install_phase } + } + + let(:source_path_mini) { cask.staged_path.join("Caffeine Mini.app") } + let(:target_path_mini) { Hbc.appdir.join("Caffeine Mini.app") } + + let(:source_path_pro) { cask.staged_path.join("Caffeine Pro.app") } + let(:target_path_pro) { Hbc.appdir.join("Caffeine Pro.app") } + + before(:each) do + InstallHelper.install_without_artifacts(cask) + end + + it "installs both apps using the proper target directory" do + shutup do + install_phase.call + end + + expect(target_path_mini).to be_a_directory + expect(source_path_mini).not_to exist + + expect(target_path_pro).to be_a_directory + expect(source_path_pro).not_to exist + end + + describe "when apps are in a subdirectory" do + let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-two-apps-subdir.rb") } + + it "installs both apps using the proper target directory" do + shutup do + install_phase.call + end + + expect(target_path_mini).to be_a_directory + expect(source_path_mini).not_to exist + + expect(target_path_pro).to be_a_directory + expect(source_path_pro).not_to exist + end + end + + it "only uses apps when they are specified" do + FileUtils.cp_r source_path_mini, source_path_mini.sub("Caffeine Mini.app", "Caffeine Deluxe.app") + + shutup do + install_phase.call + end + + expect(target_path_mini).to be_a_directory + expect(source_path_mini).not_to exist + + expect(Hbc.appdir.join("Caffeine Deluxe.app")).not_to exist + expect(cask.staged_path.join("Caffeine Deluxe.app")).to exist + end + + describe "avoids clobbering an existing app" do + it "when the first app of two already exists" do + target_path_mini.mkpath + + expect { + expect(install_phase).to output(<<-EOS.undent).to_stdout + ==> Moving App 'Caffeine Pro.app' to '#{target_path_pro}' + EOS + }.to raise_error(Hbc::CaskError, "It seems there is already an App at '#{target_path_mini}'.") + + expect(source_path_mini).to be_a_directory + expect(target_path_mini).to be_a_directory + expect(File.identical?(source_path_mini, target_path_mini)).to be false + end + + it "when the second app of two already exists" do + target_path_pro.mkpath + + expect { + expect(install_phase).to output(<<-EOS.undent).to_stdout + ==> Moving App 'Caffeine Mini.app' to '#{target_path_mini}' + EOS + }.to raise_error(Hbc::CaskError, "It seems there is already an App at '#{target_path_pro}'.") + + expect(source_path_pro).to be_a_directory + expect(target_path_pro).to be_a_directory + expect(File.identical?(source_path_pro, target_path_pro)).to be false + end + end + end +end diff --git a/Library/Homebrew/cask/test/cask/artifact/two_apps_correct_test.rb b/Library/Homebrew/cask/test/cask/artifact/two_apps_correct_test.rb deleted file mode 100644 index c6ad9db47..000000000 --- a/Library/Homebrew/cask/test/cask/artifact/two_apps_correct_test.rb +++ /dev/null @@ -1,97 +0,0 @@ -require "test_helper" - -describe Hbc::Artifact::App do - describe "multiple apps" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-two-apps-correct.rb") } - - let(:install_phase) { - -> { Hbc::Artifact::App.new(cask).install_phase } - } - - let(:source_path_mini) { cask.staged_path.join("Caffeine Mini.app") } - let(:target_path_mini) { Hbc.appdir.join("Caffeine Mini.app") } - - let(:source_path_pro) { cask.staged_path.join("Caffeine Pro.app") } - let(:target_path_pro) { Hbc.appdir.join("Caffeine Pro.app") } - - before do - TestHelper.install_without_artifacts(cask) - end - - it "installs both apps using the proper target directory" do - shutup do - install_phase.call - end - - target_path_mini.must_be :directory? - source_path_mini.wont_be :exist? - - target_path_pro.must_be :directory? - source_path_pro.wont_be :exist? - end - - describe "when apps are in a subdirectory" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-two-apps-subdir.rb") } - - it "installs both apps using the proper target directory" do - shutup do - install_phase.call - end - - target_path_mini.must_be :directory? - source_path_mini.wont_be :exist? - - target_path_pro.must_be :directory? - source_path_pro.wont_be :exist? - end - end - - it "only uses apps when they are specified" do - FileUtils.cp_r source_path_mini, source_path_mini.sub("Caffeine Mini.app", "Caffeine Deluxe.app") - - shutup do - install_phase.call - end - - target_path_mini.must_be :directory? - source_path_mini.wont_be :exist? - - Hbc.appdir.join("Caffeine Deluxe.app").wont_be :exist? - cask.staged_path.join("Caffeine Deluxe.app").must_be :exist? - end - - describe "avoids clobbering an existing app" do - it "when the first app of two already exists" do - target_path_mini.mkpath - - err = assert_raises Hbc::CaskError do - install_phase.must_output <<-EOS.undent - ==> Moving App 'Caffeine Pro.app' to '#{target_path_pro}' - EOS - end - - err.message.must_equal("It seems there is already an App at '#{target_path_mini}'.") - - source_path_mini.must_be :directory? - target_path_mini.must_be :directory? - File.identical?(source_path_mini, target_path_mini).must_equal false - end - - it "when the second app of two already exists" do - target_path_pro.mkpath - - err = assert_raises Hbc::CaskError do - install_phase.must_output <<-EOS.undent - ==> Moving App 'Caffeine Mini.app' to '#{target_path_mini}' - EOS - end - - err.message.must_equal("It seems there is already an App at '#{target_path_pro}'.") - - source_path_pro.must_be :directory? - target_path_pro.must_be :directory? - File.identical?(source_path_pro, target_path_pro).must_equal false - end - end - end -end -- cgit v1.2.3