Refactor cask/cli specs.

This commit is contained in:
Markus Reiter 2017-10-03 10:49:58 +02:00
parent ec0d8fa7ba
commit 643b2a168c
22 changed files with 178 additions and 228 deletions

View File

@ -32,6 +32,7 @@ Metrics/ParameterLists:
Style/BlockDelimiters: Style/BlockDelimiters:
Exclude: Exclude:
- '**/*_spec.rb' - '**/*_spec.rb'
- '**/shared_examples/**/*.rb'
# so many of these in formulae but none in here # so many of these in formulae but none in here
Style/GuardClause: Style/GuardClause:

View File

@ -1,6 +1,10 @@
require_relative "shared_examples/invalid_option"
describe Hbc::CLI::Audit, :cask do describe Hbc::CLI::Audit, :cask do
let(:cask) { Hbc::Cask.new(nil) } let(:cask) { Hbc::Cask.new(nil) }
it_behaves_like "a command that handles invalid options"
describe "selection of Casks to audit" do describe "selection of Casks to audit" do
it "audits all Casks if no tokens are given" do it "audits all Casks if no tokens are given" do
expect(cask).to be_a Hbc::Cask expect(cask).to be_a Hbc::Cask
@ -9,7 +13,7 @@ describe Hbc::CLI::Audit, :cask do
expect(Hbc::Auditor).to receive(:audit).twice.and_return(true) expect(Hbc::Auditor).to receive(:audit).twice.and_return(true)
Hbc::CLI::Audit.run described_class.run
end end
it "audits specified Casks if tokens are given" do it "audits specified Casks if tokens are given" do
@ -20,7 +24,7 @@ describe Hbc::CLI::Audit, :cask do
.with(cask, audit_download: false, check_token_conflicts: false) .with(cask, audit_download: false, check_token_conflicts: false)
.and_return(true) .and_return(true)
Hbc::CLI::Audit.run(cask_token) described_class.run(cask_token)
end end
end end
@ -31,7 +35,7 @@ describe Hbc::CLI::Audit, :cask do
.with(cask, audit_download: false, check_token_conflicts: false) .with(cask, audit_download: false, check_token_conflicts: false)
.and_return(true) .and_return(true)
Hbc::CLI::Audit.run("casktoken") described_class.run("casktoken")
end end
it "download a Cask if --download flag is set" do it "download a Cask if --download flag is set" do
@ -40,7 +44,7 @@ describe Hbc::CLI::Audit, :cask do
.with(cask, audit_download: true, check_token_conflicts: false) .with(cask, audit_download: true, check_token_conflicts: false)
.and_return(true) .and_return(true)
Hbc::CLI::Audit.run("casktoken", "--download") described_class.run("casktoken", "--download")
end end
end end
@ -51,7 +55,7 @@ describe Hbc::CLI::Audit, :cask do
.with(cask, audit_download: false, check_token_conflicts: false) .with(cask, audit_download: false, check_token_conflicts: false)
.and_return(true) .and_return(true)
Hbc::CLI::Audit.run("casktoken") described_class.run("casktoken")
end end
it "checks for token conflicts if --token-conflicts flag is set" do it "checks for token conflicts if --token-conflicts flag is set" do
@ -60,7 +64,7 @@ describe Hbc::CLI::Audit, :cask do
.with(cask, audit_download: false, check_token_conflicts: true) .with(cask, audit_download: false, check_token_conflicts: true)
.and_return(true) .and_return(true)
Hbc::CLI::Audit.run("casktoken", "--token-conflicts") described_class.run("casktoken", "--token-conflicts")
end end
end end
end end

View File

