From cd4705b7bca5f266907ea6424d721190617edbcd Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 8 Feb 2017 12:29:33 +0100 Subject: Convert Install test to spec. --- .../Homebrew/cask/spec/cask/cli/install_spec.rb | 109 +++++++++++++++++++++ Library/Homebrew/cask/spec/spec_helper.rb | 3 + .../Homebrew/cask/test/cask/cli/install_test.rb | 107 -------------------- 3 files changed, 112 insertions(+), 107 deletions(-) create mode 100644 Library/Homebrew/cask/spec/cask/cli/install_spec.rb delete mode 100644 Library/Homebrew/cask/test/cask/cli/install_test.rb (limited to 'Library') diff --git a/Library/Homebrew/cask/spec/cask/cli/install_spec.rb b/Library/Homebrew/cask/spec/cask/cli/install_spec.rb new file mode 100644 index 000000000..07aa78aa3 --- /dev/null +++ b/Library/Homebrew/cask/spec/cask/cli/install_spec.rb @@ -0,0 +1,109 @@ +require "spec_helper" + +describe Hbc::CLI::Install do + it "allows staging and activation of multiple Casks at once" do + shutup do + Hbc::CLI::Install.run("local-transmission", "local-caffeine") + end + + expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed + expect(Hbc.appdir.join("Transmission.app")).to be_a_directory + expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")).to be_installed + expect(Hbc.appdir.join("Caffeine.app")).to be_a_directory + end + + it "skips double install (without nuking existing installation)" do + shutup do + Hbc::CLI::Install.run("local-transmission") + end + shutup do + Hbc::CLI::Install.run("local-transmission") + end + expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed + end + + it "prints a warning message on double install" do + shutup do + Hbc::CLI::Install.run("local-transmission") + end + + expect { + Hbc::CLI::Install.run("local-transmission", "") + }.to output(/Warning: A Cask for local-transmission is already installed./).to_stderr + end + + it "allows double install with --force" do + shutup do + Hbc::CLI::Install.run("local-transmission") + end + + expect { + expect { + Hbc::CLI::Install.run("local-transmission", "--force") + }.to output(/It seems there is already an App at.*overwriting\./).to_stderr + }.to output(/local-transmission was successfully installed!/).to_stdout + end + + it "skips dependencies with --skip-cask-deps" do + shutup do + Hbc::CLI::Install.run("with-depends-on-cask-multiple", "--skip-cask-deps") + end + expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-cask-multiple.rb")).to be_installed + expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")).not_to be_installed + expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).not_to be_installed + end + + it "properly handles Casks that are not present" do + expect { + shutup do + Hbc::CLI::Install.run("notacask") + end + }.to raise_error(Hbc::CaskError) + end + + it "returns a suggestion for a misspelled Cask" do + expect { + begin + Hbc::CLI::Install.run("googlechrome") + rescue Hbc::CaskError + nil + end + }.to output(/No available Cask for googlechrome\. Did you mean:\ngoogle-chrome/).to_stderr + end + + it "returns multiple suggestions for a Cask fragment" do + expect { + begin + Hbc::CLI::Install.run("google") + rescue Hbc::CaskError + nil + end + }.to output(/No available Cask for google\. Did you mean one of:\ngoogle/).to_stderr + end + + describe "when no Cask is specified" do + with_options = lambda do |options| + it "raises an exception" do + expect { + Hbc::CLI::Install.run(*options) + }.to raise_error(Hbc::CaskUnspecifiedError) + end + end + + describe "without options" do + with_options.call([]) + end + + describe "with --force" do + with_options.call(["--force"]) + end + + describe "with --skip-cask-deps" do + with_options.call(["--skip-cask-deps"]) + end + + describe "with an invalid option" do + with_options.call(["--notavalidoption"]) + end + end +end diff --git a/Library/Homebrew/cask/spec/spec_helper.rb b/Library/Homebrew/cask/spec/spec_helper.rb index d9f29c828..059d13a3a 100644 --- a/Library/Homebrew/cask/spec/spec_helper.rb +++ b/Library/Homebrew/cask/spec/spec_helper.rb @@ -31,6 +31,9 @@ Hbc.default_tap = Tap.fetch("caskroom", "spec").tap do |tap| FileUtils.ln_s TEST_FIXTURE_DIR.join("cask"), tap.path end +# pretend that the caskroom/cask Tap is installed +FileUtils.ln_s Pathname.new(ENV["HOMEBREW_LIBRARY"]).join("Taps", "caskroom", "homebrew-cask"), Tap.fetch("caskroom", "cask").path + RSpec.configure do |config| config.order = :random config.include(Test::Helper::Shutup) diff --git a/Library/Homebrew/cask/test/cask/cli/install_test.rb b/Library/Homebrew/cask/test/cask/cli/install_test.rb deleted file mode 100644 index d47d55a50..000000000 --- a/Library/Homebrew/cask/test/cask/cli/install_test.rb +++ /dev/null @@ -1,107 +0,0 @@ -require "test_helper" - -describe Hbc::CLI::Install do - it "allows staging and activation of multiple Casks at once" do - shutup do - Hbc::CLI::Install.run("local-transmission", "local-caffeine") - end - - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb").must_be :installed? - Hbc.appdir.join("Transmission.app").must_be :directory? - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb").must_be :installed? - Hbc.appdir.join("Caffeine.app").must_be :directory? - end - - it "skips double install (without nuking existing installation)" do - shutup do - Hbc::CLI::Install.run("local-transmission") - end - shutup do - Hbc::CLI::Install.run("local-transmission") - end - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb").must_be :installed? - end - - it "prints a warning message on double install" do - shutup do - Hbc::CLI::Install.run("local-transmission") - end - - lambda { - Hbc::CLI::Install.run("local-transmission", "") - }.must_output nil, /Warning: A Cask for local-transmission is already installed./ - end - - it "allows double install with --force" do - shutup do - Hbc::CLI::Install.run("local-transmission") - end - - lambda { - Hbc::CLI::Install.run("local-transmission", "--force") - }.must_output(/local-transmission was successfully installed!/) - end - - it "skips dependencies with --skip-cask-deps" do - shutup do - Hbc::CLI::Install.run("with-depends-on-cask-multiple", "--skip-cask-deps") - end - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-cask-multiple.rb").must_be :installed? - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb").wont_be :installed? - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb").wont_be :installed? - end - - it "properly handles Casks that are not present" do - lambda { - shutup do - Hbc::CLI::Install.run("notacask") - end - }.must_raise Hbc::CaskError - end - - it "returns a suggestion for a misspelled Cask" do - lambda { - begin - Hbc::CLI::Install.run("googlechrome") - rescue Hbc::CaskError - nil - end - }.must_output(nil, /No available Cask for googlechrome\. Did you mean:\ngoogle-chrome/) - end - - it "returns multiple suggestions for a Cask fragment" do - lambda { - begin - Hbc::CLI::Install.run("google") - rescue Hbc::CaskError - nil - end - }.must_output(nil, /No available Cask for google\. Did you mean one of:\ngoogle/) - end - - describe "when no Cask is specified" do - with_options = lambda do |options| - it "raises an exception" do - lambda { - Hbc::CLI::Install.run(*options) - }.must_raise Hbc::CaskUnspecifiedError - end - end - - describe "without options" do - with_options.call([]) - end - - describe "with --force" do - with_options.call(["--force"]) - end - - describe "with --skip-cask-deps" do - with_options.call(["--skip-cask-deps"]) - end - - describe "with an invalid option" do - with_options.call(["--notavalidoption"]) - end - end -end -- cgit v1.2.3