2017-03-05 19:26:56 +01:00
describe Hbc :: Installer , :cask do
2016-08-18 22:11:42 +03:00
describe " install " do
2016-10-24 00:13:48 +02:00
let ( :empty_depends_on_stub ) {
2017-02-08 11:52:20 +01:00
double ( formula : [ ] , cask : [ ] , macos : nil , arch : nil , x11 : nil )
2016-10-24 00:13:48 +02:00
}
2016-08-18 22:11:42 +03:00
it " downloads and installs a nice fresh Cask " do
2017-10-07 15:58:49 +02:00
caffeine = Hbc :: CaskLoader . load ( cask_path ( " local-caffeine " ) )
2016-08-18 22:11:42 +03:00
2017-07-29 19:55:05 +02:00
Hbc :: Installer . new ( caffeine ) . install
2016-08-18 22:11:42 +03:00
2018-06-09 09:42:49 +02:00
expect ( Hbc :: Caskroom . path . join ( " local-caffeine " , caffeine . version ) ) . to be_a_directory
2017-12-03 09:06:23 +01:00
expect ( Hbc :: Config . global . appdir . join ( " Caffeine.app " ) ) . to be_a_directory
2016-08-18 22:11:42 +03:00
end
it " works with dmg-based Casks " do
2017-10-07 15:58:49 +02:00
asset = Hbc :: CaskLoader . load ( cask_path ( " container-dmg " ) )
2016-08-18 22:11:42 +03:00
2017-07-29 19:55:05 +02:00
Hbc :: Installer . new ( asset ) . install
2016-08-18 22:11:42 +03:00
2018-06-09 09:42:49 +02:00
expect ( Hbc :: Caskroom . path . join ( " container-dmg " , asset . version ) ) . to be_a_directory
2017-12-03 09:06:23 +01:00
expect ( Hbc :: Config . global . appdir . join ( " container " ) ) . to be_a_file
2016-08-18 22:11:42 +03:00
end
2016-08-20 00:03:11 +02:00
it " works with tar-gz-based Casks " do
2017-10-07 15:58:49 +02:00
asset = Hbc :: CaskLoader . load ( cask_path ( " container-tar-gz " ) )
2016-08-18 22:11:42 +03:00
2017-07-29 19:55:05 +02:00
Hbc :: Installer . new ( asset ) . install
2016-08-18 22:11:42 +03:00
2018-06-09 09:42:49 +02:00
expect ( Hbc :: Caskroom . path . join ( " container-tar-gz " , asset . version ) ) . to be_a_directory
2017-12-03 09:06:23 +01:00
expect ( Hbc :: Config . global . appdir . join ( " container " ) ) . to be_a_file
2016-08-18 22:11:42 +03:00
end
it " works with xar-based Casks " do
2017-10-07 15:58:49 +02:00
asset = Hbc :: CaskLoader . load ( cask_path ( " container-xar " ) )
2016-08-18 22:11:42 +03:00
2017-07-29 19:55:05 +02:00
Hbc :: Installer . new ( asset ) . install
2016-08-18 22:11:42 +03:00
2018-06-09 09:42:49 +02:00
expect ( Hbc :: Caskroom . path . join ( " container-xar " , asset . version ) ) . to be_a_directory
2017-12-03 09:06:23 +01:00
expect ( Hbc :: Config . global . appdir . join ( " container " ) ) . to be_a_file
2016-08-18 22:11:42 +03:00
end
2016-08-20 00:03:11 +02:00
it " works with pure bzip2-based Casks " do
2017-10-07 15:58:49 +02:00
asset = Hbc :: CaskLoader . load ( cask_path ( " container-bzip2 " ) )
2016-08-18 22:11:42 +03:00
2017-07-29 19:55:05 +02:00
Hbc :: Installer . new ( asset ) . install
2016-08-18 22:11:42 +03:00
2018-06-09 09:42:49 +02:00
expect ( Hbc :: Caskroom . path . join ( " container-bzip2 " , asset . version ) ) . to be_a_directory
2017-12-03 09:06:23 +01:00
expect ( Hbc :: Config . global . appdir . join ( " container-bzip2-- #{ asset . version } " ) ) . to be_a_file
2016-08-18 22:11:42 +03:00
end
2016-08-20 00:03:11 +02:00
it " works with pure gzip-based Casks " do
2017-10-07 15:58:49 +02:00
asset = Hbc :: CaskLoader . load ( cask_path ( " container-gzip " ) )
2016-08-18 22:11:42 +03:00
2017-07-29 19:55:05 +02:00
Hbc :: Installer . new ( asset ) . install
2016-08-18 22:11:42 +03:00
2018-06-09 09:42:49 +02:00
expect ( Hbc :: Caskroom . path . join ( " container-gzip " , asset . version ) ) . to be_a_directory
2017-12-03 09:06:23 +01:00
expect ( Hbc :: Config . global . appdir . join ( " container " ) ) . to be_a_file
2016-08-18 22:11:42 +03:00
end
it " blows up on a bad checksum " do
2017-10-07 15:58:49 +02:00
bad_checksum = Hbc :: CaskLoader . load ( cask_path ( " bad-checksum " ) )
2017-02-05 08:51:25 +01:00
expect {
2017-07-29 19:55:05 +02:00
Hbc :: Installer . new ( bad_checksum ) . install
2017-02-08 11:52:20 +01:00
} . to raise_error ( Hbc :: CaskSha256MismatchError )
2016-08-18 22:11:42 +03:00
end
it " blows up on a missing checksum " do
2017-10-07 15:58:49 +02:00
missing_checksum = Hbc :: CaskLoader . load ( cask_path ( " missing-checksum " ) )
2017-02-05 08:51:25 +01:00
expect {
2017-07-29 19:55:05 +02:00
Hbc :: Installer . new ( missing_checksum ) . install
2017-02-08 11:52:20 +01:00
} . to raise_error ( Hbc :: CaskSha256MissingError )
2016-08-18 22:11:42 +03:00
end
it " installs fine if sha256 :no_check is used " do
2017-10-07 15:58:49 +02:00
no_checksum = Hbc :: CaskLoader . load ( cask_path ( " no-checksum " ) )
2016-08-18 22:11:42 +03:00
2017-07-29 19:55:05 +02:00
Hbc :: Installer . new ( no_checksum ) . install
2016-08-18 22:11:42 +03:00
2017-02-08 11:52:20 +01:00
expect ( no_checksum ) . to be_installed
2016-08-18 22:11:42 +03:00
end
it " fails to install if sha256 :no_check is used with --require-sha " do
2017-10-07 15:58:49 +02:00
no_checksum = Hbc :: CaskLoader . load ( cask_path ( " no-checksum " ) )
2017-02-05 08:51:25 +01:00
expect {
2017-07-29 19:55:05 +02:00
Hbc :: Installer . new ( no_checksum , require_sha : true ) . install
2017-02-08 11:52:20 +01:00
} . to raise_error ( Hbc :: CaskNoShasumError )
2016-08-18 22:11:42 +03:00
end
it " installs fine if sha256 :no_check is used with --require-sha and --force " do
2017-10-07 15:58:49 +02:00
no_checksum = Hbc :: CaskLoader . load ( cask_path ( " no-checksum " ) )
2016-08-18 22:11:42 +03:00
2017-07-29 19:55:05 +02:00
Hbc :: Installer . new ( no_checksum , require_sha : true , force : true ) . install
2016-08-18 22:11:42 +03:00
2017-02-08 11:52:20 +01:00
expect ( no_checksum ) . to be_installed
2016-08-18 22:11:42 +03:00
end
it " prints caveats if they're present " do
2017-10-07 15:58:49 +02:00
with_caveats = Hbc :: CaskLoader . load ( cask_path ( " with-caveats " ) )
2017-02-05 08:51:25 +01:00
expect {
2016-08-18 22:11:42 +03:00
Hbc :: Installer . new ( with_caveats ) . install
2017-02-08 11:52:20 +01:00
} . to output ( / Here are some things you might want to know / ) . to_stdout
2017-02-05 08:51:25 +01:00
2017-02-08 11:52:20 +01:00
expect ( with_caveats ) . to be_installed
2016-08-18 22:11:42 +03:00
end
it " prints installer :manual instructions when present " do
2017-10-07 15:58:49 +02:00
with_installer_manual = Hbc :: CaskLoader . load ( cask_path ( " with-installer-manual " ) )
2017-02-05 08:51:25 +01:00
expect {
2016-08-18 22:11:42 +03:00
Hbc :: Installer . new ( with_installer_manual ) . install
2017-02-08 11:52:20 +01:00
} . to 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' ) } ' / ) . to_stdout
2017-02-05 08:51:25 +01:00
2017-02-08 11:52:20 +01:00
expect ( with_installer_manual ) . to be_installed
2016-08-18 22:11:42 +03:00
end
it " does not extract __MACOSX directories from zips " do
2017-10-07 15:58:49 +02:00
with_macosx_dir = Hbc :: CaskLoader . load ( cask_path ( " with-macosx-dir " ) )
2016-08-18 22:11:42 +03:00
2017-07-29 19:55:05 +02:00
Hbc :: Installer . new ( with_macosx_dir ) . install
2016-08-18 22:11:42 +03:00
2017-02-08 11:52:20 +01:00
expect ( with_macosx_dir . staged_path . join ( " __MACOSX " ) ) . not_to be_a_directory
2016-08-18 22:11:42 +03:00
end
it " allows already-installed Casks which auto-update to be installed if force is provided " do
2017-10-07 15:58:49 +02:00
with_auto_updates = Hbc :: CaskLoader . load ( cask_path ( " auto-updates " ) )
2017-02-05 08:51:25 +01:00
2017-02-08 11:52:20 +01:00
expect ( with_auto_updates ) . not_to be_installed
2016-08-18 22:11:42 +03:00
2017-07-29 19:55:05 +02:00
Hbc :: Installer . new ( with_auto_updates ) . install
2016-08-18 22:11:42 +03:00
2017-02-08 11:52:20 +01:00
expect {
2017-07-29 19:55:05 +02:00
Hbc :: Installer . new ( with_auto_updates , force : true ) . install
2017-02-08 11:52:20 +01:00
} . not_to raise_error
2016-08-18 22:11:42 +03:00
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
2017-10-07 15:58:49 +02:00
transmission = Hbc :: CaskLoader . load ( cask_path ( " local-transmission " ) )
2017-02-05 08:51:25 +01:00
2017-02-08 11:52:20 +01:00
expect ( transmission ) . not_to be_installed
2017-02-05 08:51:25 +01:00
2016-08-18 22:11:42 +03:00
installer = Hbc :: Installer . new ( transmission )
2017-07-29 19:55:05 +02:00
installer . install
2016-08-18 22:11:42 +03:00
2017-02-05 08:51:25 +01:00
expect {
2016-08-18 22:11:42 +03:00
installer . install
2017-02-08 11:52:20 +01:00
} . to raise_error ( Hbc :: CaskAlreadyInstalledError )
2016-08-18 22:11:42 +03:00
end
it " allows already-installed Casks to be installed if force is provided " do
2017-10-07 15:58:49 +02:00
transmission = Hbc :: CaskLoader . load ( cask_path ( " local-transmission " ) )
2017-02-05 08:51:25 +01:00
2017-02-08 11:52:20 +01:00
expect ( transmission ) . not_to be_installed
2016-08-18 22:11:42 +03:00
2017-07-29 19:55:05 +02:00
Hbc :: Installer . new ( transmission ) . install
2016-08-18 22:11:42 +03:00
2017-07-29 19:55:05 +02:00
expect {
2016-08-18 22:11:42 +03:00
Hbc :: Installer . new ( transmission , force : true ) . install
2017-07-29 19:55:05 +02:00
} . not_to raise_error
2016-08-18 22:11:42 +03:00
end
2016-08-20 00:03:11 +02:00
it " works naked-pkg-based Casks " do
2017-10-07 15:58:49 +02:00
naked_pkg = Hbc :: CaskLoader . load ( cask_path ( " container-pkg " ) )
2016-08-18 22:11:42 +03:00
2017-07-29 19:55:05 +02:00
Hbc :: Installer . new ( naked_pkg ) . install
2016-08-18 22:11:42 +03:00
2018-06-09 09:42:49 +02:00
expect ( Hbc :: Caskroom . path . join ( " container-pkg " , naked_pkg . version , " container.pkg " ) ) . to be_a_file
2016-08-18 22:11:42 +03:00
end
it " works properly with an overridden container :type " do
2017-10-07 15:58:49 +02:00
naked_executable = Hbc :: CaskLoader . load ( cask_path ( " naked-executable " ) )
2016-08-18 22:11:42 +03:00
2017-07-29 19:55:05 +02:00
Hbc :: Installer . new ( naked_executable ) . install
2016-08-18 22:11:42 +03:00
2018-06-09 09:42:49 +02:00
expect ( Hbc :: Caskroom . path . join ( " naked-executable " , naked_executable . version , " naked_executable " ) ) . to be_a_file
2016-08-18 22:11:42 +03:00
end
it " works fine with a nested container " do
2017-10-07 15:58:49 +02:00
nested_app = Hbc :: CaskLoader . load ( cask_path ( " nested-app " ) )
2016-08-18 22:11:42 +03:00
2017-07-29 19:55:05 +02:00
Hbc :: Installer . new ( nested_app ) . install
2016-08-18 22:11:42 +03:00
2017-12-03 09:06:23 +01:00
expect ( Hbc :: Config . global . appdir . join ( " MyNestedApp.app " ) ) . to be_a_directory
2016-08-18 22:11:42 +03:00
end
it " generates and finds a timestamped metadata directory for an installed Cask " do
2017-10-07 15:58:49 +02:00
caffeine = Hbc :: CaskLoader . load ( cask_path ( " local-caffeine " ) )
2016-08-18 22:11:42 +03:00
2017-07-29 19:55:05 +02:00
Hbc :: Installer . new ( caffeine ) . install
2016-08-18 22:11:42 +03:00
2017-04-20 10:48:32 +02:00
m_path = caffeine . metadata_timestamped_path ( timestamp : :now , create : true )
expect ( caffeine . metadata_timestamped_path ( timestamp : :latest ) ) . to eq ( m_path )
2016-08-18 22:11:42 +03:00
end
it " generates and finds a metadata subdirectory for an installed Cask " do
2017-10-07 15:58:49 +02:00
caffeine = Hbc :: CaskLoader . load ( cask_path ( " local-caffeine " ) )
2016-08-18 22:11:42 +03:00
2017-07-29 19:55:05 +02:00
Hbc :: Installer . new ( caffeine ) . install
2016-08-18 22:11:42 +03:00
subdir_name = " Casks "
2017-04-20 10:48:32 +02:00
m_subdir = caffeine . metadata_subdir ( subdir_name , timestamp : :now , create : true )
expect ( caffeine . metadata_subdir ( subdir_name , timestamp : :latest ) ) . to eq ( m_subdir )
2016-08-18 22:11:42 +03:00
end
end
describe " uninstall " do
it " fully uninstalls a Cask " do
2017-10-07 15:58:49 +02:00
caffeine = Hbc :: CaskLoader . load ( cask_path ( " local-caffeine " ) )
2016-08-18 22:11:42 +03:00
installer = Hbc :: Installer . new ( caffeine )
2017-07-29 19:55:05 +02:00
installer . install
installer . uninstall
2016-08-18 22:11:42 +03:00
2018-06-09 09:42:49 +02:00
expect ( Hbc :: Caskroom . path . join ( " local-caffeine " , caffeine . version , " Caffeine.app " ) ) . not_to be_a_directory
expect ( Hbc :: Caskroom . path . join ( " local-caffeine " , caffeine . version ) ) . not_to be_a_directory
expect ( Hbc :: Caskroom . path . join ( " local-caffeine " ) ) . not_to be_a_directory
2016-08-18 22:11:42 +03:00
end
it " uninstalls all versions if force is set " do
2017-10-07 15:58:49 +02:00
caffeine = Hbc :: CaskLoader . load ( cask_path ( " local-caffeine " ) )
2016-08-18 22:11:42 +03:00
mutated_version = caffeine . version + " .1 "
2017-07-29 19:55:05 +02:00
Hbc :: Installer . new ( caffeine ) . install
2016-08-18 22:11:42 +03:00
2018-06-09 09:42:49 +02:00
expect ( Hbc :: Caskroom . path . join ( " local-caffeine " , caffeine . version ) ) . to be_a_directory
expect ( Hbc :: Caskroom . path . join ( " local-caffeine " , mutated_version ) ) . not_to be_a_directory
FileUtils . mv ( Hbc :: Caskroom . path . join ( " local-caffeine " , caffeine . version ) , Hbc :: Caskroom . path . join ( " local-caffeine " , mutated_version ) )
expect ( Hbc :: Caskroom . path . join ( " local-caffeine " , caffeine . version ) ) . not_to be_a_directory
expect ( Hbc :: Caskroom . path . join ( " local-caffeine " , mutated_version ) ) . to be_a_directory
2016-08-18 22:11:42 +03:00
2017-07-29 19:55:05 +02:00
Hbc :: Installer . new ( caffeine , force : true ) . uninstall
2016-08-18 22:11:42 +03:00
2018-06-09 09:42:49 +02:00
expect ( Hbc :: Caskroom . path . join ( " local-caffeine " , caffeine . version ) ) . not_to be_a_directory
expect ( Hbc :: Caskroom . path . join ( " local-caffeine " , mutated_version ) ) . not_to be_a_directory
expect ( Hbc :: Caskroom . path . join ( " local-caffeine " ) ) . not_to be_a_directory
2016-08-18 22:11:42 +03:00
end
end
end