@ -1,4 +1,10 @@
require_relative "shared_examples/requires_cask_token"
require_relative "shared_examples/invalid_option"
describe Hbc::CLI::Cat, :cask do 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 describe "given a basic Cask" do
let(:basic_cask_content) { let(:basic_cask_content) {
<<-EOS.undent <<-EOS.undent
@ -16,41 +22,19 @@ describe Hbc::CLI::Cat, :cask do
it "displays the Cask file content about the specified Cask" do it "displays the Cask file content about the specified Cask" do
expect { expect {
Hbc::CLI::Cat.run("basic-cask") described_class.run("basic-cask")
}.to output(basic_cask_content).to_stdout }.to output(basic_cask_content).to_stdout
end end
it "can display multiple Casks" do it "can display multiple Casks" do
expect { expect {
Hbc::CLI::Cat.run("basic-cask", "basic-cask") described_class.run("basic-cask", "basic-cask")
}.to output(basic_cask_content * 2).to_stdout }.to output(basic_cask_content * 2).to_stdout
end end
it "fails when option is unknown" do
expect {
Hbc::CLI::Cat.run("--notavalidoption", "basic-cask")
}.to raise_error(/invalid option/)
end
end end
it "raises an exception when the Cask does not exist" do it "raises an exception when the Cask does not exist" do
expect { Hbc::CLI::Cat.run("notacask") } expect { described_class.run("notacask") }
.to raise_error(Hbc::CaskUnavailableError, /is unavailable/) .to raise_error(Hbc::CaskUnavailableError, /is unavailable/)
end 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
end
end end

View File

@ -1,3 +1,5 @@
require_relative "shared_examples/invalid_option"
describe Hbc::CLI::Cleanup, :cask do describe Hbc::CLI::Cleanup, :cask do
let(:cache_location) { Pathname.new(Dir.mktmpdir).realpath } let(:cache_location) { Pathname.new(Dir.mktmpdir).realpath }
let(:outdated_only) { false } let(:outdated_only) { false }
@ -12,6 +14,8 @@ describe Hbc::CLI::Cleanup, :cask do
cache_location.rmtree cache_location.rmtree
end end
it_behaves_like "a command that handles invalid options"
describe "cleanup" do describe "cleanup" do
let(:cask_token) { "caffeine" } let(:cask_token) { "caffeine" }
let(:cask_tokens) { [cask_token] } let(:cask_tokens) { [cask_token] }

View File

@ -1,3 +1,6 @@
require_relative "shared_examples/requires_cask_token"
require_relative "shared_examples/invalid_option"
describe Hbc::CLI::Create, :cask do describe Hbc::CLI::Create, :cask do
around(:each) do |example| around(:each) do |example|
begin begin
@ -13,6 +16,9 @@ describe Hbc::CLI::Create, :cask do
allow_any_instance_of(described_class).to receive(:exec_editor) allow_any_instance_of(described_class).to receive(:exec_editor)
end 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 it "opens the editor for the specified Cask" do
command = described_class.new("new-cask") command = described_class.new("new-cask")
expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("new-cask")) expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("new-cask"))
@ -53,26 +59,4 @@ describe Hbc::CLI::Create, :cask do
expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("local-caff")) expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("local-caff"))
command.run command.run
end 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 end

View File

@ -1,4 +1,8 @@
require_relative "shared_examples/invalid_option"
describe Hbc::CLI::Doctor, :cask do describe Hbc::CLI::Doctor, :cask do
it_behaves_like "a command that handles invalid options"
it "displays some nice info about the environment" do it "displays some nice info about the environment" do
expect { expect {
Hbc::CLI::Doctor.run Hbc::CLI::Doctor.run

View File

@ -1,8 +1,14 @@
require_relative "shared_examples/requires_cask_token"
require_relative "shared_examples/invalid_option"
describe Hbc::CLI::Edit, :cask do describe Hbc::CLI::Edit, :cask do
before(:each) do before(:each) do
allow_any_instance_of(described_class).to receive(:exec_editor) allow_any_instance_of(described_class).to receive(:exec_editor)
end 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 it "opens the editor for the specified Cask" do
command = described_class.new("local-caffeine") command = described_class.new("local-caffeine")
expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("local-caffeine")) expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("local-caffeine"))
@ -20,20 +26,4 @@ describe Hbc::CLI::Edit, :cask do
described_class.run("notacask") described_class.run("notacask")
}.to raise_error(Hbc::CaskUnavailableError) }.to raise_error(Hbc::CaskUnavailableError)
end 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 end

