diff --git a/Library/Homebrew/cask/test/cask/installer_test.rb b/Library/Homebrew/cask/test/cask/installer_test.rb index b26c288478da82328c54e4af140621e04ccb1ad4..17629dce2eeedb9d40be10b429e12f262c73debb 100644 --- a/Library/Homebrew/cask/test/cask/installer_test.rb +++ b/Library/Homebrew/cask/test/cask/installer_test.rb @@ -13,10 +13,8 @@ describe Hbc::Installer do Hbc::Installer.new(caffeine).install end - dest_path = Hbc.caskroom.join("local-caffeine", caffeine.version) - dest_path.must_be :directory? - application = Hbc.appdir.join("Caffeine.app") - application.must_be :directory? + expect(Hbc.caskroom.join("local-caffeine", caffeine.version)).must_be :directory? + expect(Hbc.appdir.join("Caffeine.app")).must_be :directory? end it "works with dmg-based Casks" do @@ -26,10 +24,8 @@ describe Hbc::Installer do Hbc::Installer.new(asset).install end - dest_path = Hbc.caskroom.join("container-dmg", asset.version) - dest_path.must_be :directory? - file = Hbc.appdir.join("container") - file.must_be :file? + expect(Hbc.caskroom.join("container-dmg", asset.version)).must_be :directory? + expect(Hbc.appdir.join("container")).must_be :file? end it "works with tar-gz-based Casks" do @@ -39,10 +35,8 @@ describe Hbc::Installer do Hbc::Installer.new(asset).install end - dest_path = Hbc.caskroom.join("container-tar-gz", asset.version) - dest_path.must_be :directory? - application = Hbc.appdir.join("container") - application.must_be :file? + expect(Hbc.caskroom.join("container-tar-gz", asset.version)).must_be :directory? + expect(Hbc.appdir.join("container")).must_be :file? end it "works with cab-based Casks" do @@ -55,10 +49,8 @@ describe Hbc::Installer do end end - dest_path = Hbc.caskroom.join("container-cab", asset.version) - dest_path.must_be :directory? - application = Hbc.appdir.join("container") - application.must_be :file? + expect(Hbc.caskroom.join("container-cab", asset.version)).must_be :directory? + expect(Hbc.appdir.join("container")).must_be :file? end it "works with Adobe AIR-based Casks" do @@ -69,10 +61,8 @@ describe Hbc::Installer do Hbc::Installer.new(asset).install end - dest_path = Hbc.caskroom.join("container-air", asset.version) - dest_path.must_be :directory? - application = Hbc.appdir.join("container.app") - application.must_be :directory? + expect(Hbc.caskroom.join("container-air", asset.version)).must_be :directory? + expect(Hbc.appdir.join("container.app")).must_be :directory? end it "works with 7z-based Casks" do @@ -85,10 +75,8 @@ describe Hbc::Installer do end end - dest_path = Hbc.caskroom.join("container-7z", asset.version) - dest_path.must_be :directory? - file = Hbc.appdir.join("container") - file.must_be :file? + expect(Hbc.caskroom.join("container-7z", asset.version)).must_be :directory? + expect(Hbc.appdir.join("container")).must_be :file? end it "works with xar-based Casks" do @@ -98,10 +86,8 @@ describe Hbc::Installer do Hbc::Installer.new(asset).install end - dest_path = Hbc.caskroom.join("container-xar", asset.version) - dest_path.must_be :directory? - file = Hbc.appdir.join("container") - file.must_be :file? + expect(Hbc.caskroom.join("container-xar", asset.version)).must_be :directory? + expect(Hbc.appdir.join("container")).must_be :file? end it "works with Stuffit-based Casks" do @@ -114,10 +100,8 @@ describe Hbc::Installer do end end - dest_path = Hbc.caskroom.join("container-sit", asset.version) - dest_path.must_be :directory? - application = Hbc.appdir.join("container") - application.must_be :file? + expect(Hbc.caskroom.join("container-sit", asset.version)).must_be :directory? + expect(Hbc.appdir.join("container")).must_be :file? end it "works with RAR-based Casks" do @@ -130,10 +114,8 @@ describe Hbc::Installer do end end - dest_path = Hbc.caskroom.join("container-rar", asset.version) - dest_path.must_be :directory? - application = Hbc.appdir.join("container") - application.must_be :file? + expect(Hbc.caskroom.join("container-rar", asset.version)).must_be :directory? + expect(Hbc.appdir.join("container")).must_be :file? end it "works with pure bzip2-based Casks" do @@ -143,10 +125,8 @@ describe Hbc::Installer do Hbc::Installer.new(asset).install end - dest_path = Hbc.caskroom.join("container-bzip2", asset.version) - dest_path.must_be :directory? - file = Hbc.appdir.join("container-bzip2--#{asset.version}") - file.must_be :file? + expect(Hbc.caskroom.join("container-bzip2", asset.version)).must_be :directory? + expect(Hbc.appdir.join("container-bzip2--#{asset.version}")).must_be :file? end it "works with pure gzip-based Casks" do @@ -156,10 +136,8 @@ describe Hbc::Installer do Hbc::Installer.new(asset).install end - dest_path = Hbc.caskroom.join("container-gzip", asset.version) - dest_path.must_be :directory? - file = Hbc.appdir.join("container") - file.must_be :file? + expect(Hbc.caskroom.join("container-gzip", asset.version)).must_be :directory? + expect(Hbc.appdir.join("container")).must_be :file? end it "works with pure xz-based Casks" do @@ -172,10 +150,8 @@ describe Hbc::Installer do end end - dest_path = Hbc.caskroom.join("container-xz", asset.version) - dest_path.must_be :directory? - file = Hbc.appdir.join("container-xz--#{asset.version}") - file.must_be :file? + expect(Hbc.caskroom.join("container-xz", asset.version)).must_be :directory? + expect(Hbc.appdir.join("container-xz--#{asset.version}")).must_be :file? end it "works with lzma-based Casks" do @@ -188,15 +164,13 @@ describe Hbc::Installer do end end - dest_path = Hbc.caskroom.join("container-lzma", asset.version) - dest_path.must_be :directory? - file = Hbc.appdir.join("container-lzma--#{asset.version}") - file.must_be :file? + expect(Hbc.caskroom.join("container-lzma", asset.version)).must_be :directory? + expect(Hbc.appdir.join("container-lzma--#{asset.version}")).must_be :file? end it "blows up on a bad checksum" do bad_checksum = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/bad-checksum.rb") - lambda { + expect { shutup do Hbc::Installer.new(bad_checksum).install end @@ -205,7 +179,7 @@ describe Hbc::Installer do it "blows up on a missing checksum" do missing_checksum = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/missing-checksum.rb") - lambda { + expect { shutup do Hbc::Installer.new(missing_checksum).install end @@ -219,12 +193,12 @@ describe Hbc::Installer do Hbc::Installer.new(no_checksum).install end - no_checksum.must_be :installed? + expect(no_checksum).must_be :installed? end it "fails to install if sha256 :no_check is used with --require-sha" do no_checksum = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/no-checksum.rb") - lambda { + expect { Hbc::Installer.new(no_checksum, require_sha: true).install }.must_raise(Hbc::CaskNoShasumError) end @@ -236,23 +210,27 @@ describe Hbc::Installer do Hbc::Installer.new(no_checksum, require_sha: true, force: true).install end - no_checksum.must_be :installed? + expect(no_checksum).must_be :installed? end it "prints caveats if they're present" do with_caveats = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-caveats.rb") - lambda { + + expect { Hbc::Installer.new(with_caveats).install }.must_output(/Here are some things you might want to know/) - with_caveats.must_be :installed? + + expect(with_caveats).must_be :installed? end it "prints installer :manual instructions when present" do with_installer_manual = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-installer-manual.rb") - lambda { + + expect { Hbc::Installer.new(with_installer_manual).install }.must_output(/To complete the installation of Cask with-installer-manual, you must also\nrun the installer at\n\n '#{with_installer_manual.staged_path.join('Caffeine.app')}'/) - with_installer_manual.must_be :installed? + + expect(with_installer_manual).must_be :installed? end it "does not extract __MACOSX directories from zips" do @@ -262,54 +240,60 @@ describe Hbc::Installer do Hbc::Installer.new(with_macosx_dir).install end - with_macosx_dir.staged_path.join("__MACOSX").wont_be :directory? + expect(with_macosx_dir.staged_path.join("__MACOSX")).wont_be :directory? end it "installer method raises an exception when already-installed Casks which auto-update are attempted" do - auto_updates = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/auto-updates.rb") - auto_updates.installed?.must_equal false - installer = Hbc::Installer.new(auto_updates) + with_auto_updates = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/auto-updates.rb") + + expect(with_auto_updates).wont_be :installed? + + installer = Hbc::Installer.new(with_auto_updates) shutup do installer.install end - lambda { + expect { installer.install }.must_raise(Hbc::CaskAlreadyInstalledAutoUpdatesError) end it "allows already-installed Casks which auto-update to be installed if force is provided" do - auto_updates = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/auto-updates.rb") - auto_updates.installed?.must_equal false + with_auto_updates = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/auto-updates.rb") + + expect(with_auto_updates).wont_be :installed? shutup do - Hbc::Installer.new(auto_updates).install + Hbc::Installer.new(with_auto_updates).install end shutup do - Hbc::Installer.new(auto_updates, force: true).install + Hbc::Installer.new(with_auto_updates, force: true).install end # wont_raise end # unlike the CLI, the internal interface throws exception on double-install it "installer method raises an exception when already-installed Casks are attempted" do transmission = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") - transmission.installed?.must_equal false + + expect(transmission).wont_be :installed? + installer = Hbc::Installer.new(transmission) shutup do installer.install end - lambda { + expect { installer.install }.must_raise(Hbc::CaskAlreadyInstalledError) end it "allows already-installed Casks to be installed if force is provided" do transmission = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") - transmission.installed?.must_equal false + + expect(transmission).wont_be :installed? shutup do Hbc::Installer.new(transmission).install @@ -327,9 +311,7 @@ describe Hbc::Installer do Hbc::Installer.new(naked_pkg).install end - dest_path = Hbc.caskroom.join("container-pkg", naked_pkg.version) - pkg = dest_path.join("container.pkg") - pkg.must_be :file? + expect(Hbc.caskroom.join("container-pkg", naked_pkg.version, "container.pkg")).must_be :file? end it "works properly with an overridden container :type" do @@ -339,9 +321,7 @@ describe Hbc::Installer do Hbc::Installer.new(naked_executable).install end - dest_path = Hbc.caskroom.join("naked-executable", naked_executable.version) - executable = dest_path.join("naked_executable") - executable.must_be :file? + expect(Hbc.caskroom.join("naked-executable", naked_executable.version, "naked_executable")).must_be :file? end it "works fine with a nested container" do @@ -351,8 +331,7 @@ describe Hbc::Installer do Hbc::Installer.new(nested_app).install end - dest_path = Hbc.appdir.join("MyNestedApp.app") - dest_path.must_be :directory? + expect(Hbc.appdir.join("MyNestedApp.app")).must_be :directory? end it "generates and finds a timestamped metadata directory for an installed Cask" do @@ -363,8 +342,8 @@ describe Hbc::Installer do end m_path = caffeine.metadata_path(:now, true) - caffeine.metadata_path(:now, false).must_equal(m_path) - caffeine.metadata_path(:latest).must_equal(m_path) + expect(caffeine.metadata_path(:now, false)).must_equal(m_path) + expect(caffeine.metadata_path(:latest)).must_equal(m_path) end it "generates and finds a metadata subdirectory for an installed Cask" do @@ -376,8 +355,8 @@ describe Hbc::Installer do subdir_name = "Casks" m_subdir = caffeine.metadata_subdir(subdir_name, :now, true) - caffeine.metadata_subdir(subdir_name, :now, false).must_equal(m_subdir) - caffeine.metadata_subdir(subdir_name, :latest).must_equal(m_subdir) + expect(caffeine.metadata_subdir(subdir_name, :now, false)).must_equal(m_subdir) + expect(caffeine.metadata_subdir(subdir_name, :latest)).must_equal(m_subdir) end end @@ -391,9 +370,9 @@ describe Hbc::Installer do installer.uninstall end - Hbc.caskroom.join("local-caffeine", caffeine.version, "Caffeine.app").wont_be :directory? - Hbc.caskroom.join("local-caffeine", caffeine.version).wont_be :directory? - Hbc.caskroom.join("local-caffeine").wont_be :directory? + expect(Hbc.caskroom.join("local-caffeine", caffeine.version, "Caffeine.app")).wont_be :directory? + expect(Hbc.caskroom.join("local-caffeine", caffeine.version)).wont_be :directory? + expect(Hbc.caskroom.join("local-caffeine")).wont_be :directory? end it "uninstalls all versions if force is set" do @@ -404,19 +383,19 @@ describe Hbc::Installer do Hbc::Installer.new(caffeine).install end - Hbc.caskroom.join("local-caffeine", caffeine.version).must_be :directory? - Hbc.caskroom.join("local-caffeine", mutated_version).wont_be :directory? + expect(Hbc.caskroom.join("local-caffeine", caffeine.version)).must_be :directory? + expect(Hbc.caskroom.join("local-caffeine", mutated_version)).wont_be :directory? FileUtils.mv(Hbc.caskroom.join("local-caffeine", caffeine.version), Hbc.caskroom.join("local-caffeine", mutated_version)) - Hbc.caskroom.join("local-caffeine", caffeine.version).wont_be :directory? - Hbc.caskroom.join("local-caffeine", mutated_version).must_be :directory? + expect(Hbc.caskroom.join("local-caffeine", caffeine.version)).wont_be :directory? + expect(Hbc.caskroom.join("local-caffeine", mutated_version)).must_be :directory? shutup do Hbc::Installer.new(caffeine, force: true).uninstall end - Hbc.caskroom.join("local-caffeine", caffeine.version).wont_be :directory? - Hbc.caskroom.join("local-caffeine", mutated_version).wont_be :directory? - Hbc.caskroom.join("local-caffeine").wont_be :directory? + expect(Hbc.caskroom.join("local-caffeine", caffeine.version)).wont_be :directory? + expect(Hbc.caskroom.join("local-caffeine", mutated_version)).wont_be :directory? + expect(Hbc.caskroom.join("local-caffeine")).wont_be :directory? end end end