diff options
| author | Markus Reiter | 2017-10-03 10:49:58 +0200 | 
|---|---|---|
| committer | Markus Reiter | 2017-10-03 10:56:40 +0200 | 
| commit | 643b2a168c6c5b2f21b141ec385fc49d29c41718 (patch) | |
| tree | ae9f32f7283806d2e1878bb4aa8932b2fbacb2de /Library/Homebrew/test/cask/cli | |
| parent | ec0d8fa7ba18f4fe05c5241258502c8db332b13d (diff) | |
| download | brew-643b2a168c6c5b2f21b141ec385fc49d29c41718.tar.bz2 | |
Refactor `cask/cli` specs.
Diffstat (limited to 'Library/Homebrew/test/cask/cli')
20 files changed, 173 insertions, 227 deletions
diff --git a/Library/Homebrew/test/cask/cli/audit_spec.rb b/Library/Homebrew/test/cask/cli/audit_spec.rb index 30ab437cb..da8bf1273 100644 --- a/Library/Homebrew/test/cask/cli/audit_spec.rb +++ b/Library/Homebrew/test/cask/cli/audit_spec.rb @@ -1,6 +1,10 @@ +require_relative "shared_examples/invalid_option" +  describe Hbc::CLI::Audit, :cask do    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 @@ -9,7 +13,7 @@ describe Hbc::CLI::Audit, :cask do        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 @@ -20,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 @@ -31,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 @@ -40,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 @@ -51,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 @@ -60,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 5a4b29c6f..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,41 +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") } +    expect { described_class.run("notacask") }        .to raise_error(Hbc::CaskUnavailableError, /is unavailable/)    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 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 17d426f78..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")) @@ -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 51542807f..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")) @@ -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 faaa69b35..087a30f50 100644 --- a/Library/Homebrew/test/cask/cli/fetch_spec.rb +++ b/Library/Homebrew/test/cask/cli/fetch_spec.rb @@ -1,3 +1,6 @@ +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") @@ -7,8 +10,11 @@ describe Hbc::CLI::Fetch, :cask do      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 -    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") +      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::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 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 df02bb1e5..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 @@ -38,20 +44,14 @@ describe Hbc::CLI::Info, :cask do      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 @@ -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 @@ -92,7 +92,7 @@ describe Hbc::CLI::Info, :cask do    it "prints languages specified in the Cask" do      expect { -      Hbc::CLI::Info.run("with-languages") +      described_class.run("with-languages")      }.to output(<<-EOS.undent).to_stdout        with-languages: 1.2.3        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      expect { -      Hbc::CLI::Info.run("without-languages") +      described_class.run("without-languages")      }.to output(<<-EOS.undent).to_stdout        without-languages: 1.2.3        http://example.com/local-caffeine @@ -121,20 +121,4 @@ describe Hbc::CLI::Info, :cask do        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 -  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 diff --git a/Library/Homebrew/test/cask/cli/install_spec.rb b/Library/Homebrew/test/cask/cli/install_spec.rb index e30489789..17a7b9f99 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,12 +15,12 @@ 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.appdir.join("Transmission.app")).to be_a_directory @@ -23,31 +29,31 @@ describe Hbc::CLI::Install, :cask do    end    it "skips double install (without nuking existing installation)" do -    Hbc::CLI::Install.run("local-transmission") -    Hbc::CLI::Install.run("local-transmission") +    described_class.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    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") +    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/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 @@ -55,49 +61,19 @@ describe Hbc::CLI::Install, :cask do    it "properly handles Casks that are not present" do      expect { -      Hbc::CLI::Install.run("notacask") +      described_class.run("notacask")      }.to raise_error(Hbc::CaskUnavailableError)    end    it "returns a suggestion for a misspelled Cask" do      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”?/)    end    it "returns multiple suggestions for a Cask fragment" do      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/)    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 diff --git a/Library/Homebrew/test/cask/cli/list_spec.rb b/Library/Homebrew/test/cask/cli/list_spec.rb index d2d7efd3b..75da82762 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,7 +11,7 @@ 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 @@ -26,7 +30,7 @@ describe Hbc::CLI::List, :cask do      end      expect { -      Hbc::CLI::List.run("--full-name") +      described_class.run("--full-name")      }.to output(<<-EOS.undent).to_stdout        local-caffeine        local-transmission @@ -49,13 +53,13 @@ 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 @@ -72,7 +76,7 @@ describe Hbc::CLI::List, :cask do          .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) }        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..7fca8c248 100644 --- a/Library/Homebrew/test/cask/cli/outdated_spec.rb +++ b/Library/Homebrew/test/cask/cli/outdated_spec.rb @@ -1,3 +1,5 @@ +require_relative "shared_examples/invalid_option" +  describe Hbc::CLI::Outdated, :cask 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)    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 { diff --git a/Library/Homebrew/test/cask/cli/reinstall_spec.rb b/Library/Homebrew/test/cask/cli/reinstall_spec.rb index 3a9c3e2f5..073fbb23c 100644 --- a/Library/Homebrew/test/cask/cli/reinstall_spec.rb +++ b/Library/Homebrew/test/cask/cli/reinstall_spec.rb @@ -1,4 +1,8 @@ +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") diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index 3d58e6a15..a4f796f3c 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -1,8 +1,12 @@ +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([]) 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 2ec506839..9ebd80dfb 100644 --- a/Library/Homebrew/test/cask/cli/uninstall_spec.rb +++ b/Library/Homebrew/test/cask/cli/uninstall_spec.rb @@ -1,4 +1,10 @@ +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") @@ -10,23 +16,23 @@ 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") } +    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") } +    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 @@ -40,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 @@ -57,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 @@ -73,13 +79,13 @@ describe Hbc::CLI::Uninstall, :cask do      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/)      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 @@ -112,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 @@ -127,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 @@ -157,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 502bf8e69..19e8ff261 100644 --- a/Library/Homebrew/test/cask/cli/zap_spec.rb +++ b/Library/Homebrew/test/cask/cli/zap_spec.rb @@ -1,6 +1,12 @@ +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") } +    expect { described_class.run("notacask") }        .to raise_error(Hbc::CaskUnavailableError, /is unavailable/)    end @@ -14,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 @@ -45,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  | 
