From 787860c1bd228c849ab311e57a5042c1cb5162e2 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 8 Feb 2017 13:44:28 +0100 Subject: Convert Zap test to spec. --- Library/Homebrew/cask/spec/cask/cli/zap_spec.rb | 75 +++++++++++++++++++++++++ Library/Homebrew/cask/test/cask/cli/zap_test.rb | 75 ------------------------- 2 files changed, 75 insertions(+), 75 deletions(-) create mode 100644 Library/Homebrew/cask/spec/cask/cli/zap_spec.rb delete mode 100644 Library/Homebrew/cask/test/cask/cli/zap_test.rb (limited to 'Library') diff --git a/Library/Homebrew/cask/spec/cask/cli/zap_spec.rb b/Library/Homebrew/cask/spec/cask/cli/zap_spec.rb new file mode 100644 index 000000000..d26114567 --- /dev/null +++ b/Library/Homebrew/cask/spec/cask/cli/zap_spec.rb @@ -0,0 +1,75 @@ +require "spec_helper" + +describe Hbc::CLI::Zap do + it "shows an error when a bad Cask is provided" do + expect { + Hbc::CLI::Zap.run("notacask") + }.to raise_error(Hbc::CaskUnavailableError) + end + + it "can zap and unlink multiple Casks at once" do + caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") + transmission = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") + + shutup do + Hbc::Installer.new(caffeine).install + Hbc::Installer.new(transmission).install + end + + expect(caffeine).to be_installed + expect(transmission).to be_installed + + shutup do + Hbc::CLI::Zap.run("--notavalidoption", + "local-caffeine", "local-transmission") + end + + expect(caffeine).not_to be_installed + expect(Hbc.appdir.join("Caffeine.app")).not_to be_a_symlink + expect(transmission).not_to be_installed + expect(Hbc.appdir.join("Transmission.app")).not_to be_a_symlink + end + + # TODO: Explicit test that both zap and uninstall directives get dispatched. + # The above tests that implicitly. + # + # it "dispatches both uninstall and zap stanzas" do + # with_zap = Hbc.load('with-zap') + # + # shutup do + # Hbc::Installer.new(with_zap).install + # end + # + # with_zap.must_be :installed? + # + # Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/bin/osascript', '-e', 'tell application "System Events" to count processes whose bundle identifier is "my.fancy.package.app"'], '1') + # Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/bin/osascript', '-e', 'tell application id "my.fancy.package.app" to quit']) + # Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/bin/osascript', '-e', 'tell application "System Events" to count processes whose bundle identifier is "my.fancy.package.app.from.uninstall"'], '1') + # Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/bin/osascript', '-e', 'tell application id "my.fancy.package.app.from.uninstall" to quit']) + # + # Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', with_zap.staged_path.join('MyFancyPkg','FancyUninstaller.tool'), '--please']) + # Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', '/bin/rm', '-rf', '--', + # Pathname.new('~/Library/Preferences/my.fancy.app.plist').expand_path]) + # + # shutup do + # Hbc::CLI::Zap.run('with-zap') + # end + # with_zap.wont_be :installed? + # end + + describe "when no Cask is specified" do + it "raises an exception" do + expect { + Hbc::CLI::Zap.run + }.to raise_error(Hbc::CaskUnspecifiedError) + end + end + + describe "when no Cask is specified, but an invalid option" do + it "raises an exception" do + expect { + Hbc::CLI::Zap.run("--notavalidoption") + }.to raise_error(Hbc::CaskUnspecifiedError) + end + end +end diff --git a/Library/Homebrew/cask/test/cask/cli/zap_test.rb b/Library/Homebrew/cask/test/cask/cli/zap_test.rb deleted file mode 100644 index 0f2aa4f8e..000000000 --- a/Library/Homebrew/cask/test/cask/cli/zap_test.rb +++ /dev/null @@ -1,75 +0,0 @@ -require "test_helper" - -describe Hbc::CLI::Zap do - it "shows an error when a bad Cask is provided" do - lambda { - Hbc::CLI::Zap.run("notacask") - }.must_raise Hbc::CaskUnavailableError - end - - it "can zap and unlink multiple Casks at once" do - caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") - transmission = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") - - shutup do - Hbc::Installer.new(caffeine).install - Hbc::Installer.new(transmission).install - end - - caffeine.must_be :installed? - transmission.must_be :installed? - - shutup do - Hbc::CLI::Zap.run("--notavalidoption", - "local-caffeine", "local-transmission") - end - - caffeine.wont_be :installed? - Hbc.appdir.join("Transmission.app").wont_be :symlink? - transmission.wont_be :installed? - Hbc.appdir.join("Caffeine.app").wont_be :symlink? - end - - # TODO: Explicit test that both zap and uninstall directives get dispatched. - # The above tests that implicitly. - # - # it "dispatches both uninstall and zap stanzas" do - # with_zap = Hbc.load('with-zap') - # - # shutup do - # Hbc::Installer.new(with_zap).install - # end - # - # with_zap.must_be :installed? - # - # Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/bin/osascript', '-e', 'tell application "System Events" to count processes whose bundle identifier is "my.fancy.package.app"'], '1') - # Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/bin/osascript', '-e', 'tell application id "my.fancy.package.app" to quit']) - # Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/bin/osascript', '-e', 'tell application "System Events" to count processes whose bundle identifier is "my.fancy.package.app.from.uninstall"'], '1') - # Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/bin/osascript', '-e', 'tell application id "my.fancy.package.app.from.uninstall" to quit']) - # - # Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', with_zap.staged_path.join('MyFancyPkg','FancyUninstaller.tool'), '--please']) - # Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', '/bin/rm', '-rf', '--', - # Pathname.new('~/Library/Preferences/my.fancy.app.plist').expand_path]) - # - # shutup do - # Hbc::CLI::Zap.run('with-zap') - # end - # with_zap.wont_be :installed? - # end - - describe "when no Cask is specified" do - it "raises an exception" do - lambda { - Hbc::CLI::Zap.run - }.must_raise Hbc::CaskUnspecifiedError - end - end - - describe "when no Cask is specified, but an invalid option" do - it "raises an exception" do - lambda { - Hbc::CLI::Zap.run("--notavalidoption") - }.must_raise Hbc::CaskUnspecifiedError - end - end -end -- cgit v1.2.3