diff options
| author | Markus Reiter | 2017-05-23 13:27:44 +0200 |
|---|---|---|
| committer | GitHub | 2017-05-23 13:27:44 +0200 |
| commit | d1f599f1ed51976fc76ad19803de04864d12ef2b (patch) | |
| tree | 9096569a3630b7ee9bd5751811e35c043ab1a02d /Library/Homebrew/test | |
| parent | 04420d07a4c127b9a85013f31619eed4b88ec94b (diff) | |
| parent | 02a1e2781fcb808b731fd04d18369ec5bfd3bc68 (diff) | |
| download | brew-d1f599f1ed51976fc76ad19803de04864d12ef2b.tar.bz2 | |
Merge pull request #2654 from reitermarkus/refactor-cli
Refactor `CLI`.
Diffstat (limited to 'Library/Homebrew/test')
| -rw-r--r-- | Library/Homebrew/test/cask/artifact/binary_spec.rb | 30 | ||||
| -rw-r--r-- | Library/Homebrew/test/cask/cli/audit_spec.rb | 39 | ||||
| -rw-r--r-- | Library/Homebrew/test/cask/cli/cat_spec.rb | 16 | ||||
| -rw-r--r-- | Library/Homebrew/test/cask/cli/cleanup_spec.rb | 94 | ||||
| -rw-r--r-- | Library/Homebrew/test/cask/cli/create_spec.rb | 80 | ||||
| -rw-r--r-- | Library/Homebrew/test/cask/cli/edit_spec.rb | 45 | ||||
| -rw-r--r-- | Library/Homebrew/test/cask/cli/fetch_spec.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/test/cask/cli/home_spec.rb | 41 | ||||
| -rw-r--r-- | Library/Homebrew/test/cask/cli/info_spec.rb | 4 | ||||
| -rw-r--r-- | Library/Homebrew/test/cask/cli/install_spec.rb | 8 | ||||
| -rw-r--r-- | Library/Homebrew/test/cask/cli/options_spec.rb | 65 | ||||
| -rw-r--r-- | Library/Homebrew/test/cask/cli/outdated_spec.rb | 32 | ||||
| -rw-r--r-- | Library/Homebrew/test/cask/cli/style_spec.rb | 97 | ||||
| -rw-r--r-- | Library/Homebrew/test/cask/cli/uninstall_spec.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/test/cask/cli/zap_spec.rb | 5 | ||||
| -rw-r--r-- | Library/Homebrew/test/cask/cli_spec.rb | 24 |
16 files changed, 199 insertions, 385 deletions
diff --git a/Library/Homebrew/test/cask/artifact/binary_spec.rb b/Library/Homebrew/test/cask/artifact/binary_spec.rb index ee62e6439..f9b5f5b42 100644 --- a/Library/Homebrew/test/cask/artifact/binary_spec.rb +++ b/Library/Homebrew/test/cask/artifact/binary_spec.rb @@ -16,6 +16,20 @@ describe Hbc::Artifact::Binary, :cask do FileUtils.rm expected_path if expected_path.exist? end + context "when --no-binaries is specified" do + let(:cask) { + Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-binary.rb") + } + + it "doesn't link the binary when --no-binaries is specified" do + shutup do + Hbc::Installer.new(cask, binaries: false).install + end + + expect(expected_path).not_to exist + end + end + it "links the binary to the proper directory" do shutup do Hbc::Artifact::Binary.new(cask).install_phase @@ -70,22 +84,6 @@ describe Hbc::Artifact::Binary, :cask do expect(File.readlink(expected_path)).not_to eq("/tmp") end - it "respects --no-binaries flag" do - begin - Hbc::CLI.binaries = false - - expect(Hbc::CLI).not_to be_binaries - - shutup do - Hbc::Artifact::Binary.new(cask).install_phase - end - - expect(expected_path.exist?).to be false - ensure - Hbc::CLI.binaries = true - end - end - it "creates parent directory if it doesn't exist" do FileUtils.rmdir Hbc.binarydir diff --git a/Library/Homebrew/test/cask/cli/audit_spec.rb b/Library/Homebrew/test/cask/cli/audit_spec.rb index 007ba1eb3..412db1481 100644 --- a/Library/Homebrew/test/cask/cli/audit_spec.rb +++ b/Library/Homebrew/test/cask/cli/audit_spec.rb @@ -1,59 +1,64 @@ describe Hbc::CLI::Audit, :cask do - let(:auditor) { double } let(:cask) { double } describe "selection of Casks to audit" do it "audits all Casks if no tokens are given" do allow(Hbc).to receive(:all).and_return([cask, cask]) - expect(auditor).to receive(:audit).twice + expect(Hbc::Auditor).to receive(:audit).twice.and_return(true) - run_audit([], auditor) + Hbc::CLI::Audit.run end it "audits specified Casks if tokens are given" do cask_token = "nice-app" expect(Hbc::CaskLoader).to receive(:load).with(cask_token).and_return(cask) - expect(auditor).to receive(:audit).with(cask, audit_download: false, check_token_conflicts: false) + expect(Hbc::Auditor).to receive(:audit) + .with(cask, audit_download: false, check_token_conflicts: false) + .and_return(true) - run_audit([cask_token], auditor) + Hbc::CLI::Audit.run(cask_token) end end describe "rules for downloading a Cask" do it "does not download the Cask per default" do allow(Hbc::CaskLoader).to receive(:load).and_return(cask) - expect(auditor).to receive(:audit).with(cask, audit_download: false, check_token_conflicts: false) + expect(Hbc::Auditor).to receive(:audit) + .with(cask, audit_download: false, check_token_conflicts: false) + .and_return(true) - run_audit(["casktoken"], auditor) + Hbc::CLI::Audit.run("casktoken") end it "download a Cask if --download flag is set" do allow(Hbc::CaskLoader).to receive(:load).and_return(cask) - expect(auditor).to receive(:audit).with(cask, audit_download: true, check_token_conflicts: false) + expect(Hbc::Auditor).to receive(:audit) + .with(cask, audit_download: true, check_token_conflicts: false) + .and_return(true) - run_audit(["casktoken", "--download"], auditor) + Hbc::CLI::Audit.run("casktoken", "--download") end end describe "rules for checking token conflicts" do it "does not check for token conflicts per default" do allow(Hbc::CaskLoader).to receive(:load).and_return(cask) - expect(auditor).to receive(:audit).with(cask, audit_download: false, check_token_conflicts: false) + expect(Hbc::Auditor).to receive(:audit) + .with(cask, audit_download: false, check_token_conflicts: false) + .and_return(true) - run_audit(["casktoken"], auditor) + Hbc::CLI::Audit.run("casktoken") end it "checks for token conflicts if --token-conflicts flag is set" do allow(Hbc::CaskLoader).to receive(:load).and_return(cask) - expect(auditor).to receive(:audit).with(cask, audit_download: false, check_token_conflicts: true) + expect(Hbc::Auditor).to receive(:audit) + .with(cask, audit_download: false, check_token_conflicts: true) + .and_return(true) - run_audit(["casktoken", "--token-conflicts"], auditor) + Hbc::CLI::Audit.run("casktoken", "--token-conflicts") end end - - def run_audit(args, auditor) - Hbc::CLI::Audit.new(args, auditor).run - end end diff --git a/Library/Homebrew/test/cask/cli/cat_spec.rb b/Library/Homebrew/test/cask/cli/cat_spec.rb index daf6fb960..28089b2f1 100644 --- a/Library/Homebrew/test/cask/cli/cat_spec.rb +++ b/Library/Homebrew/test/cask/cli/cat_spec.rb @@ -1,6 +1,6 @@ describe Hbc::CLI::Cat, :cask do describe "given a basic Cask" do - let(:expected_output) { + let(:basic_cask_content) { <<-EOS.undent cask 'basic-cask' do version '1.2.3' @@ -17,19 +17,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") - }.to output(expected_output).to_stdout + }.to output(basic_cask_content).to_stdout end - it "throws away additional Cask arguments and uses the first" do + it "can display multiple Casks" do expect { - Hbc::CLI::Cat.run("basic-cask", "local-caffeine") - }.to output(expected_output).to_stdout + Hbc::CLI::Cat.run("basic-cask", "basic-cask") + }.to output(basic_cask_content * 2).to_stdout end - it "throws away stray options" do + it "fails when option is unknown" do expect { Hbc::CLI::Cat.run("--notavalidoption", "basic-cask") - }.to output(expected_output).to_stdout + }.to raise_error(/invalid option/) end end @@ -51,7 +51,7 @@ describe Hbc::CLI::Cat, :cask do it "raises an exception" do expect { Hbc::CLI::Cat.run("--notavalidoption") - }.to raise_error(Hbc::CaskUnspecifiedError) + }.to raise_error(/invalid option/) end end end diff --git a/Library/Homebrew/test/cask/cli/cleanup_spec.rb b/Library/Homebrew/test/cask/cli/cleanup_spec.rb index c7ef356c0..64e3ef49f 100644 --- a/Library/Homebrew/test/cask/cli/cleanup_spec.rb +++ b/Library/Homebrew/test/cask/cli/cleanup_spec.rb @@ -1,19 +1,24 @@ describe Hbc::CLI::Cleanup, :cask do let(:cache_location) { Pathname.new(Dir.mktmpdir).realpath } - let(:cleanup_outdated) { false } + let(:outdated_only) { false } - subject { described_class.new(cache_location, cleanup_outdated) } + subject { described_class.new(*cask_tokens, cache_location: cache_location) } + + before(:each) do + allow_any_instance_of(described_class).to receive(:outdated_only?).and_return(outdated_only) + end after do cache_location.rmtree end describe "cleanup" do - it "removes cached downloads of given casks" do - cleaned_up_cached_download = "caffeine" + let(:cask_token) { "caffeine" } + let(:cask_tokens) { [cask_token] } + it "removes cached downloads of given casks" do cached_downloads = [ - cache_location.join("#{cleaned_up_cached_download}--latest.zip"), + cache_location.join("#{cask_token}--latest.zip"), cache_location.join("transmission--2.61.dmg"), ] @@ -22,9 +27,9 @@ describe Hbc::CLI::Cleanup, :cask do cleanup_size = cached_downloads[0].disk_usage expect { - subject.cleanup(cleaned_up_cached_download) + subject.run }.to output(<<-EOS.undent).to_stdout - ==> Removing cached downloads for #{cleaned_up_cached_download} + ==> Removing cached downloads for #{cask_token} #{cached_downloads[0]} ==> This operation has freed approximately #{disk_usage_readable(cleanup_size)} of disk space. EOS @@ -32,61 +37,42 @@ describe Hbc::CLI::Cleanup, :cask do expect(cached_downloads[0].exist?).to eq(false) expect(cached_downloads[1].exist?).to eq(true) end - end - describe "cleanup!" do - it "removes cached downloads" do - cached_download = cache_location.join("SomeDownload.dmg") - FileUtils.touch(cached_download) - cleanup_size = subject.disk_cleanup_size + context "when no argument is given" do + let(:cask_tokens) { [] } - expect { - subject.cleanup! - }.to output(<<-EOS.undent).to_stdout - ==> Removing cached downloads - #{cached_download} - ==> This operation has freed approximately #{disk_usage_readable(cleanup_size)} of disk space. - EOS - - expect(cached_download.exist?).to eq(false) - end - - # TODO: uncomment when unflaky. - # it "does not removed locked files" do - # cached_download = cache_location.join("SomeDownload.dmg") - # FileUtils.touch(cached_download) - # cleanup_size = subject.disk_cleanup_size - # - # File.new(cached_download).flock(File::LOCK_EX) - # - # expect(Hbc::Utils).to be_file_locked(cached_download) - # - # expect { - # subject.cleanup! - # }.to output(<<-EOS.undent).to_stdout - # ==> Removing cached downloads - # skipping: #{cached_download} is locked - # ==> This operation has freed approximately #{disk_usage_readable(cleanup_size)} of disk space. - # EOS - # - # expect(cached_download.exist?).to eq(true) - # end - - context "when cleanup_outdated is specified" do - let(:cleanup_outdated) { true } - - it "does not remove cache files newer than 10 days old" do - cached_download = cache_location.join("SomeNewDownload.dmg") + it "removes all cached downloads" do + cached_download = cache_location.join("SomeDownload.dmg") FileUtils.touch(cached_download) + cleanup_size = subject.disk_cleanup_size expect { - subject.cleanup! + subject.run }.to output(<<-EOS.undent).to_stdout - ==> Removing cached downloads older than 10 days old - Nothing to do + ==> Removing cached downloads + #{cached_download} + ==> This operation has freed approximately #{disk_usage_readable(cleanup_size)} of disk space. EOS - expect(cached_download.exist?).to eq(true) + expect(cached_download.exist?).to eq(false) + end + + context "and :outdated_only is specified" do + let(:outdated_only) { true } + + it "does not remove cache files newer than 10 days old" do + cached_download = cache_location.join("SomeNewDownload.dmg") + FileUtils.touch(cached_download) + + expect { + subject.run + }.to output(<<-EOS.undent).to_stdout + ==> Removing cached downloads older than 10 days old + Nothing to do + EOS + + expect(cached_download.exist?).to eq(true) + end end end end diff --git a/Library/Homebrew/test/cask/cli/create_spec.rb b/Library/Homebrew/test/cask/cli/create_spec.rb index b1cee6990..d77b0a2aa 100644 --- a/Library/Homebrew/test/cask/cli/create_spec.rb +++ b/Library/Homebrew/test/cask/cli/create_spec.rb @@ -1,43 +1,26 @@ -# monkeypatch for testing -module Hbc - class CLI - class Create - def self.exec_editor(*command) - editor_commands << command - end - - def self.reset! - @editor_commands = [] - end - - def self.editor_commands - @editor_commands ||= [] +describe Hbc::CLI::Create, :cask do + around(:each) do |example| + begin + example.run + ensure + %w[new-cask additional-cask another-cask yet-another-cask local-caff].each do |cask| + FileUtils.rm_f Hbc::CaskLoader.path(cask) end end end -end -describe Hbc::CLI::Create, :cask do before(:each) do - Hbc::CLI::Create.reset! - end - - after(:each) do - %w[new-cask additional-cask another-cask yet-another-cask local-caff].each do |cask| - path = Hbc::CaskLoader.path(cask) - path.delete if path.exist? - end + allow_any_instance_of(described_class).to receive(:exec_editor) end it "opens the editor for the specified Cask" do - Hbc::CLI::Create.run("new-cask") - expect(Hbc::CLI::Create.editor_commands).to eq [ - [Hbc::CaskLoader.path("new-cask")], - ] + command = described_class.new("new-cask") + expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("new-cask")) + command.run end it "drops a template down for the specified Cask" do - Hbc::CLI::Create.run("new-cask") + described_class.run("new-cask") template = File.read(Hbc::CaskLoader.path("new-cask")) expect(template).to eq <<-EOS.undent cask 'new-cask' do @@ -53,46 +36,43 @@ describe Hbc::CLI::Create, :cask do EOS end - it "throws away additional Cask arguments and uses the first" do - Hbc::CLI::Create.run("additional-cask", "another-cask") - expect(Hbc::CLI::Create.editor_commands).to eq [ - [Hbc::CaskLoader.path("additional-cask")], - ] - end - - it "throws away stray options" do - Hbc::CLI::Create.run("--notavalidoption", "yet-another-cask") - expect(Hbc::CLI::Create.editor_commands).to eq [ - [Hbc::CaskLoader.path("yet-another-cask")], - ] + 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./) end it "raises an exception when the Cask already exists" do expect { - Hbc::CLI::Create.run("basic-cask") + described_class.run("basic-cask") }.to raise_error(Hbc::CaskAlreadyCreatedError) end it "allows creating Casks that are substrings of existing Casks" do - Hbc::CLI::Create.run("local-caff") - expect(Hbc::CLI::Create.editor_commands).to eq [ - [Hbc::CaskLoader.path("local-caff")], - ] + command = described_class.new("local-caff") + 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 { - Hbc::CLI::Create.run + described_class.run }.to raise_error(Hbc::CaskUnspecifiedError) end end - describe "when no Cask is specified, but an invalid option" do + 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 { - Hbc::CLI::Create.run("--notavalidoption") - }.to raise_error(Hbc::CaskUnspecifiedError) + described_class.run("--notavalidoption", "yet-another-cask") + }.to raise_error(/invalid option/) end end end diff --git a/Library/Homebrew/test/cask/cli/edit_spec.rb b/Library/Homebrew/test/cask/cli/edit_spec.rb index f5f98afc8..5d5cbf4b9 100644 --- a/Library/Homebrew/test/cask/cli/edit_spec.rb +++ b/Library/Homebrew/test/cask/cli/edit_spec.rb @@ -1,51 +1,30 @@ -# monkeypatch for testing -module Hbc - class CLI - class Edit - def self.exec_editor(*command) - editor_commands << command - end - - def self.reset! - @editor_commands = [] - end - - def self.editor_commands - @editor_commands ||= [] - end - end - end -end - describe Hbc::CLI::Edit, :cask do before(:each) do - Hbc::CLI::Edit.reset! + allow_any_instance_of(described_class).to receive(:exec_editor) end it "opens the editor for the specified Cask" do - Hbc::CLI::Edit.run("local-caffeine") - expect(Hbc::CLI::Edit.editor_commands).to eq [ - [Hbc::CaskLoader.path("local-caffeine")], - ] + command = described_class.new("local-caffeine") + expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("local-caffeine")) + command.run end - it "throws away additional arguments and uses the first" do - Hbc::CLI::Edit.run("local-caffeine", "local-transmission") - expect(Hbc::CLI::Edit.editor_commands).to eq [ - [Hbc::CaskLoader.path("local-caffeine")], - ] + 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./) end it "raises an exception when the Cask doesnt exist" do expect { - Hbc::CLI::Edit.run("notacask") + described_class.run("notacask") }.to raise_error(Hbc::CaskUnavailableError) end describe "when no Cask is specified" do it "raises an exception" do expect { - Hbc::CLI::Edit.run + described_class.run }.to raise_error(Hbc::CaskUnspecifiedError) end end @@ -53,8 +32,8 @@ describe Hbc::CLI::Edit, :cask do describe "when no Cask is specified, but an invalid option" do it "raises an exception" do expect { - Hbc::CLI::Edit.run("--notavalidoption") - }.to raise_error(Hbc::CaskUnspecifiedError) + 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 1571c2a70..9f3056631 100644 --- a/Library/Homebrew/test/cask/cli/fetch_spec.rb +++ b/Library/Homebrew/test/cask/cli/fetch_spec.rb @@ -69,7 +69,7 @@ describe Hbc::CLI::Fetch, :cask do it "raises an exception" do expect { Hbc::CLI::Fetch.run("--notavalidoption") - }.to raise_error(Hbc::CaskUnspecifiedError) + }.to raise_error(/invalid option/) end end end diff --git a/Library/Homebrew/test/cask/cli/home_spec.rb b/Library/Homebrew/test/cask/cli/home_spec.rb index 7be26dd4c..e985fb6cd 100644 --- a/Library/Homebrew/test/cask/cli/home_spec.rb +++ b/Library/Homebrew/test/cask/cli/home_spec.rb @@ -1,46 +1,21 @@ -# monkeypatch for testing -module Hbc - class CLI - class Home - def self.system(*command) - system_commands << command - end - - def self.reset! - @system_commands = [] - end - - def self.system_commands - @system_commands ||= [] - end - end - end -end - describe Hbc::CLI::Home, :cask do before do - Hbc::CLI::Home.reset! + allow(described_class).to receive(:open_url) end it "opens the homepage for the specified Cask" do - Hbc::CLI::Home.run("local-caffeine") - expect(Hbc::CLI::Home.system_commands).to eq [ - ["/usr/bin/open", "--", "http://example.com/local-caffeine"], - ] + expect(described_class).to receive(:open_url).with("http://example.com/local-caffeine") + described_class.run("local-caffeine") end it "works for multiple Casks" do - Hbc::CLI::Home.run("local-caffeine", "local-transmission") - expect(Hbc::CLI::Home.system_commands).to eq [ - ["/usr/bin/open", "--", "http://example.com/local-caffeine"], - ["/usr/bin/open", "--", "http://example.com/local-transmission"], - ] + 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-transmission") + described_class.run("local-caffeine", "local-transmission") end it "opens the project page when no Cask is specified" do - Hbc::CLI::Home.run - expect(Hbc::CLI::Home.system_commands).to eq [ - ["/usr/bin/open", "--", "https://caskroom.github.io/"], - ] + expect(described_class).to receive(:open_url).with("https://caskroom.github.io/") + described_class.run end end diff --git a/Library/Homebrew/test/cask/cli/info_spec.rb b/Library/Homebrew/test/cask/cli/info_spec.rb index 2f70a0b96..bffe900ec 100644 --- a/Library/Homebrew/test/cask/cli/info_spec.rb +++ b/Library/Homebrew/test/cask/cli/info_spec.rb @@ -45,7 +45,7 @@ describe Hbc::CLI::Info, :cask do it "throws away stray options" do expect { Hbc::CLI::Info.run("--notavalidoption", "local-caffeine", "local-transmission") - }.to output(expected_output).to_stdout + }.to raise_error(/invalid option/) end end @@ -102,7 +102,7 @@ describe Hbc::CLI::Info, :cask do it "raises an exception" do expect { Hbc::CLI::Info.run("--notavalidoption") - }.to raise_error(Hbc::CaskUnspecifiedError) + }.to raise_error(/invalid option/) end end end diff --git a/Library/Homebrew/test/cask/cli/install_spec.rb b/Library/Homebrew/test/cask/cli/install_spec.rb index 219b9522e..b1b26c867 100644 --- a/Library/Homebrew/test/cask/cli/install_spec.rb +++ b/Library/Homebrew/test/cask/cli/install_spec.rb @@ -40,7 +40,7 @@ describe Hbc::CLI::Install, :cask do end expect { - Hbc::CLI::Install.run("local-transmission", "") + Hbc::CLI::Install.run("local-transmission") }.to output(/Warning: A Cask for local-transmission is already installed./).to_stderr end @@ -115,7 +115,11 @@ describe Hbc::CLI::Install, :cask do end describe "with an invalid option" do - with_options.call(["--notavalidoption"]) + it "raises an error" do + expect { + Hbc::CLI::Install.run("--notavalidoption") + }.to raise_error(/invalid option/) + end end end end diff --git a/Library/Homebrew/test/cask/cli/options_spec.rb b/Library/Homebrew/test/cask/cli/options_spec.rb index 44a391b48..98eb05f7e 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.process_options %w[help --appdir=/some/path/foo] + Hbc::CLI.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.process_options %w[help] + Hbc::CLI.new.process_options("help") expect(Hbc.appdir).to eq(Pathname.new("/some/path/bar")) end it "supports setting the prefpanedir" do - Hbc::CLI.process_options %w[help --prefpanedir=/some/path/foo] + Hbc::CLI.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.process_options %w[help] + Hbc::CLI.new.process_options("help") expect(Hbc.prefpanedir).to eq(Pathname.new("/some/path/bar")) end it "supports setting the qlplugindir" do - Hbc::CLI.process_options %w[help --qlplugindir=/some/path/foo] + Hbc::CLI.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.process_options %w[help] + Hbc::CLI.new.process_options("help") expect(Hbc.qlplugindir).to eq(Pathname.new("/some/path/bar")) end it "supports setting the colorpickerdir" do - Hbc::CLI.process_options %w[help --colorpickerdir=/some/path/foo] + Hbc::CLI.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.process_options %w[help] + Hbc::CLI.new.process_options("help") expect(Hbc.colorpickerdir).to eq(Pathname.new("/some/path/bar")) end it "supports setting the dictionarydir" do - Hbc::CLI.process_options %w[help --dictionarydir=/some/path/foo] + Hbc::CLI.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.process_options %w[help] + Hbc::CLI.new.process_options("help") expect(Hbc.dictionarydir).to eq(Pathname.new("/some/path/bar")) end it "supports setting the fontdir" do - Hbc::CLI.process_options %w[help --fontdir=/some/path/foo] + Hbc::CLI.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.process_options %w[help] + Hbc::CLI.new.process_options("help") expect(Hbc.fontdir).to eq(Pathname.new("/some/path/bar")) end it "supports setting the servicedir" do - Hbc::CLI.process_options %w[help --servicedir=/some/path/foo] + Hbc::CLI.new.process_options("help", "--servicedir=/some/path/foo") expect(Hbc.servicedir).to eq(Pathname.new("/some/path/foo")) end @@ -92,53 +92,22 @@ describe Hbc::CLI, :cask do it "supports setting the servicedir from ENV" do ENV["HOMEBREW_CASK_OPTS"] = "--servicedir=/some/path/bar" - Hbc::CLI.process_options %w[help] + Hbc::CLI.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.process_options %w[edit foo --create --appdir=/some/path/qux] + rest = Hbc::CLI.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]) end - describe "when a mandatory argument is missing" do - it "shows a user-friendly error message" do - expect { - Hbc::CLI.process_options %w[install -f] - }.to raise_error(ArgumentError) - end - end - - describe "given an ambiguous option" do - it "shows a user-friendly error message" do - expect { - Hbc::CLI.process_options %w[edit -c] - }.to raise_error(ArgumentError) - end - end - - describe "--debug" do - it "sets the Cask debug method to true" do - begin - Hbc::CLI.process_options %w[help --debug] - expect(Hbc::CLI.debug?).to be true - ensure - Hbc::CLI.debug = false - end - end - end - describe "--help" do it "sets the Cask help method to true" do - begin - Hbc::CLI.process_options %w[foo --help] - expect(Hbc::CLI.help?).to be true - ensure - Hbc::CLI.help = false - end + command = Hbc::CLI.new("foo", "--help") + expect(command.help?).to be true end end end diff --git a/Library/Homebrew/test/cask/cli/outdated_spec.rb b/Library/Homebrew/test/cask/cli/outdated_spec.rb index a0f13009d..3d9e9bdeb 100644 --- a/Library/Homebrew/test/cask/cli/outdated_spec.rb +++ b/Library/Homebrew/test/cask/cli/outdated_spec.rb @@ -13,13 +13,13 @@ describe Hbc::CLI::Outdated, :cask do shutup do installed.each { |cask| InstallHelper.install_with_caskfile(cask) } end - allow(Hbc::CLI).to receive(:verbose?).and_return(true) + allow_any_instance_of(described_class).to receive(:verbose?).and_return(true) end 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 { - Hbc::CLI::Outdated.run + described_class.run }.to output(<<-EOS.undent).to_stdout local-caffeine (1.2.2) != 1.2.3 local-transmission (2.60) != 2.61 @@ -28,7 +28,7 @@ describe Hbc::CLI::Outdated, :cask do it "checks only the tokens specified in the command line" do expect { - Hbc::CLI::Outdated.run("local-caffeine") + described_class.run("local-caffeine") }.to output(<<-EOS.undent).to_stdout local-caffeine (1.2.2) != 1.2.3 EOS @@ -36,26 +36,32 @@ describe Hbc::CLI::Outdated, :cask do it 'ignores "auto_updates" and "latest" Casks even when their tokens are provided in the command line' do expect { - Hbc::CLI::Outdated.run("local-caffeine", "auto-updates", "version-latest-string") + described_class.run("local-caffeine", "auto-updates", "version-latest-string") }.to output(<<-EOS.undent).to_stdout local-caffeine (1.2.2) != 1.2.3 EOS end end - it "lists only the names (no versions) of the outdated Casks with --quiet" do - expect { - Hbc::CLI::Outdated.run("--quiet") - }.to output(<<-EOS.undent).to_stdout - local-caffeine - local-transmission - EOS + describe "--quiet overrides --verbose" do + before do + allow_any_instance_of(described_class).to receive(:verbose?).and_call_original + end + + it "lists only the names (no versions) of the outdated Casks with --quiet" do + expect { + described_class.run("--verbose", "--quiet") + }.to output(<<-EOS.undent).to_stdout + local-caffeine + local-transmission + EOS + end end describe "with --greedy it checks additional Casks" do it 'includes the Casks with "auto_updates true" or "version latest" with --greedy' do expect { - Hbc::CLI::Outdated.run("--greedy") + described_class.run("--greedy") }.to output(<<-EOS.undent).to_stdout auto-updates (2.57) != 2.61 local-caffeine (1.2.2) != 1.2.3 @@ -69,7 +75,7 @@ describe Hbc::CLI::Outdated, :cask do InstallHelper.install_with_caskfile(cask) expect { - Hbc::CLI::Outdated.run("--greedy") + described_class.run("--greedy") }.to output(<<-EOS.undent).to_stdout local-caffeine (1.2.2) != 1.2.3 local-transmission (2.60) != 2.61 diff --git a/Library/Homebrew/test/cask/cli/style_spec.rb b/Library/Homebrew/test/cask/cli/style_spec.rb index d41636beb..7d250c166 100644 --- a/Library/Homebrew/test/cask/cli/style_spec.rb +++ b/Library/Homebrew/test/cask/cli/style_spec.rb @@ -4,37 +4,12 @@ require "rubygems" describe Hbc::CLI::Style, :cask do let(:args) { [] } - let(:cli) { described_class.new(args) } + let(:cli) { described_class.new(*args) } around do |example| shutup { example.run } end - describe ".run" do - subject { described_class.run(args) } - - before do - allow(described_class).to receive(:new).and_return(cli) - allow(cli).to receive(:run).and_return(retval) - end - - context "when rubocop succeeds" do - let(:retval) { true } - - it "exits successfully" do - subject - end - end - - context "when rubocop fails" do - let(:retval) { false } - - it "raises an exception" do - expect { subject }.to raise_error(Hbc::CaskError) - end - end - end - describe "#run" do subject { cli.run } @@ -53,7 +28,10 @@ describe Hbc::CLI::Style, :cask do context "when rubocop fails" do let(:success) { false } - it { is_expected.to be_falsey } + + it "raises an error" do + expect { subject }.to raise_error(Hbc::CaskError) + end end end @@ -99,7 +77,7 @@ describe Hbc::CLI::Style, :cask do subject { cli.cask_paths } before do - allow(cli).to receive(:cask_tokens).and_return(tokens) + allow(cli).to receive(:args).and_return(tokens) end context "when no cask tokens are given" do @@ -136,40 +114,6 @@ describe Hbc::CLI::Style, :cask do end end - describe "#cask_tokens" do - subject { cli.cask_tokens } - - context "when no args are given" do - let(:args) { [] } - it { is_expected.to be_empty } - end - - context "when only flags are given" do - let(:args) { ["--fix"] } - it { is_expected.to be_empty } - end - - context "when only empty args are given" do - let(:args) { ["", ""] } - it { is_expected.to be_empty } - end - - context "when a cask token is given" do - let(:args) { ["adium"] } - it { is_expected.to eq(["adium"]) } - end - - context "when multiple cask tokens are given" do - let(:args) { %w[adium dropbox] } - it { is_expected.to eq(%w[adium dropbox]) } - end - - context "when cask tokens are given with flags" do - let(:args) { ["adium", "dropbox", "--fix"] } - it { is_expected.to eq(%w[adium dropbox]) } - end - end - describe "#rubocop_args" do subject { cli.rubocop_args } @@ -203,33 +147,4 @@ describe Hbc::CLI::Style, :cask do expect(subject).to include("--auto-correct", *default_args) end end - - describe "#fix?" do - subject { cli.fix? } - - context "when --fix is passed as an argument" do - let(:args) { ["adium", "--fix"] } - it { is_expected.to be_truthy } - end - - context "when --correct is passed as an argument" do - let(:args) { ["adium", "--correct"] } - it { is_expected.to be_truthy } - end - - context "when --auto-correct is passed as an argument" do - let(:args) { ["adium", "--auto-correct"] } - it { is_expected.to be_truthy } - end - - context "when --auto-correct is misspelled as --autocorrect" do - let(:args) { ["adium", "--autocorrect"] } - it { is_expected.to be_truthy } - end - - context "when no flag equivalent to --fix is passed as an argument" do - let(:args) { ["adium"] } - it { is_expected.to be_falsey } - end - end end diff --git a/Library/Homebrew/test/cask/cli/uninstall_spec.rb b/Library/Homebrew/test/cask/cli/uninstall_spec.rb index 4089c47b4..bc1f52613 100644 --- a/Library/Homebrew/test/cask/cli/uninstall_spec.rb +++ b/Library/Homebrew/test/cask/cli/uninstall_spec.rb @@ -203,7 +203,7 @@ describe Hbc::CLI::Uninstall, :cask do it "raises an exception" do expect { Hbc::CLI::Uninstall.run("--notavalidoption") - }.to raise_error(Hbc::CaskUnspecifiedError) + }.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 58992deb5..f3af0e66f 100644 --- a/Library/Homebrew/test/cask/cli/zap_spec.rb +++ b/Library/Homebrew/test/cask/cli/zap_spec.rb @@ -18,8 +18,7 @@ describe Hbc::CLI::Zap, :cask do expect(transmission).to be_installed shutup do - Hbc::CLI::Zap.run("--notavalidoption", - "local-caffeine", "local-transmission") + Hbc::CLI::Zap.run("local-caffeine", "local-transmission") end expect(caffeine).not_to be_installed @@ -67,7 +66,7 @@ describe Hbc::CLI::Zap, :cask do it "raises an exception" do expect { Hbc::CLI::Zap.run("--notavalidoption") - }.to raise_error(Hbc::CaskUnspecifiedError) + }.to raise_error(/invalid option/) end end end diff --git a/Library/Homebrew/test/cask/cli_spec.rb b/Library/Homebrew/test/cask/cli_spec.rb index 9bf14fd89..d5bfba754 100644 --- a/Library/Homebrew/test/cask/cli_spec.rb +++ b/Library/Homebrew/test/cask/cli_spec.rb @@ -13,7 +13,7 @@ describe Hbc::CLI, :cask do ]) end - context ".process" do + context "::run" do let(:noop_command) { double("CLI::Noop") } before do @@ -30,37 +30,35 @@ describe Hbc::CLI, :cask do version_command = double("CLI::Version") allow(described_class).to receive(:lookup_command).with("--version").and_return(version_command) expect(described_class).to receive(:run_command).with(version_command) - described_class.process(["--version"]) + described_class.run("--version") end it "prints help output when subcommand receives `--help` flag" do - begin - expect(described_class).to receive(:run_command).with("help") - described_class.process(%w[noop --help]) - expect(Hbc::CLI.help?).to eq(true) - ensure - Hbc::CLI.help = false - end + command = Hbc::CLI.new("noop", "--help") + expect(described_class).to receive(:run_command).with("help") + command.run + expect(command.help?).to eq(true) end it "respects the env variable when choosing what appdir to create" do allow(ENV).to receive(:[]) allow(ENV).to receive(:[]).with("HOMEBREW_CASK_OPTS").and_return("--appdir=/custom/appdir") expect(Hbc).to receive(:appdir=).with(Pathname.new("/custom/appdir")) - described_class.process("noop") + described_class.run("noop") end it "respects the env variable when choosing a non-default Caskroom location" do allow(ENV).to receive(:[]) allow(ENV).to receive(:[]).with("HOMEBREW_CASK_OPTS").and_return("--caskroom=/custom/caskdir") expect(Hbc).to receive(:caskroom=).with(Pathname.new("/custom/caskdir")) - described_class.process("noop") + described_class.run("noop") end it "exits with a status of 1 when something goes wrong" do allow(described_class).to receive(:lookup_command).and_raise(Hbc::CaskError) - expect(described_class).to receive(:exit).with(1) - described_class.process("noop") + command = Hbc::CLI.new("noop") + expect(command).to receive(:exit).with(1) + command.run end end |