View File

@ -1,3 +1,6 @@
require_relative "shared_examples/requires_cask_token"
require_relative "shared_examples/invalid_option"
describe Hbc::CLI::Fetch, :cask do describe Hbc::CLI::Fetch, :cask do
let(:local_transmission) { let(:local_transmission) {
Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")
@ -7,8 +10,11 @@ describe Hbc::CLI::Fetch, :cask do
Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")
} }
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 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_transmission).cached_location).to exist
expect(Hbc::CurlDownloadStrategy.new(local_caffeine).cached_location).to exist expect(Hbc::CurlDownloadStrategy.new(local_caffeine).cached_location).to exist
end end
@ -19,7 +25,7 @@ describe Hbc::CLI::Fetch, :cask do
Hbc::Download.new(local_transmission).perform Hbc::Download.new(local_transmission).perform
old_ctime = File.stat(download_stategy.cached_location).ctime 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 new_ctime = File.stat(download_stategy.cached_location).ctime
expect(old_ctime.to_i).to eq(new_ctime.to_i) 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 old_ctime = File.stat(download_stategy.cached_location).ctime
sleep(1) sleep(1)
Hbc::CLI::Fetch.run("local-transmission", "--force") described_class.run("local-transmission", "--force")
download_stategy = Hbc::CurlDownloadStrategy.new(local_transmission) download_stategy = Hbc::CurlDownloadStrategy.new(local_transmission)
new_ctime = File.stat(download_stategy.cached_location).ctime 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 it "properly handles Casks that are not present" do
expect { expect {
Hbc::CLI::Fetch.run("notacask") described_class.run("notacask")
}.to raise_error(Hbc::CaskUnavailableError) }.to raise_error(Hbc::CaskUnavailableError)
end 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
end
end end

View File

@ -1,8 +1,12 @@
require_relative "shared_examples/invalid_option"
describe Hbc::CLI::Home, :cask do describe Hbc::CLI::Home, :cask do
before do before do
allow(described_class).to receive(:open_url) allow(described_class).to receive(:open_url)
end end
it_behaves_like "a command that handles invalid options"
it "opens the homepage for the specified Cask" do it "opens the homepage for the specified Cask" do
expect(described_class).to receive(:open_url).with("http://example.com/local-caffeine") expect(described_class).to receive(:open_url).with("http://example.com/local-caffeine")
described_class.run("local-caffeine") described_class.run("local-caffeine")

View File

