Use expect syntax in installer_test.

This commit is contained in:
Markus Reiter 2017-02-05 08:51:25 +01:00
parent 73df504595
commit 4e7062a9ce

View File

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