aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/cask/cli
diff options
context:
space:
mode:
authorGautham Goli2017-10-12 00:29:19 +0530
committerGautham Goli2017-10-13 19:50:46 +0530
commit7fa51f71f1a8a21b905bafc1fb4106f0222d654f (patch)
tree098d2477a8262a5770310fed4693da31c4392e1c /Library/Homebrew/test/cask/cli
parentafdd0e2437426ec85ff86e5b7562d3a6a69ba3e5 (diff)
parent56458f03fcc68ef6d8ee3ee4a7c1d16021aa5800 (diff)
downloadbrew-7fa51f71f1a8a21b905bafc1fb4106f0222d654f.tar.bz2
Merge branch 'master' into audit_line_rubocop_part_4_rebase_attempt_1
Diffstat (limited to 'Library/Homebrew/test/cask/cli')
-rw-r--r--Library/Homebrew/test/cask/cli/audit_spec.rb20
-rw-r--r--Library/Homebrew/test/cask/cli/cat_spec.rb37
-rw-r--r--Library/Homebrew/test/cask/cli/cleanup_spec.rb4
-rw-r--r--Library/Homebrew/test/cask/cli/create_spec.rb30
-rw-r--r--Library/Homebrew/test/cask/cli/doctor_spec.rb4
-rw-r--r--Library/Homebrew/test/cask/cli/edit_spec.rb24
-rw-r--r--Library/Homebrew/test/cask/cli/fetch_spec.rb36
-rw-r--r--Library/Homebrew/test/cask/cli/home_spec.rb4
-rw-r--r--Library/Homebrew/test/cask/cli/info_spec.rb70
-rw-r--r--Library/Homebrew/test/cask/cli/install_spec.rb86
-rw-r--r--Library/Homebrew/test/cask/cli/list_spec.rb40
-rw-r--r--Library/Homebrew/test/cask/cli/options_spec.rb32
-rw-r--r--Library/Homebrew/test/cask/cli/outdated_spec.rb16
-rw-r--r--Library/Homebrew/test/cask/cli/reinstall_spec.rb14
-rw-r--r--Library/Homebrew/test/cask/cli/search_spec.rb57
-rw-r--r--Library/Homebrew/test/cask/cli/shared_examples/invalid_option.rb15
-rw-r--r--Library/Homebrew/test/cask/cli/shared_examples/requires_cask_token.rb9
-rw-r--r--Library/Homebrew/test/cask/cli/style_spec.rb4
-rw-r--r--Library/Homebrew/test/cask/cli/uninstall_spec.rb65
-rw-r--r--Library/Homebrew/test/cask/cli/zap_spec.rb33
20 files changed, 312 insertions, 288 deletions
diff --git a/Library/Homebrew/test/cask/cli/audit_spec.rb b/Library/Homebrew/test/cask/cli/audit_spec.rb
index 01f506c8c..da8bf1273 100644
--- a/Library/Homebrew/test/cask/cli/audit_spec.rb
+++ b/Library/Homebrew/test/cask/cli/audit_spec.rb
@@ -1,13 +1,19 @@
+require_relative "shared_examples/invalid_option"
+
describe Hbc::CLI::Audit, :cask do
- let(:cask) { double("cask", token: nil) }
+ let(:cask) { Hbc::Cask.new(nil) }
+
+ it_behaves_like "a command that handles invalid options"
describe "selection of Casks to audit" do
it "audits all Casks if no tokens are given" do
+ expect(cask).to be_a Hbc::Cask
+
allow(Hbc).to receive(:all).and_return([cask, cask])
expect(Hbc::Auditor).to receive(:audit).twice.and_return(true)
- Hbc::CLI::Audit.run
+ described_class.run
end
it "audits specified Casks if tokens are given" do
@@ -18,7 +24,7 @@ describe Hbc::CLI::Audit, :cask do
.with(cask, audit_download: false, check_token_conflicts: false)
.and_return(true)
- Hbc::CLI::Audit.run(cask_token)
+ described_class.run(cask_token)
end
end
@@ -29,7 +35,7 @@ describe Hbc::CLI::Audit, :cask do
.with(cask, audit_download: false, check_token_conflicts: false)
.and_return(true)
- Hbc::CLI::Audit.run("casktoken")
+ described_class.run("casktoken")
end
it "download a Cask if --download flag is set" do
@@ -38,7 +44,7 @@ describe Hbc::CLI::Audit, :cask do
.with(cask, audit_download: true, check_token_conflicts: false)
.and_return(true)
- Hbc::CLI::Audit.run("casktoken", "--download")
+ described_class.run("casktoken", "--download")
end
end
@@ -49,7 +55,7 @@ describe Hbc::CLI::Audit, :cask do
.with(cask, audit_download: false, check_token_conflicts: false)
.and_return(true)
- Hbc::CLI::Audit.run("casktoken")
+ described_class.run("casktoken")
end
it "checks for token conflicts if --token-conflicts flag is set" do
@@ -58,7 +64,7 @@ describe Hbc::CLI::Audit, :cask do
.with(cask, audit_download: false, check_token_conflicts: true)
.and_return(true)
- Hbc::CLI::Audit.run("casktoken", "--token-conflicts")
+ described_class.run("casktoken", "--token-conflicts")
end
end
end
diff --git a/Library/Homebrew/test/cask/cli/cat_spec.rb b/Library/Homebrew/test/cask/cli/cat_spec.rb
index b726a0b36..6b54a2e4b 100644
--- a/Library/Homebrew/test/cask/cli/cat_spec.rb
+++ b/Library/Homebrew/test/cask/cli/cat_spec.rb
@@ -1,4 +1,10 @@
+require_relative "shared_examples/requires_cask_token"
+require_relative "shared_examples/invalid_option"
+
describe Hbc::CLI::Cat, :cask do
+ it_behaves_like "a command that requires a Cask token"
+ it_behaves_like "a command that handles invalid options"
+
describe "given a basic Cask" do
let(:basic_cask_content) {
<<-EOS.undent
@@ -16,42 +22,19 @@ describe Hbc::CLI::Cat, :cask do
it "displays the Cask file content about the specified Cask" do
expect {
- Hbc::CLI::Cat.run("basic-cask")
+ described_class.run("basic-cask")
}.to output(basic_cask_content).to_stdout
end
it "can display multiple Casks" do
expect {
- Hbc::CLI::Cat.run("basic-cask", "basic-cask")
+ described_class.run("basic-cask", "basic-cask")
}.to output(basic_cask_content * 2).to_stdout
end
-
- it "fails when option is unknown" do
- expect {
- Hbc::CLI::Cat.run("--notavalidoption", "basic-cask")
- }.to raise_error(/invalid option/)
- end
end
it "raises an exception when the Cask does not exist" do
- expect { Hbc::CLI::Cat.run("notacask") }
- .to output(/is unavailable/).to_stderr
- .and raise_error(Hbc::CaskError, "Cat incomplete.")
- end
-
- describe "when no Cask is specified" do
- it "raises an exception" do
- expect {
- Hbc::CLI::Cat.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::Cat.run("--notavalidoption")
- }.to raise_error(/invalid option/)
- end
+ expect { described_class.run("notacask") }
+ .to raise_error(Hbc::CaskUnavailableError, /is unavailable/)
end
end
diff --git a/Library/Homebrew/test/cask/cli/cleanup_spec.rb b/Library/Homebrew/test/cask/cli/cleanup_spec.rb
index 64e3ef49f..7cf00352d 100644
--- a/Library/Homebrew/test/cask/cli/cleanup_spec.rb
+++ b/Library/Homebrew/test/cask/cli/cleanup_spec.rb
@@ -1,3 +1,5 @@
+require_relative "shared_examples/invalid_option"
+
describe Hbc::CLI::Cleanup, :cask do
let(:cache_location) { Pathname.new(Dir.mktmpdir).realpath }
let(:outdated_only) { false }
@@ -12,6 +14,8 @@ describe Hbc::CLI::Cleanup, :cask do
cache_location.rmtree
end
+ it_behaves_like "a command that handles invalid options"
+
describe "cleanup" do
let(:cask_token) { "caffeine" }
let(:cask_tokens) { [cask_token] }
diff --git a/Library/Homebrew/test/cask/cli/create_spec.rb b/Library/Homebrew/test/cask/cli/create_spec.rb
index d77b0a2aa..60c03db75 100644
--- a/Library/Homebrew/test/cask/cli/create_spec.rb
+++ b/Library/Homebrew/test/cask/cli/create_spec.rb
@@ -1,3 +1,6 @@
+require_relative "shared_examples/requires_cask_token"
+require_relative "shared_examples/invalid_option"
+
describe Hbc::CLI::Create, :cask do
around(:each) do |example|
begin
@@ -13,6 +16,9 @@ describe Hbc::CLI::Create, :cask do
allow_any_instance_of(described_class).to receive(:exec_editor)
end
+ it_behaves_like "a command that requires a Cask token"
+ it_behaves_like "a command that handles invalid options"
+
it "opens the editor for the specified Cask" do
command = described_class.new("new-cask")
expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("new-cask"))
@@ -39,7 +45,7 @@ describe Hbc::CLI::Create, :cask do
it "raises an exception when more than one Cask is given" do
expect {
described_class.run("additional-cask", "another-cask")
- }.to raise_error(/Only one Cask can be created at a time./)
+ }.to raise_error(/Only one Cask can be created at a time\./)
end
it "raises an exception when the Cask already exists" do
@@ -53,26 +59,4 @@ describe Hbc::CLI::Create, :cask do
expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("local-caff"))
command.run
end
-
- describe "when no Cask is specified" do
- it "raises an exception" do
- expect {
- described_class.run
- }.to raise_error(Hbc::CaskUnspecifiedError)
- end
- end
-
- context "when an invalid option is specified" do
- it "raises an exception when no Cask is specified" do
- expect {
- described_class.run("--notavalidoption")
- }.to raise_error(/invalid option/)
- end
-
- it "raises an exception" do
- expect {
- described_class.run("--notavalidoption", "yet-another-cask")
- }.to raise_error(/invalid option/)
- end
- end
end
diff --git a/Library/Homebrew/test/cask/cli/doctor_spec.rb b/Library/Homebrew/test/cask/cli/doctor_spec.rb
index b24c777eb..e3967060e 100644
--- a/Library/Homebrew/test/cask/cli/doctor_spec.rb
+++ b/Library/Homebrew/test/cask/cli/doctor_spec.rb
@@ -1,4 +1,8 @@
+require_relative "shared_examples/invalid_option"
+
describe Hbc::CLI::Doctor, :cask do
+ it_behaves_like "a command that handles invalid options"
+
it "displays some nice info about the environment" do
expect {
Hbc::CLI::Doctor.run
diff --git a/Library/Homebrew/test/cask/cli/edit_spec.rb b/Library/Homebrew/test/cask/cli/edit_spec.rb
index 5d5cbf4b9..347522020 100644
--- a/Library/Homebrew/test/cask/cli/edit_spec.rb
+++ b/Library/Homebrew/test/cask/cli/edit_spec.rb
@@ -1,8 +1,14 @@
+require_relative "shared_examples/requires_cask_token"
+require_relative "shared_examples/invalid_option"
+
describe Hbc::CLI::Edit, :cask do
before(:each) do
allow_any_instance_of(described_class).to receive(:exec_editor)
end
+ it_behaves_like "a command that requires a Cask token"
+ it_behaves_like "a command that handles invalid options"
+
it "opens the editor for the specified Cask" do
command = described_class.new("local-caffeine")
expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("local-caffeine"))
@@ -12,7 +18,7 @@ describe Hbc::CLI::Edit, :cask do
it "raises an error when given more than one argument" do
expect {
described_class.new("local-caffeine", "local-transmission")
- }.to raise_error(/Only one Cask can be created at a time./)
+ }.to raise_error(/Only one Cask can be edited at a time\./)
end
it "raises an exception when the Cask doesnt exist" do
@@ -20,20 +26,4 @@ describe Hbc::CLI::Edit, :cask do
described_class.run("notacask")
}.to raise_error(Hbc::CaskUnavailableError)
end
-
- describe "when no Cask is specified" do
- it "raises an exception" do
- expect {
- described_class.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 {
- described_class.run("--notavalidoption")
- }.to raise_error(/invalid option/)
- end
- end
end
diff --git a/Library/Homebrew/test/cask/cli/fetch_spec.rb b/Library/Homebrew/test/cask/cli/fetch_spec.rb
index f71c23fb6..67cf6e61d 100644
--- a/Library/Homebrew/test/cask/cli/fetch_spec.rb
+++ b/Library/Homebrew/test/cask/cli/fetch_spec.rb
@@ -1,14 +1,20 @@
+require_relative "shared_examples/requires_cask_token"
+require_relative "shared_examples/invalid_option"
+
describe Hbc::CLI::Fetch, :cask do
let(:local_transmission) {
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")
+ Hbc::CaskLoader.load(cask_path("local-transmission"))
}
let(:local_caffeine) {
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")
+ Hbc::CaskLoader.load(cask_path("local-caffeine"))
}
+ it_behaves_like "a command that requires a Cask token"
+ it_behaves_like "a command that handles invalid options"
+
it "allows download the installer of a Cask" do
- Hbc::CLI::Fetch.run("local-transmission", "local-caffeine")
+ described_class.run("local-transmission", "local-caffeine")
expect(Hbc::CurlDownloadStrategy.new(local_transmission).cached_location).to exist
expect(Hbc::CurlDownloadStrategy.new(local_caffeine).cached_location).to exist
end
@@ -19,7 +25,7 @@ describe Hbc::CLI::Fetch, :cask do
Hbc::Download.new(local_transmission).perform
old_ctime = File.stat(download_stategy.cached_location).ctime
- Hbc::CLI::Fetch.run("local-transmission")
+ described_class.run("local-transmission")
new_ctime = File.stat(download_stategy.cached_location).ctime
expect(old_ctime.to_i).to eq(new_ctime.to_i)
@@ -32,7 +38,7 @@ describe Hbc::CLI::Fetch, :cask do
old_ctime = File.stat(download_stategy.cached_location).ctime
sleep(1)
- Hbc::CLI::Fetch.run("local-transmission", "--force")
+ described_class.run("local-transmission", "--force")
download_stategy = Hbc::CurlDownloadStrategy.new(local_transmission)
new_ctime = File.stat(download_stategy.cached_location).ctime
@@ -41,23 +47,7 @@ describe Hbc::CLI::Fetch, :cask do
it "properly handles Casks that are not present" do
expect {
- Hbc::CLI::Fetch.run("notacask")
- }.to raise_error(Hbc::CaskError, "Fetch incomplete.")
- end
-
- describe "when no Cask is specified" do
- it "raises an exception" do
- expect {
- Hbc::CLI::Fetch.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::Fetch.run("--notavalidoption")
- }.to raise_error(/invalid option/)
- end
+ described_class.run("notacask")
+ }.to raise_error(Hbc::CaskUnavailableError)
end
end
diff --git a/Library/Homebrew/test/cask/cli/home_spec.rb b/Library/Homebrew/test/cask/cli/home_spec.rb
index e985fb6cd..8960d2acc 100644
--- a/Library/Homebrew/test/cask/cli/home_spec.rb
+++ b/Library/Homebrew/test/cask/cli/home_spec.rb
@@ -1,8 +1,12 @@
+require_relative "shared_examples/invalid_option"
+
describe Hbc::CLI::Home, :cask do
before do
allow(described_class).to receive(:open_url)
end
+ it_behaves_like "a command that handles invalid options"
+
it "opens the homepage for the specified Cask" do
expect(described_class).to receive(:open_url).with("http://example.com/local-caffeine")
described_class.run("local-caffeine")
diff --git a/Library/Homebrew/test/cask/cli/info_spec.rb b/Library/Homebrew/test/cask/cli/info_spec.rb
index bffe900ec..e24eead11 100644
--- a/Library/Homebrew/test/cask/cli/info_spec.rb
+++ b/Library/Homebrew/test/cask/cli/info_spec.rb
@@ -1,7 +1,13 @@
+require_relative "shared_examples/requires_cask_token"
+require_relative "shared_examples/invalid_option"
+
describe Hbc::CLI::Info, :cask do
+ it_behaves_like "a command that requires a Cask token"
+ it_behaves_like "a command that handles invalid options"
+
it "displays some nice info about the specified Cask" do
expect {
- Hbc::CLI::Info.run("local-caffeine")
+ described_class.run("local-caffeine")
}.to output(<<-EOS.undent).to_stdout
local-caffeine: 1.2.3
http://example.com/local-caffeine
@@ -10,7 +16,7 @@ describe Hbc::CLI::Info, :cask do
==> Name
None
==> Artifacts
- Caffeine.app (app)
+ Caffeine.app (App)
EOS
end
@@ -24,7 +30,7 @@ describe Hbc::CLI::Info, :cask do
==> Name
None
==> Artifacts
- Caffeine.app (app)
+ Caffeine.app (App)
local-transmission: 2.61
http://example.com/local-transmission
Not installed
@@ -32,26 +38,20 @@ describe Hbc::CLI::Info, :cask do
==> Name
None
==> Artifacts
- Transmission.app (app)
+ Transmission.app (App)
EOS
}
it "displays the info" do
expect {
- Hbc::CLI::Info.run("local-caffeine", "local-transmission")
+ described_class.run("local-caffeine", "local-transmission")
}.to output(expected_output).to_stdout
end
-
- it "throws away stray options" do
- expect {
- Hbc::CLI::Info.run("--notavalidoption", "local-caffeine", "local-transmission")
- }.to raise_error(/invalid option/)
- end
end
it "should print caveats if the Cask provided one" do
expect {
- Hbc::CLI::Info.run("with-caveats")
+ described_class.run("with-caveats")
}.to output(<<-EOS.undent).to_stdout
with-caveats: 1.2.3
http://example.com/local-caffeine
@@ -60,7 +60,7 @@ describe Hbc::CLI::Info, :cask do
==> Name
None
==> Artifacts
- Caffeine.app (app)
+ Caffeine.app (App)
==> Caveats
Here are some things you might want to know.
@@ -77,7 +77,7 @@ describe Hbc::CLI::Info, :cask do
it 'should not print "Caveats" section divider if the caveats block has no output' do
expect {
- Hbc::CLI::Info.run("with-conditional-caveats")
+ described_class.run("with-conditional-caveats")
}.to output(<<-EOS.undent).to_stdout
with-conditional-caveats: 1.2.3
http://example.com/local-caffeine
@@ -86,23 +86,39 @@ describe Hbc::CLI::Info, :cask do
==> Name
None
==> Artifacts
- Caffeine.app (app)
+ Caffeine.app (App)
EOS
end
- describe "when no Cask is specified" do
- it "raises an exception" do
- expect {
- Hbc::CLI::Info.run
- }.to raise_error(Hbc::CaskUnspecifiedError)
- end
+ it "prints languages specified in the Cask" do
+ expect {
+ described_class.run("with-languages")
+ }.to output(<<-EOS.undent).to_stdout
+ with-languages: 1.2.3
+ http://example.com/local-caffeine
+ Not installed
+ From: https://github.com/caskroom/homebrew-spec/blob/master/Casks/with-languages.rb
+ ==> Name
+ None
+ ==> Languages
+ zh, en-US
+ ==> Artifacts
+ Caffeine.app (App)
+ EOS
end
- describe "when no Cask is specified, but an invalid option" do
- it "raises an exception" do
- expect {
- Hbc::CLI::Info.run("--notavalidoption")
- }.to raise_error(/invalid option/)
- end
+ it 'does not print "Languages" section divider if the languages block has no output' do
+ expect {
+ described_class.run("without-languages")
+ }.to output(<<-EOS.undent).to_stdout
+ without-languages: 1.2.3
+ http://example.com/local-caffeine
+ Not installed
+ From: https://github.com/caskroom/homebrew-spec/blob/master/Casks/without-languages.rb
+ ==> Name
+ None
+ ==> Artifacts
+ Caffeine.app (App)
+ EOS
end
end
diff --git a/Library/Homebrew/test/cask/cli/install_spec.rb b/Library/Homebrew/test/cask/cli/install_spec.rb
index 64feacce9..c918a3529 100644
--- a/Library/Homebrew/test/cask/cli/install_spec.rb
+++ b/Library/Homebrew/test/cask/cli/install_spec.rb
@@ -1,4 +1,10 @@
+require_relative "shared_examples/requires_cask_token"
+require_relative "shared_examples/invalid_option"
+
describe Hbc::CLI::Install, :cask do
+ it_behaves_like "a command that requires a Cask token"
+ it_behaves_like "a command that handles invalid options"
+
it "displays the installation progress" do
output = Regexp.new <<-EOS.undent
==> Downloading file:.*caffeine.zip
@@ -9,103 +15,65 @@ describe Hbc::CLI::Install, :cask do
EOS
expect {
- Hbc::CLI::Install.run("local-caffeine")
+ described_class.run("local-caffeine")
}.to output(output).to_stdout
end
it "allows staging and activation of multiple Casks at once" do
- Hbc::CLI::Install.run("local-transmission", "local-caffeine")
+ described_class.run("local-transmission", "local-caffeine")
- expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed
+ expect(Hbc::CaskLoader.load(cask_path("local-transmission"))).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::CaskLoader.load(cask_path("local-caffeine"))).to be_installed
expect(Hbc.appdir.join("Caffeine.app")).to be_a_directory
end
it "skips double install (without nuking existing installation)" do
- Hbc::CLI::Install.run("local-transmission")
- Hbc::CLI::Install.run("local-transmission")
- expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed
+ described_class.run("local-transmission")
+ described_class.run("local-transmission")
+ expect(Hbc::CaskLoader.load(cask_path("local-transmission"))).to be_installed
end
it "prints a warning message on double install" do
- Hbc::CLI::Install.run("local-transmission")
+ described_class.run("local-transmission")
expect {
- Hbc::CLI::Install.run("local-transmission")
+ described_class.run("local-transmission")
}.to output(/Warning: Cask 'local-transmission' is already installed./).to_stderr
end
it "allows double install with --force" do
- Hbc::CLI::Install.run("local-transmission")
+ described_class.run("local-transmission")
expect {
expect {
- Hbc::CLI::Install.run("local-transmission", "--force")
+ described_class.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
- Hbc::CLI::Install.run("with-depends-on-cask-multiple", "--skip-cask-deps")
- 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
+ described_class.run("with-depends-on-cask-multiple", "--skip-cask-deps")
+ expect(Hbc::CaskLoader.load(cask_path("with-depends-on-cask-multiple"))).to be_installed
+ expect(Hbc::CaskLoader.load(cask_path("local-caffeine"))).not_to be_installed
+ expect(Hbc::CaskLoader.load(cask_path("local-transmission"))).not_to be_installed
end
it "properly handles Casks that are not present" do
expect {
- Hbc::CLI::Install.run("notacask")
- }.to raise_error(Hbc::CaskError, "Install incomplete.")
+ described_class.run("notacask")
+ }.to raise_error(Hbc::CaskUnavailableError)
end
it "returns a suggestion for a misspelled Cask" do
expect {
- begin
- Hbc::CLI::Install.run("localcaffeine")
- rescue Hbc::CaskError
- nil
- end
- }.to output(/Cask 'localcaffeine' is unavailable: No Cask with this name exists\. Did you mean:\nlocal-caffeine/).to_stderr
+ described_class.run("localcaffeine")
+ }.to raise_error(Hbc::CaskUnavailableError, /Cask 'localcaffeine' is unavailable: No Cask with this name exists\. Did you mean “local-caffeine”?/)
end
it "returns multiple suggestions for a Cask fragment" do
expect {
- begin
- Hbc::CLI::Install.run("local-caf")
- rescue Hbc::CaskError
- nil
- end
- }.to output(/Cask 'local-caf' is unavailable: No Cask with this name exists\. Did you mean one of:\nlocal-caffeine/).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
- it "raises an error" do
- expect {
- Hbc::CLI::Install.run("--notavalidoption")
- }.to raise_error(/invalid option/)
- end
- end
+ described_class.run("local")
+ }.to raise_error(Hbc::CaskUnavailableError, /Cask 'local' is unavailable: No Cask with this name exists\. Did you mean one of these\?\nlocal-caffeine\nlocal-transmission/)
end
end
diff --git a/Library/Homebrew/test/cask/cli/list_spec.rb b/Library/Homebrew/test/cask/cli/list_spec.rb
index ecca3035f..301ca9b89 100644
--- a/Library/Homebrew/test/cask/cli/list_spec.rb
+++ b/Library/Homebrew/test/cask/cli/list_spec.rb
@@ -1,4 +1,8 @@
+require_relative "shared_examples/invalid_option"
+
describe Hbc::CLI::List, :cask do
+ it_behaves_like "a command that handles invalid options"
+
it "lists the installed Casks in a pretty fashion" do
casks = %w[local-caffeine local-transmission].map { |c| Hbc::CaskLoader.load(c) }
@@ -7,10 +11,30 @@ describe Hbc::CLI::List, :cask do
end
expect {
- Hbc::CLI::List.run
+ described_class.run
+ }.to output(<<-EOS.undent).to_stdout
+ local-caffeine
+ local-transmission
+ EOS
+ end
+
+ it "lists full names" do
+ casks = %w[
+ local-caffeine
+ third-party/tap/third-party-cask
+ local-transmission
+ ].map { |c| Hbc::CaskLoader.load(c) }
+
+ casks.each do |c|
+ InstallHelper.install_with_caskfile(c)
+ end
+
+ expect {
+ described_class.run("--full-name")
}.to output(<<-EOS.undent).to_stdout
local-caffeine
local-transmission
+ third-party/tap/third-party-cask
EOS
end
@@ -29,29 +53,31 @@ describe Hbc::CLI::List, :cask do
it "of all installed Casks" do
expect {
- Hbc::CLI::List.run("--versions")
+ described_class.run("--versions")
}.to output(expected_output).to_stdout
end
it "of given Casks" do
expect {
- Hbc::CLI::List.run("--versions", "local-caffeine", "local-transmission")
+ described_class.run("--versions", "local-caffeine", "local-transmission")
}.to output(expected_output).to_stdout
end
end
describe "given a set of installed Casks" do
- let(:caffeine) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") }
- let(:transmission) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") }
+ let(:caffeine) { Hbc::CaskLoader.load(cask_path("local-caffeine")) }
+ let(:transmission) { Hbc::CaskLoader.load(cask_path("local-transmission")) }
let(:casks) { [caffeine, transmission] }
it "lists the installed files for those Casks" do
casks.each(&InstallHelper.method(:install_without_artifacts_with_caskfile))
- Hbc::Artifact::App.new(transmission).install_phase
+ transmission.artifacts.select { |a| a.is_a?(Hbc::Artifact::App) }.each do |artifact|
+ artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false)
+ end
expect {
- Hbc::CLI::List.run("local-transmission", "local-caffeine")
+ described_class.run("local-transmission", "local-caffeine")
}.to output(<<-EOS.undent).to_stdout
==> Apps
#{Hbc.appdir.join("Transmission.app")} (#{Hbc.appdir.join("Transmission.app").abv})
diff --git a/Library/Homebrew/test/cask/cli/options_spec.rb b/Library/Homebrew/test/cask/cli/options_spec.rb
index 98eb05f7e..82d830795 100644
--- a/Library/Homebrew/test/cask/cli/options_spec.rb
+++ b/Library/Homebrew/test/cask/cli/options_spec.rb
@@ -1,6 +1,6 @@
describe Hbc::CLI, :cask do
it "supports setting the appdir" do
- Hbc::CLI.new.process_options("help", "--appdir=/some/path/foo")
+ described_class.new.process_options("help", "--appdir=/some/path/foo")
expect(Hbc.appdir).to eq(Pathname.new("/some/path/foo"))
end
@@ -8,13 +8,13 @@ describe Hbc::CLI, :cask do
it "supports setting the appdir from ENV" do
ENV["HOMEBREW_CASK_OPTS"] = "--appdir=/some/path/bar"
- Hbc::CLI.new.process_options("help")
+ described_class.new.process_options("help")
expect(Hbc.appdir).to eq(Pathname.new("/some/path/bar"))
end
it "supports setting the prefpanedir" do
- Hbc::CLI.new.process_options("help", "--prefpanedir=/some/path/foo")
+ described_class.new.process_options("help", "--prefpanedir=/some/path/foo")
expect(Hbc.prefpanedir).to eq(Pathname.new("/some/path/foo"))
end
@@ -22,13 +22,13 @@ describe Hbc::CLI, :cask do
it "supports setting the prefpanedir from ENV" do
ENV["HOMEBREW_CASK_OPTS"] = "--prefpanedir=/some/path/bar"
- Hbc::CLI.new.process_options("help")
+ described_class.new.process_options("help")
expect(Hbc.prefpanedir).to eq(Pathname.new("/some/path/bar"))
end
it "supports setting the qlplugindir" do
- Hbc::CLI.new.process_options("help", "--qlplugindir=/some/path/foo")
+ described_class.new.process_options("help", "--qlplugindir=/some/path/foo")
expect(Hbc.qlplugindir).to eq(Pathname.new("/some/path/foo"))
end
@@ -36,13 +36,13 @@ describe Hbc::CLI, :cask do
it "supports setting the qlplugindir from ENV" do
ENV["HOMEBREW_CASK_OPTS"] = "--qlplugindir=/some/path/bar"
- Hbc::CLI.new.process_options("help")
+ described_class.new.process_options("help")
expect(Hbc.qlplugindir).to eq(Pathname.new("/some/path/bar"))
end
it "supports setting the colorpickerdir" do
- Hbc::CLI.new.process_options("help", "--colorpickerdir=/some/path/foo")
+ described_class.new.process_options("help", "--colorpickerdir=/some/path/foo")
expect(Hbc.colorpickerdir).to eq(Pathname.new("/some/path/foo"))
end
@@ -50,13 +50,13 @@ describe Hbc::CLI, :cask do
it "supports setting the colorpickerdir from ENV" do
ENV["HOMEBREW_CASK_OPTS"] = "--colorpickerdir=/some/path/bar"
- Hbc::CLI.new.process_options("help")
+ described_class.new.process_options("help")
expect(Hbc.colorpickerdir).to eq(Pathname.new("/some/path/bar"))
end
it "supports setting the dictionarydir" do
- Hbc::CLI.new.process_options("help", "--dictionarydir=/some/path/foo")
+ described_class.new.process_options("help", "--dictionarydir=/some/path/foo")
expect(Hbc.dictionarydir).to eq(Pathname.new("/some/path/foo"))
end
@@ -64,13 +64,13 @@ describe Hbc::CLI, :cask do
it "supports setting the dictionarydir from ENV" do
ENV["HOMEBREW_CASK_OPTS"] = "--dictionarydir=/some/path/bar"
- Hbc::CLI.new.process_options("help")
+ described_class.new.process_options("help")
expect(Hbc.dictionarydir).to eq(Pathname.new("/some/path/bar"))
end
it "supports setting the fontdir" do
- Hbc::CLI.new.process_options("help", "--fontdir=/some/path/foo")
+ described_class.new.process_options("help", "--fontdir=/some/path/foo")
expect(Hbc.fontdir).to eq(Pathname.new("/some/path/foo"))
end
@@ -78,13 +78,13 @@ describe Hbc::CLI, :cask do
it "supports setting the fontdir from ENV" do
ENV["HOMEBREW_CASK_OPTS"] = "--fontdir=/some/path/bar"
- Hbc::CLI.new.process_options("help")
+ described_class.new.process_options("help")
expect(Hbc.fontdir).to eq(Pathname.new("/some/path/bar"))
end
it "supports setting the servicedir" do
- Hbc::CLI.new.process_options("help", "--servicedir=/some/path/foo")
+ described_class.new.process_options("help", "--servicedir=/some/path/foo")
expect(Hbc.servicedir).to eq(Pathname.new("/some/path/foo"))
end
@@ -92,13 +92,13 @@ describe Hbc::CLI, :cask do
it "supports setting the servicedir from ENV" do
ENV["HOMEBREW_CASK_OPTS"] = "--servicedir=/some/path/bar"
- Hbc::CLI.new.process_options("help")
+ described_class.new.process_options("help")
expect(Hbc.servicedir).to eq(Pathname.new("/some/path/bar"))
end
it "allows additional options to be passed through" do
- rest = Hbc::CLI.new.process_options("edit", "foo", "--create", "--appdir=/some/path/qux")
+ rest = described_class.new.process_options("edit", "foo", "--create", "--appdir=/some/path/qux")
expect(Hbc.appdir).to eq(Pathname.new("/some/path/qux"))
expect(rest).to eq(%w[edit foo --create])
@@ -106,7 +106,7 @@ describe Hbc::CLI, :cask do
describe "--help" do
it "sets the Cask help method to true" do
- command = Hbc::CLI.new("foo", "--help")
+ command = described_class.new("foo", "--help")
expect(command.help?).to be true
end
end
diff --git a/Library/Homebrew/test/cask/cli/outdated_spec.rb b/Library/Homebrew/test/cask/cli/outdated_spec.rb
index 946092f89..5bbf18d21 100644
--- a/Library/Homebrew/test/cask/cli/outdated_spec.rb
+++ b/Library/Homebrew/test/cask/cli/outdated_spec.rb
@@ -1,11 +1,13 @@
+require_relative "shared_examples/invalid_option"
+
describe Hbc::CLI::Outdated, :cask do
let(:installed) do
[
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb"),
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/outdated/local-caffeine.rb"),
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/outdated/local-transmission.rb"),
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/version-latest-string.rb"),
- Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/outdated/auto-updates.rb"),
+ Hbc::CaskLoader.load(cask_path("basic-cask")),
+ Hbc::CaskLoader.load(cask_path("outdated/local-caffeine")),
+ Hbc::CaskLoader.load(cask_path("outdated/local-transmission")),
+ Hbc::CaskLoader.load(cask_path("version-latest-string")),
+ Hbc::CaskLoader.load(cask_path("outdated/auto-updates")),
]
end
@@ -15,6 +17,8 @@ describe Hbc::CLI::Outdated, :cask do
allow_any_instance_of(described_class).to receive(:verbose?).and_return(true)
end
+ it_behaves_like "a command that handles invalid options"
+
describe 'without --greedy it ignores the Casks with "vesion latest" or "auto_updates true"' do
it "checks all the installed Casks when no token is provided" do
expect {
@@ -70,7 +74,7 @@ describe Hbc::CLI::Outdated, :cask do
end
it 'does not include the Casks with "auto_updates true" when the version did not change' do
- cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/auto-updates.rb")
+ cask = Hbc::CaskLoader.load(cask_path("auto-updates"))
InstallHelper.install_with_caskfile(cask)
expect {
diff --git a/Library/Homebrew/test/cask/cli/reinstall_spec.rb b/Library/Homebrew/test/cask/cli/reinstall_spec.rb
index 3a9c3e2f5..95294b695 100644
--- a/Library/Homebrew/test/cask/cli/reinstall_spec.rb
+++ b/Library/Homebrew/test/cask/cli/reinstall_spec.rb
@@ -1,6 +1,10 @@
+require_relative "shared_examples/invalid_option"
+
describe Hbc::CLI::Reinstall, :cask do
+ it_behaves_like "a command that handles invalid options"
+
it "displays the reinstallation progress" do
- caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")
+ caffeine = Hbc::CaskLoader.load(cask_path("local-caffeine"))
Hbc::Installer.new(caffeine).install
@@ -23,16 +27,16 @@ describe Hbc::CLI::Reinstall, :cask do
it "allows reinstalling a Cask" do
Hbc::CLI::Install.run("local-transmission")
- expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed
+ expect(Hbc::CaskLoader.load(cask_path("local-transmission"))).to be_installed
Hbc::CLI::Reinstall.run("local-transmission")
- expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed
+ expect(Hbc::CaskLoader.load(cask_path("local-transmission"))).to be_installed
end
it "allows reinstalling a non installed Cask" do
- expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).not_to be_installed
+ expect(Hbc::CaskLoader.load(cask_path("local-transmission"))).not_to be_installed
Hbc::CLI::Reinstall.run("local-transmission")
- expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed
+ expect(Hbc::CaskLoader.load(cask_path("local-transmission"))).to be_installed
end
end
diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb
index e237ad464..a4f796f3c 100644
--- a/Library/Homebrew/test/cask/cli/search_spec.rb
+++ b/Library/Homebrew/test/cask/cli/search_spec.rb
@@ -1,9 +1,15 @@
+require_relative "shared_examples/invalid_option"
+
describe Hbc::CLI::Search, :cask do
before(:each) do
allow(Tty).to receive(:width).and_return(0)
end
+ it_behaves_like "a command that handles invalid options"
+
it "lists the available Casks that match the search term" do
+ allow(GitHub).to receive(:search_code).and_return([])
+
expect {
Hbc::CLI::Search.run("local")
}.to output(<<-EOS.undent).to_stdout.as_tty
@@ -14,24 +20,47 @@ describe Hbc::CLI::Search, :cask do
end
it "outputs a plain list when stdout is not a TTY" do
+ allow(GitHub).to receive(:search_code).and_return([])
+
+ expect {
+ Hbc::CLI::Search.run("local")
+ }.to output(<<-EOS.undent).to_stdout
+ local-caffeine
+ local-transmission
+ EOS
+ end
+
+ it "returns matches even when online search failed" do
+ allow(GitHub).to receive(:search_code).and_raise(GitHub::Error.new("reason"))
+
expect {
Hbc::CLI::Search.run("local")
}.to output(<<-EOS.undent).to_stdout
local-caffeine
local-transmission
EOS
+ .and output(/^Warning: Error searching on GitHub: reason/).to_stderr
end
it "shows that there are no Casks matching a search term that did not result in anything" do
expect {
Hbc::CLI::Search.run("foo-bar-baz")
- }.to output("No Cask found for \"foo-bar-baz\".\n").to_stdout.as_tty
+ }.to output(<<-EOS.undent).to_stdout.as_tty
+ No Cask found for "foo-bar-baz".
+ EOS
end
- it "lists all available Casks with no search term" do
- expect {
- Hbc::CLI::Search.run
- }.to output(/local-caffeine/).to_stdout.as_tty
+ it "doesn't output anything to non-TTY stdout when there are no matches" do
+ expect { Hbc::CLI::Search.run("foo-bar-baz") }
+ .to not_to_output.to_stdout
+ .and not_to_output.to_stderr
+ end
+
+ it "lists all Casks available offline with no search term" do
+ allow(GitHub).to receive(:search_code).and_raise(GitHub::Error.new("reason"))
+ expect { Hbc::CLI::Search.run }
+ .to output(/local-caffeine/).to_stdout.as_tty
+ .and not_to_output.to_stderr
end
it "ignores hyphens in search terms" do
@@ -55,19 +84,29 @@ describe Hbc::CLI::Search, :cask do
it "accepts a regexp argument" do
expect {
Hbc::CLI::Search.run("/^local-c[a-z]ffeine$/")
- }.to output("==> Regexp Matches\nlocal-caffeine\n").to_stdout.as_tty
+ }.to output(<<-EOS.undent).to_stdout.as_tty
+ ==> Regexp Matches
+ local-caffeine
+ EOS
end
- it "Returns both exact and partial matches" do
+ it "returns both exact and partial matches" do
expect {
Hbc::CLI::Search.run("test-opera")
- }.to output(/^==> Exact Match\ntest-opera\n==> Partial Matches\ntest-opera-mail/).to_stdout.as_tty
+ }.to output(<<-EOS.undent).to_stdout.as_tty
+ ==> Exact Match
+ test-opera
+ ==> Partial Matches
+ test-opera-mail
+ EOS
end
it "does not search the Tap name" do
expect {
Hbc::CLI::Search.run("caskroom")
- }.to output(/^No Cask found for "caskroom"\.\n/).to_stdout.as_tty
+ }.to output(<<-EOS.undent).to_stdout.as_tty
+ No Cask found for "caskroom".
+ EOS
end
it "doesn't highlight packages that aren't installed" do
diff --git a/Library/Homebrew/test/cask/cli/shared_examples/invalid_option.rb b/Library/Homebrew/test/cask/cli/shared_examples/invalid_option.rb
new file mode 100644
index 000000000..12a05be92
--- /dev/null
+++ b/Library/Homebrew/test/cask/cli/shared_examples/invalid_option.rb
@@ -0,0 +1,15 @@
+shared_examples "a command that handles invalid options" do
+ context "when an invalid option is specified" do
+ it "raises an exception when no Cask is specified" do
+ expect {
+ described_class.run("--not-a-valid-option")
+ }.to raise_error("invalid option: --not-a-valid-option")
+ end
+
+ it "raises an exception when a Cask is specified" do
+ expect {
+ described_class.run("--not-a-valid-option", "basic-cask")
+ }.to raise_error("invalid option: --not-a-valid-option")
+ end
+ end
+end
diff --git a/Library/Homebrew/test/cask/cli/shared_examples/requires_cask_token.rb b/Library/Homebrew/test/cask/cli/shared_examples/requires_cask_token.rb
new file mode 100644
index 000000000..dc1e471e5
--- /dev/null
+++ b/Library/Homebrew/test/cask/cli/shared_examples/requires_cask_token.rb
@@ -0,0 +1,9 @@
+shared_examples "a command that requires a Cask token" do
+ context "when no Cask is specified" do
+ it "raises an exception " do
+ expect {
+ described_class.run
+ }.to raise_error(Hbc::CaskUnspecifiedError, "This command requires a Cask token.")
+ end
+ end
+end
diff --git a/Library/Homebrew/test/cask/cli/style_spec.rb b/Library/Homebrew/test/cask/cli/style_spec.rb
index 2007b87d7..12cd348a0 100644
--- a/Library/Homebrew/test/cask/cli/style_spec.rb
+++ b/Library/Homebrew/test/cask/cli/style_spec.rb
@@ -1,11 +1,13 @@
require "open3"
require "rubygems"
+require_relative "shared_examples/invalid_option"
+
describe Hbc::CLI::Style, :cask do
let(:args) { [] }
let(:cli) { described_class.new(*args) }
- around(&:run)
+ it_behaves_like "a command that handles invalid options"
describe "#run" do
subject { cli.run }
diff --git a/Library/Homebrew/test/cask/cli/uninstall_spec.rb b/Library/Homebrew/test/cask/cli/uninstall_spec.rb
index 1a1c57e88..80b7edbd3 100644
--- a/Library/Homebrew/test/cask/cli/uninstall_spec.rb
+++ b/Library/Homebrew/test/cask/cli/uninstall_spec.rb
@@ -1,6 +1,12 @@
+require_relative "shared_examples/requires_cask_token"
+require_relative "shared_examples/invalid_option"
+
describe Hbc::CLI::Uninstall, :cask do
+ it_behaves_like "a command that requires a Cask token"
+ it_behaves_like "a command that handles invalid options"
+
it "displays the uninstallation progress" do
- caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")
+ caffeine = Hbc::CaskLoader.load(cask_path("local-caffeine"))
Hbc::Installer.new(caffeine).install
@@ -10,31 +16,29 @@ describe Hbc::CLI::Uninstall, :cask do
EOS
expect {
- Hbc::CLI::Uninstall.run("local-caffeine")
+ described_class.run("local-caffeine")
}.to output(output).to_stdout
end
it "shows an error when a bad Cask is provided" do
- expect { Hbc::CLI::Uninstall.run("notacask") }
- .to output(/is unavailable/).to_stderr
- .and raise_error(Hbc::CaskError, "Uninstall incomplete.")
+ expect { described_class.run("notacask") }
+ .to raise_error(Hbc::CaskUnavailableError, /is unavailable/)
end
it "shows an error when a Cask is provided that's not installed" do
- expect { Hbc::CLI::Uninstall.run("local-caffeine") }
- .to output(/is not installed/).to_stderr
- .and raise_error(Hbc::CaskError, "Uninstall incomplete.")
+ expect { described_class.run("local-caffeine") }
+ .to raise_error(Hbc::CaskNotInstalledError, /is not installed/)
end
it "tries anyway on a non-present Cask when --force is given" do
expect {
- Hbc::CLI::Uninstall.run("local-caffeine", "--force")
+ described_class.run("local-caffeine", "--force")
}.not_to raise_error
end
it "can uninstall 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")
+ caffeine = Hbc::CaskLoader.load(cask_path("local-caffeine"))
+ transmission = Hbc::CaskLoader.load(cask_path("local-transmission"))
Hbc::Installer.new(caffeine).install
Hbc::Installer.new(transmission).install
@@ -42,7 +46,7 @@ describe Hbc::CLI::Uninstall, :cask do
expect(caffeine).to be_installed
expect(transmission).to be_installed
- Hbc::CLI::Uninstall.run("local-caffeine", "local-transmission")
+ described_class.run("local-caffeine", "local-transmission")
expect(caffeine).not_to be_installed
expect(Hbc.appdir.join("Transmission.app")).not_to exist
@@ -51,7 +55,7 @@ describe Hbc::CLI::Uninstall, :cask do
end
it "calls `uninstall` before removing artifacts" do
- cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-script-app.rb")
+ cask = Hbc::CaskLoader.load(cask_path("with-uninstall-script-app"))
Hbc::Installer.new(cask).install
@@ -59,7 +63,7 @@ describe Hbc::CLI::Uninstall, :cask do
expect(Hbc.appdir.join("MyFancyApp.app")).to exist
expect {
- Hbc::CLI::Uninstall.run("with-uninstall-script-app")
+ described_class.run("with-uninstall-script-app")
}.not_to raise_error
expect(cask).not_to be_installed
@@ -67,7 +71,7 @@ describe Hbc::CLI::Uninstall, :cask do
end
it "can uninstall Casks when the uninstall script is missing, but only when using `--force`" do
- cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-script-app.rb")
+ cask = Hbc::CaskLoader.load(cask_path("with-uninstall-script-app"))
Hbc::Installer.new(cask).install
@@ -75,14 +79,13 @@ describe Hbc::CLI::Uninstall, :cask do
Hbc.appdir.join("MyFancyApp.app").rmtree
- expect { Hbc::CLI::Uninstall.run("with-uninstall-script-app") }
- .to output(/does not exist/).to_stderr
- .and raise_error(Hbc::CaskError, "Uninstall incomplete.")
+ expect { described_class.run("with-uninstall-script-app") }
+ .to raise_error(Hbc::CaskError, /uninstall script .* does not exist/)
expect(cask).to be_installed
expect {
- Hbc::CLI::Uninstall.run("with-uninstall-script-app", "--force")
+ described_class.run("with-uninstall-script-app", "--force")
}.not_to raise_error
expect(cask).not_to be_installed
@@ -115,13 +118,13 @@ describe Hbc::CLI::Uninstall, :cask do
end
it "uninstalls one version at a time" do
- Hbc::CLI::Uninstall.run("versioned-cask")
+ described_class.run("versioned-cask")
expect(caskroom_path.join(first_installed_version)).to exist
expect(caskroom_path.join(last_installed_version)).not_to exist
expect(caskroom_path).to exist
- Hbc::CLI::Uninstall.run("versioned-cask")
+ described_class.run("versioned-cask")
expect(caskroom_path.join(first_installed_version)).not_to exist
expect(caskroom_path).not_to exist
@@ -130,7 +133,7 @@ describe Hbc::CLI::Uninstall, :cask do
it "displays a message when versions remain installed" do
expect {
expect {
- Hbc::CLI::Uninstall.run("versioned-cask")
+ described_class.run("versioned-cask")
}.not_to output.to_stderr
}.to output(/#{token} #{first_installed_version} is still installed./).to_stdout
end
@@ -160,26 +163,10 @@ describe Hbc::CLI::Uninstall, :cask do
end
it "can still uninstall those Casks" do
- Hbc::CLI::Uninstall.run("ive-been-renamed")
+ described_class.run("ive-been-renamed")
expect(app).not_to exist
expect(caskroom_path).not_to exist
end
end
-
- describe "when no Cask is specified" do
- it "raises an exception" do
- expect {
- Hbc::CLI::Uninstall.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::Uninstall.run("--notavalidoption")
- }.to raise_error(/invalid option/)
- end
- end
end
diff --git a/Library/Homebrew/test/cask/cli/zap_spec.rb b/Library/Homebrew/test/cask/cli/zap_spec.rb
index fdc5b4125..05c882854 100644
--- a/Library/Homebrew/test/cask/cli/zap_spec.rb
+++ b/Library/Homebrew/test/cask/cli/zap_spec.rb
@@ -1,13 +1,18 @@
+require_relative "shared_examples/requires_cask_token"
+require_relative "shared_examples/invalid_option"
+
describe Hbc::CLI::Zap, :cask do
+ it_behaves_like "a command that requires a Cask token"
+ it_behaves_like "a command that handles invalid options"
+
it "shows an error when a bad Cask is provided" do
- expect { Hbc::CLI::Zap.run("notacask") }
- .to output(/is unavailable/).to_stderr
- .and raise_error(Hbc::CaskError, "Zap incomplete.")
+ expect { described_class.run("notacask") }
+ .to raise_error(Hbc::CaskUnavailableError, /is unavailable/)
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")
+ caffeine = Hbc::CaskLoader.load(cask_path("local-caffeine"))
+ transmission = Hbc::CaskLoader.load(cask_path("local-transmission"))
Hbc::Installer.new(caffeine).install
Hbc::Installer.new(transmission).install
@@ -15,7 +20,7 @@ describe Hbc::CLI::Zap, :cask do
expect(caffeine).to be_installed
expect(transmission).to be_installed
- Hbc::CLI::Zap.run("local-caffeine", "local-transmission")
+ described_class.run("local-caffeine", "local-transmission")
expect(caffeine).not_to be_installed
expect(Hbc.appdir.join("Caffeine.app")).not_to be_a_symlink
@@ -46,20 +51,4 @@ describe Hbc::CLI::Zap, :cask do
#
# 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(/invalid option/)
- end
- end
end