@ -1,7 +1,13 @@
require_relative "shared_examples/requires_cask_token"
require_relative "shared_examples/invalid_option"
describe Hbc::CLI::Info, :cask do 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 it "displays some nice info about the specified Cask" do
expect { expect {
Hbc::CLI::Info.run("local-caffeine") described_class.run("local-caffeine")
}.to output(<<-EOS.undent).to_stdout }.to output(<<-EOS.undent).to_stdout
local-caffeine: 1.2.3 local-caffeine: 1.2.3
http://example.com/local-caffeine http://example.com/local-caffeine
@ -38,20 +44,14 @@ describe Hbc::CLI::Info, :cask do
it "displays the info" do it "displays the info" do
expect { expect {
Hbc::CLI::Info.run("local-caffeine", "local-transmission") described_class.run("local-caffeine", "local-transmission")
}.to output(expected_output).to_stdout }.to output(expected_output).to_stdout
end end
it "throws away stray options" do
expect {
Hbc::CLI::Info.run("--notavalidoption", "local-caffeine", "local-transmission")
}.to raise_error(/invalid option/)
end
end end
it "should print caveats if the Cask provided one" do it "should print caveats if the Cask provided one" do
expect { expect {
Hbc::CLI::Info.run("with-caveats") described_class.run("with-caveats")
}.to output(<<-EOS.undent).to_stdout }.to output(<<-EOS.undent).to_stdout
with-caveats: 1.2.3 with-caveats: 1.2.3
http://example.com/local-caffeine http://example.com/local-caffeine
@ -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 it 'should not print "Caveats" section divider if the caveats block has no output' do
expect { expect {
Hbc::CLI::Info.run("with-conditional-caveats") described_class.run("with-conditional-caveats")
}.to output(<<-EOS.undent).to_stdout }.to output(<<-EOS.undent).to_stdout
with-conditional-caveats: 1.2.3 with-conditional-caveats: 1.2.3
http://example.com/local-caffeine http://example.com/local-caffeine
@ -92,7 +92,7 @@ describe Hbc::CLI::Info, :cask do
it "prints languages specified in the Cask" do it "prints languages specified in the Cask" do
expect { expect {
Hbc::CLI::Info.run("with-languages") described_class.run("with-languages")
}.to output(<<-EOS.undent).to_stdout }.to output(<<-EOS.undent).to_stdout
with-languages: 1.2.3 with-languages: 1.2.3
http://example.com/local-caffeine http://example.com/local-caffeine
@ -109,7 +109,7 @@ describe Hbc::CLI::Info, :cask do
it 'does not print "Languages" section divider if the languages block has no output' do it 'does not print "Languages" section divider if the languages block has no output' do
expect { expect {
Hbc::CLI::Info.run("without-languages") described_class.run("without-languages")
}.to output(<<-EOS.undent).to_stdout }.to output(<<-EOS.undent).to_stdout
without-languages: 1.2.3 without-languages: 1.2.3
http://example.com/local-caffeine http://example.com/local-caffeine
@ -121,20 +121,4 @@ describe Hbc::CLI::Info, :cask do
Caffeine.app (App) Caffeine.app (App)
EOS EOS
end end
describe "when no Cask is specified" do
it "raises an exception" do
expect {
Hbc::CLI::Info.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::Info.run("--notavalidoption")
}.to raise_error(/invalid option/)
end
end
end end

View File

@ -1,4 +1,10 @@
require_relative "shared_examples/requires_cask_token"
require_relative "shared_examples/invalid_option"
describe Hbc::CLI::Install, :cask do 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 it "displays the installation progress" do
output = Regexp.new <<-EOS.undent output = Regexp.new <<-EOS.undent
==> Downloading file:.*caffeine.zip ==> Downloading file:.*caffeine.zip
@ -9,12 +15,12 @@ describe Hbc::CLI::Install, :cask do
EOS EOS
expect { expect {
Hbc::CLI::Install.run("local-caffeine") described_class.run("local-caffeine")
}.to output(output).to_stdout }.to output(output).to_stdout
end end
it "allows staging and activation of multiple Casks at once" do 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_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.appdir.join("Transmission.app")).to be_a_directory
@ -23,31 +29,31 @@ describe Hbc::CLI::Install, :cask do
end end
it "skips double install (without nuking existing installation)" do it "skips double install (without nuking existing installation)" do
Hbc::CLI::Install.run("local-transmission") described_class.run("local-transmission")
Hbc::CLI::Install.run("local-transmission") described_class.run("local-transmission")
expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to 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
Hbc::CLI::Install.run("local-transmission") described_class.run("local-transmission")
expect { expect {
Hbc::CLI::Install.run("local-transmission") described_class.run("local-transmission")
}.to output(/Warning: Cask 'local-transmission' is already installed./).to_stderr }.to output(/Warning: Cask 'local-transmission' is already installed./).to_stderr
end end
it "allows double install with --force" do it "allows double install with --force" do
Hbc::CLI::Install.run("local-transmission") described_class.run("local-transmission")
expect { expect {
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(/It seems there is already an App at.*overwriting\./).to_stderr
}.to output(/local-transmission was successfully installed!/).to_stdout }.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
Hbc::CLI::Install.run("with-depends-on-cask-multiple", "--skip-cask-deps") described_class.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/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-caffeine.rb")).not_to be_installed
expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).not_to be_installed expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).not_to be_installed
@ -55,49 +61,19 @@ describe Hbc::CLI::Install, :cask do
it "properly handles Casks that are not present" do it "properly handles Casks that are not present" do
expect { expect {
Hbc::CLI::Install.run("notacask") described_class.run("notacask")
}.to raise_error(Hbc::CaskUnavailableError) }.to raise_error(Hbc::CaskUnavailableError)
end end
it "returns a suggestion for a misspelled Cask" do it "returns a suggestion for a misspelled Cask" do
expect { expect {
Hbc::CLI::Install.run("localcaffeine") described_class.run("localcaffeine")
}.to raise_error(Hbc::CaskUnavailableError, /Cask 'localcaffeine' is unavailable: No Cask with this name exists\. Did you mean “local-caffeine”?/) }.to raise_error(Hbc::CaskUnavailableError, /Cask 'localcaffeine' is unavailable: No Cask with this name exists\. Did you mean “local-caffeine”?/)
end end
it "returns multiple suggestions for a Cask fragment" do it "returns multiple suggestions for a Cask fragment" do
expect { expect {
Hbc::CLI::Install.run("local") 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/) }.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
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
end
end end

