Convert Install test to spec.

This commit is contained in:
Markus Reiter 2017-02-08 12:29:33 +01:00
parent 9d36734e40
commit cd4705b7bc
2 changed files with 27 additions and 22 deletions

View File

@ -1,4 +1,4 @@
require "test_helper" require "spec_helper"
describe Hbc::CLI::Install do describe Hbc::CLI::Install do
it "allows staging and activation of multiple Casks at once" do it "allows staging and activation of multiple Casks at once" do
@ -6,10 +6,10 @@ describe Hbc::CLI::Install do
Hbc::CLI::Install.run("local-transmission", "local-caffeine") Hbc::CLI::Install.run("local-transmission", "local-caffeine")
end end
Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb").must_be :installed? expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed
Hbc.appdir.join("Transmission.app").must_be :directory? expect(Hbc.appdir.join("Transmission.app")).to be_a_directory
Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb").must_be :installed? expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")).to be_installed
Hbc.appdir.join("Caffeine.app").must_be :directory? expect(Hbc.appdir.join("Caffeine.app")).to be_a_directory
end end
it "skips double install (without nuking existing installation)" do it "skips double install (without nuking existing installation)" do
@ -19,7 +19,7 @@ describe Hbc::CLI::Install do
shutup do shutup do
Hbc::CLI::Install.run("local-transmission") Hbc::CLI::Install.run("local-transmission")
end end
Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb").must_be :installed? expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed
end end
it "prints a warning message on double install" do it "prints a warning message on double install" do
@ -27,9 +27,9 @@ describe Hbc::CLI::Install do
Hbc::CLI::Install.run("local-transmission") Hbc::CLI::Install.run("local-transmission")
end end
lambda { expect {
Hbc::CLI::Install.run("local-transmission", "") Hbc::CLI::Install.run("local-transmission", "")
}.must_output nil, /Warning: A Cask for local-transmission is already installed./ }.to output(/Warning: A Cask for local-transmission is already installed./).to_stderr
end end
it "allows double install with --force" do it "allows double install with --force" do
@ -37,54 +37,56 @@ describe Hbc::CLI::Install do
Hbc::CLI::Install.run("local-transmission") Hbc::CLI::Install.run("local-transmission")
end end
lambda { expect {
expect {
Hbc::CLI::Install.run("local-transmission", "--force") Hbc::CLI::Install.run("local-transmission", "--force")
}.must_output(/local-transmission was successfully installed!/) }.to output(/It seems there is already an App at.*overwriting\./).to_stderr
}.to output(/local-transmission was successfully installed!/).to_stdout
end end
it "skips dependencies with --skip-cask-deps" do it "skips dependencies with --skip-cask-deps" do
shutup do shutup do
Hbc::CLI::Install.run("with-depends-on-cask-multiple", "--skip-cask-deps") Hbc::CLI::Install.run("with-depends-on-cask-multiple", "--skip-cask-deps")
end end
Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-cask-multiple.rb").must_be :installed? expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-cask-multiple.rb")).to be_installed
Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb").wont_be :installed? expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")).not_to be_installed
Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb").wont_be :installed? expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).not_to be_installed
end end
it "properly handles Casks that are not present" do it "properly handles Casks that are not present" do
lambda { expect {
shutup do shutup do
Hbc::CLI::Install.run("notacask") Hbc::CLI::Install.run("notacask")
end end
}.must_raise Hbc::CaskError }.to raise_error(Hbc::CaskError)
end end
it "returns a suggestion for a misspelled Cask" do it "returns a suggestion for a misspelled Cask" do
lambda { expect {
begin begin
Hbc::CLI::Install.run("googlechrome") Hbc::CLI::Install.run("googlechrome")
rescue Hbc::CaskError rescue Hbc::CaskError
nil nil
end end
}.must_output(nil, /No available Cask for googlechrome\. Did you mean:\ngoogle-chrome/) }.to output(/No available Cask for googlechrome\. Did you mean:\ngoogle-chrome/).to_stderr
end end
it "returns multiple suggestions for a Cask fragment" do it "returns multiple suggestions for a Cask fragment" do
lambda { expect {
begin begin
Hbc::CLI::Install.run("google") Hbc::CLI::Install.run("google")
rescue Hbc::CaskError rescue Hbc::CaskError
nil nil
end end
}.must_output(nil, /No available Cask for google\. Did you mean one of:\ngoogle/) }.to output(/No available Cask for google\. Did you mean one of:\ngoogle/).to_stderr
end end
describe "when no Cask is specified" do describe "when no Cask is specified" do
with_options = lambda do |options| with_options = lambda do |options|
it "raises an exception" do it "raises an exception" do
lambda { expect {
Hbc::CLI::Install.run(*options) Hbc::CLI::Install.run(*options)
}.must_raise Hbc::CaskUnspecifiedError }.to raise_error(Hbc::CaskUnspecifiedError)
end end
end end

View File

@ -31,6 +31,9 @@ Hbc.default_tap = Tap.fetch("caskroom", "spec").tap do |tap|
FileUtils.ln_s TEST_FIXTURE_DIR.join("cask"), tap.path FileUtils.ln_s TEST_FIXTURE_DIR.join("cask"), tap.path
end 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| RSpec.configure do |config|
config.order = :random config.order = :random
config.include(Test::Helper::Shutup) config.include(Test::Helper::Shutup)