View File

@ -1,4 +1,8 @@
require_relative "shared_examples/invalid_option"
describe Hbc::CLI::List, :cask do 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 it "lists the installed Casks in a pretty fashion" do
casks = %w[local-caffeine local-transmission].map { |c| Hbc::CaskLoader.load(c) } casks = %w[local-caffeine local-transmission].map { |c| Hbc::CaskLoader.load(c) }
@ -7,7 +11,7 @@ describe Hbc::CLI::List, :cask do
end end
expect { expect {
Hbc::CLI::List.run described_class.run
}.to output(<<-EOS.undent).to_stdout }.to output(<<-EOS.undent).to_stdout
local-caffeine local-caffeine
local-transmission local-transmission
@ -26,7 +30,7 @@ describe Hbc::CLI::List, :cask do
end end
expect { expect {
Hbc::CLI::List.run("--full-name") described_class.run("--full-name")
}.to output(<<-EOS.undent).to_stdout }.to output(<<-EOS.undent).to_stdout
local-caffeine local-caffeine
local-transmission local-transmission
@ -49,13 +53,13 @@ describe Hbc::CLI::List, :cask do
it "of all installed Casks" do it "of all installed Casks" do
expect { expect {
Hbc::CLI::List.run("--versions") described_class.run("--versions")
}.to output(expected_output).to_stdout }.to output(expected_output).to_stdout
end end
it "of given Casks" do it "of given Casks" do
expect { expect {
Hbc::CLI::List.run("--versions", "local-caffeine", "local-transmission") described_class.run("--versions", "local-caffeine", "local-transmission")
}.to output(expected_output).to_stdout }.to output(expected_output).to_stdout
end end
end end
@ -72,7 +76,7 @@ describe Hbc::CLI::List, :cask do
.each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) }
expect { expect {
Hbc::CLI::List.run("local-transmission", "local-caffeine") described_class.run("local-transmission", "local-caffeine")
}.to output(<<-EOS.undent).to_stdout }.to output(<<-EOS.undent).to_stdout
==> Apps ==> Apps
#{Hbc.appdir.join("Transmission.app")} (#{Hbc.appdir.join("Transmission.app").abv}) #{Hbc.appdir.join("Transmission.app")} (#{Hbc.appdir.join("Transmission.app").abv})

View File

@ -1,6 +1,6 @@
describe Hbc::CLI, :cask do describe Hbc::CLI, :cask do
it "supports setting the appdir" 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")) expect(Hbc.appdir).to eq(Pathname.new("/some/path/foo"))
end end
@ -8,13 +8,13 @@ describe Hbc::CLI, :cask do
it "supports setting the appdir from ENV" do it "supports setting the appdir from ENV" do
ENV["HOMEBREW_CASK_OPTS"] = "--appdir=/some/path/bar" 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")) expect(Hbc.appdir).to eq(Pathname.new("/some/path/bar"))
end end
it "supports setting the prefpanedir" do 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")) expect(Hbc.prefpanedir).to eq(Pathname.new("/some/path/foo"))
end end
@ -22,13 +22,13 @@ describe Hbc::CLI, :cask do
it "supports setting the prefpanedir from ENV" do it "supports setting the prefpanedir from ENV" do
ENV["HOMEBREW_CASK_OPTS"] = "--prefpanedir=/some/path/bar" 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")) expect(Hbc.prefpanedir).to eq(Pathname.new("/some/path/bar"))
end end
it "supports setting the qlplugindir" do 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")) expect(Hbc.qlplugindir).to eq(Pathname.new("/some/path/foo"))
end end
@ -36,13 +36,13 @@ describe Hbc::CLI, :cask do
it "supports setting the qlplugindir from ENV" do it "supports setting the qlplugindir from ENV" do
ENV["HOMEBREW_CASK_OPTS"] = "--qlplugindir=/some/path/bar" 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")) expect(Hbc.qlplugindir).to eq(Pathname.new("/some/path/bar"))
end end
it "supports setting the colorpickerdir" do 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")) expect(Hbc.colorpickerdir).to eq(Pathname.new("/some/path/foo"))
end end
@ -50,13 +50,13 @@ describe Hbc::CLI, :cask do
it "supports setting the colorpickerdir from ENV" do it "supports setting the colorpickerdir from ENV" do
ENV["HOMEBREW_CASK_OPTS"] = "--colorpickerdir=/some/path/bar" 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")) expect(Hbc.colorpickerdir).to eq(Pathname.new("/some/path/bar"))
end end
it "supports setting the dictionarydir" do 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")) expect(Hbc.dictionarydir).to eq(Pathname.new("/some/path/foo"))
end end
@ -64,13 +64,13 @@ describe Hbc::CLI, :cask do
it "supports setting the dictionarydir from ENV" do it "supports setting the dictionarydir from ENV" do
ENV["HOMEBREW_CASK_OPTS"] = "--dictionarydir=/some/path/bar" 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")) expect(Hbc.dictionarydir).to eq(Pathname.new("/some/path/bar"))
end end
it "supports setting the fontdir" do 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")) expect(Hbc.fontdir).to eq(Pathname.new("/some/path/foo"))
end end
@ -78,13 +78,13 @@ describe Hbc::CLI, :cask do
it "supports setting the fontdir from ENV" do it "supports setting the fontdir from ENV" do
ENV["HOMEBREW_CASK_OPTS"] = "--fontdir=/some/path/bar" 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")) expect(Hbc.fontdir).to eq(Pathname.new("/some/path/bar"))
end end
it "supports setting the servicedir" do 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")) expect(Hbc.servicedir).to eq(Pathname.new("/some/path/foo"))
end end
@ -92,13 +92,13 @@ describe Hbc::CLI, :cask do
it "supports setting the servicedir from ENV" do it "supports setting the servicedir from ENV" do
ENV["HOMEBREW_CASK_OPTS"] = "--servicedir=/some/path/bar" 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")) expect(Hbc.servicedir).to eq(Pathname.new("/some/path/bar"))
end end
it "allows additional options to be passed through" do 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(Hbc.appdir).to eq(Pathname.new("/some/path/qux"))
expect(rest).to eq(%w[edit foo --create]) expect(rest).to eq(%w[edit foo --create])
@ -106,7 +106,7 @@ describe Hbc::CLI, :cask do
describe "--help" do describe "--help" do
it "sets the Cask help method to true" 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 expect(command.help?).to be true
end end
end end

View File

@ -1,3 +1,5 @@
require_relative "shared_examples/invalid_option"
describe Hbc::CLI::Outdated, :cask do describe Hbc::CLI::Outdated, :cask do
let(:installed) do let(:installed) do
[ [
@ -15,6 +17,8 @@ describe Hbc::CLI::Outdated, :cask do
allow_any_instance_of(described_class).to receive(:verbose?).and_return(true) allow_any_instance_of(described_class).to receive(:verbose?).and_return(true)
end 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 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 it "checks all the installed Casks when no token is provided" do
expect { expect {

View File

@ -1,4 +1,8 @@
require_relative "shared_examples/invalid_option"
describe Hbc::CLI::Reinstall, :cask do describe Hbc::CLI::Reinstall, :cask do
it_behaves_like "a command that handles invalid options"
it "displays the reinstallation progress" do it "displays the reinstallation progress" do
caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")

View File

@ -1,8 +1,12 @@
require_relative "shared_examples/invalid_option"
describe Hbc::CLI::Search, :cask do describe Hbc::CLI::Search, :cask do
before(:each) do before(:each) do
allow(Tty).to receive(:width).and_return(0) allow(Tty).to receive(:width).and_return(0)
end end
it_behaves_like "a command that handles invalid options"
it "lists the available Casks that match the search term" do it "lists the available Casks that match the search term" do
allow(GitHub).to receive(:search_code).and_return([]) allow(GitHub).to receive(:search_code).and_return([])

View File

@ -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

View File

@ -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

View File

@ -1,11 +1,13 @@
require "open3" require "open3"
require "rubygems" require "rubygems"
require_relative "shared_examples/invalid_option"
describe Hbc::CLI::Style, :cask do describe Hbc::CLI::Style, :cask do
let(:args) { [] } let(:args) { [] }
let(:cli) { described_class.new(*args) } let(:cli) { described_class.new(*args) }
around(&:run) it_behaves_like "a command that handles invalid options"
describe "#run" do describe "#run" do
subject { cli.run } subject { cli.run }

View File

@ -1,4 +1,10 @@
require_relative "shared_examples/requires_cask_token"
require_relative "shared_examples/invalid_option"
describe Hbc::CLI::Uninstall, :cask do 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 it "displays the uninstallation progress" do
caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")
@ -10,23 +16,23 @@ describe Hbc::CLI::Uninstall, :cask do
EOS EOS
expect { expect {
Hbc::CLI::Uninstall.run("local-caffeine") described_class.run("local-caffeine")
}.to output(output).to_stdout }.to output(output).to_stdout
end end
it "shows an error when a bad Cask is provided" do it "shows an error when a bad Cask is provided" do
expect { Hbc::CLI::Uninstall.run("notacask") } expect { described_class.run("notacask") }
.to raise_error(Hbc::CaskUnavailableError, /is unavailable/) .to raise_error(Hbc::CaskUnavailableError, /is unavailable/)
end end
it "shows an error when a Cask is provided that's not installed" do it "shows an error when a Cask is provided that's not installed" do
expect { Hbc::CLI::Uninstall.run("local-caffeine") } expect { described_class.run("local-caffeine") }
.to raise_error(Hbc::CaskNotInstalledError, /is not installed/) .to raise_error(Hbc::CaskNotInstalledError, /is not installed/)
end end
it "tries anyway on a non-present Cask when --force is given" do it "tries anyway on a non-present Cask when --force is given" do
expect { expect {
Hbc::CLI::Uninstall.run("local-caffeine", "--force") described_class.run("local-caffeine", "--force")
}.not_to raise_error }.not_to raise_error
end end
@ -40,7 +46,7 @@ describe Hbc::CLI::Uninstall, :cask do
expect(caffeine).to be_installed expect(caffeine).to be_installed
expect(transmission).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(caffeine).not_to be_installed
expect(Hbc.appdir.join("Transmission.app")).not_to exist expect(Hbc.appdir.join("Transmission.app")).not_to exist
@ -57,7 +63,7 @@ describe Hbc::CLI::Uninstall, :cask do
expect(Hbc.appdir.join("MyFancyApp.app")).to exist expect(Hbc.appdir.join("MyFancyApp.app")).to exist
expect { expect {
Hbc::CLI::Uninstall.run("with-uninstall-script-app") described_class.run("with-uninstall-script-app")
}.not_to raise_error }.not_to raise_error
expect(cask).not_to be_installed expect(cask).not_to be_installed
@ -73,13 +79,13 @@ describe Hbc::CLI::Uninstall, :cask do
Hbc.appdir.join("MyFancyApp.app").rmtree Hbc.appdir.join("MyFancyApp.app").rmtree
expect { Hbc::CLI::Uninstall.run("with-uninstall-script-app") } expect { described_class.run("with-uninstall-script-app") }
.to raise_error(Hbc::CaskError, /uninstall script .* does not exist/) .to raise_error(Hbc::CaskError, /uninstall script .* does not exist/)
expect(cask).to be_installed expect(cask).to be_installed
expect { expect {
Hbc::CLI::Uninstall.run("with-uninstall-script-app", "--force") described_class.run("with-uninstall-script-app", "--force")
}.not_to raise_error }.not_to raise_error
expect(cask).not_to be_installed expect(cask).not_to be_installed
@ -112,13 +118,13 @@ describe Hbc::CLI::Uninstall, :cask do
end end
it "uninstalls one version at a time" do 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(first_installed_version)).to exist
expect(caskroom_path.join(last_installed_version)).not_to exist expect(caskroom_path.join(last_installed_version)).not_to exist
expect(caskroom_path).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.join(first_installed_version)).not_to exist
expect(caskroom_path).not_to exist expect(caskroom_path).not_to exist
@ -127,7 +133,7 @@ describe Hbc::CLI::Uninstall, :cask do
it "displays a message when versions remain installed" do it "displays a message when versions remain installed" do
expect { expect {
expect { expect {
Hbc::CLI::Uninstall.run("versioned-cask") described_class.run("versioned-cask")
}.not_to output.to_stderr }.not_to output.to_stderr
}.to output(/#{token} #{first_installed_version} is still installed./).to_stdout }.to output(/#{token} #{first_installed_version} is still installed./).to_stdout
end end
@ -157,26 +163,10 @@ describe Hbc::CLI::Uninstall, :cask do
end end
it "can still uninstall those Casks" do 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(app).not_to exist
expect(caskroom_path).not_to exist expect(caskroom_path).not_to exist
end end
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 end

View File

@ -1,6 +1,12 @@
require_relative "shared_examples/requires_cask_token"
require_relative "shared_examples/invalid_option"
describe Hbc::CLI::Zap, :cask do 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 it "shows an error when a bad Cask is provided" do
expect { Hbc::CLI::Zap.run("notacask") } expect { described_class.run("notacask") }
.to raise_error(Hbc::CaskUnavailableError, /is unavailable/) .to raise_error(Hbc::CaskUnavailableError, /is unavailable/)
end end
@ -14,7 +20,7 @@ describe Hbc::CLI::Zap, :cask do
expect(caffeine).to be_installed expect(caffeine).to be_installed
expect(transmission).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(caffeine).not_to be_installed
expect(Hbc.appdir.join("Caffeine.app")).not_to be_a_symlink expect(Hbc.appdir.join("Caffeine.app")).not_to be_a_symlink
@ -45,20 +51,4 @@ describe Hbc::CLI::Zap, :cask do
# #
# with_zap.wont_be :installed? # with_zap.wont_be :installed?
# end # 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 end

View File

@ -10,7 +10,10 @@ describe "Satisfy Dependencies and Requirements", :cask do
describe "depends_on cask" do describe "depends_on cask" do
context "when depends_on cask is cyclic" do context "when depends_on cask is cyclic" do
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-cask-cyclic.rb") } let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-cask-cyclic.rb") }
it { is_expected.to raise_error(Hbc::CaskCyclicDependencyError) } it {
is_expected.to raise_error(Hbc::CaskCyclicDependencyError,
"Cask 'with-depends-on-cask-cyclic' includes cyclic dependencies on other Casks: with-depends-on-cask-cyclic-helper")
}
end end
context do context do