diff options
Diffstat (limited to 'Library/Homebrew/test')
62 files changed, 984 insertions, 692 deletions
diff --git a/Library/Homebrew/test/Gemfile b/Library/Homebrew/test/Gemfile index f3c16c710..dbe76b51c 100644 --- a/Library/Homebrew/test/Gemfile +++ b/Library/Homebrew/test/Gemfile @@ -2,11 +2,11 @@ source "https://rubygems.org" gem "parallel_tests" gem "rspec" -gem "rubocop" gem "rspec-its", require: false gem "rspec-wait", require: false +gem "rubocop" group :coverage do - gem "simplecov", require: false gem "codecov", require: false + gem "simplecov", require: false end diff --git a/Library/Homebrew/test/Gemfile.lock b/Library/Homebrew/test/Gemfile.lock index 4d4eefd7d..ccfd91542 100644 --- a/Library/Homebrew/test/Gemfile.lock +++ b/Library/Homebrew/test/Gemfile.lock @@ -2,51 +2,54 @@ GEM remote: https://rubygems.org/ specs: ast (2.3.0) - codecov (0.1.9) + codecov (0.1.10) json simplecov url diff-lcs (1.3) docile (1.1.5) - json (2.0.3) - parallel (1.10.0) - parallel_tests (2.13.0) + json (2.1.0) + parallel (1.11.2) + parallel_tests (2.14.1) parallel parser (2.4.0.0) ast (~> 2.2) powerpack (0.1.1) - rainbow (2.2.1) - rspec (3.5.0) - rspec-core (~> 3.5.0) - rspec-expectations (~> 3.5.0) - rspec-mocks (~> 3.5.0) - rspec-core (3.5.4) - rspec-support (~> 3.5.0) - rspec-expectations (3.5.0) + rainbow (2.2.2) + rake + rake (12.0.0) + rspec (3.6.0) + rspec-core (~> 3.6.0) + rspec-expectations (~> 3.6.0) + rspec-mocks (~> 3.6.0) + rspec-core (3.6.0) + rspec-support (~> 3.6.0) + rspec-expectations (3.6.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.5.0) + rspec-support (~> 3.6.0) rspec-its (1.2.0) rspec-core (>= 3.0.0) rspec-expectations (>= 3.0.0) - rspec-mocks (3.5.0) + rspec-mocks (3.6.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.5.0) - rspec-support (3.5.0) + rspec-support (~> 3.6.0) + rspec-support (3.6.0) rspec-wait (0.0.9) rspec (>= 3, < 4) - rubocop (0.47.1) + rubocop (0.49.1) + parallel (~> 1.10) parser (>= 2.3.3.1, < 3.0) powerpack (~> 0.1) rainbow (>= 1.99.1, < 3.0) ruby-progressbar (~> 1.7) unicode-display_width (~> 1.0, >= 1.0.1) ruby-progressbar (1.8.1) - simplecov (0.13.0) + simplecov (0.14.1) docile (~> 1.1.0) json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.0) - unicode-display_width (1.1.3) + unicode-display_width (1.2.1) url (0.3.2) PLATFORMS @@ -62,4 +65,4 @@ DEPENDENCIES simplecov BUNDLED WITH - 1.14.5 + 1.14.6 diff --git a/Library/Homebrew/test/bash_spec.rb b/Library/Homebrew/test/bash_spec.rb index 1b0f15066..552607810 100644 --- a/Library/Homebrew/test/bash_spec.rb +++ b/Library/Homebrew/test/bash_spec.rb @@ -1,20 +1,20 @@ require "open3" -RSpec::Matchers.define :have_valid_bash_syntax do - match do |file| - stdout, stderr, status = Open3.capture3("/bin/bash", "-n", file) +describe "Bash" do + matcher :have_valid_bash_syntax do + match do |file| + stdout, stderr, status = Open3.capture3("/bin/bash", "-n", file) - @actual = [file, stderr] + @actual = [file, stderr] - stdout.empty? && status.success? - end + stdout.empty? && status.success? + end - failure_message do |(file, stderr)| - "expected that #{file} is a valid Bash file:\n#{stderr}" + failure_message do |(file, stderr)| + "expected that #{file} is a valid Bash file:\n#{stderr}" + end end -end -describe "Bash" do context "brew" do subject { HOMEBREW_LIBRARY_PATH.parent.parent/"bin/brew" } it { is_expected.to have_valid_bash_syntax } diff --git a/Library/Homebrew/test/bottle_hooks_spec.rb b/Library/Homebrew/test/bottle_hooks_spec.rb index 05c6ea7f0..913e3ffba 100644 --- a/Library/Homebrew/test/bottle_hooks_spec.rb +++ b/Library/Homebrew/test/bottle_hooks_spec.rb @@ -1,9 +1,9 @@ require "formula_installer" require "hooks/bottles" -RSpec::Matchers.alias_matcher :pour_bottle, :be_pour_bottle - describe Homebrew::Hooks::Bottles do + alias_matcher :pour_bottle, :be_pour_bottle + subject { FormulaInstaller.new formula } let(:formula) do diff --git a/Library/Homebrew/test/build_environment_spec.rb b/Library/Homebrew/test/build_environment_spec.rb index 5a3cec452..58bec6d1f 100644 --- a/Library/Homebrew/test/build_environment_spec.rb +++ b/Library/Homebrew/test/build_environment_spec.rb @@ -1,8 +1,8 @@ require "build_environment" -RSpec::Matchers.alias_matcher :use_userpaths, :be_userpaths - describe BuildEnvironment do + alias_matcher :use_userpaths, :be_userpaths + let(:env) { described_class.new } describe "#<<" do @@ -38,29 +38,29 @@ describe BuildEnvironment do expect(env).not_to use_userpaths end end -end -describe BuildEnvironmentDSL do - subject { double.extend(described_class) } + describe BuildEnvironment::DSL do + subject { double.extend(described_class) } - context "single argument" do - before(:each) do - subject.instance_eval do - env :userpaths + context "single argument" do + before(:each) do + subject.instance_eval do + env :userpaths + end end - end - its(:env) { is_expected.to use_userpaths } - end + its(:env) { is_expected.to use_userpaths } + end - context "multiple arguments" do - before(:each) do - subject.instance_eval do - env :userpaths, :std + context "multiple arguments" do + before(:each) do + subject.instance_eval do + env :userpaths, :std + end end - end - its(:env) { is_expected.to be_std } - its(:env) { is_expected.to use_userpaths } + its(:env) { is_expected.to be_std } + its(:env) { is_expected.to use_userpaths } + end end end diff --git a/Library/Homebrew/test/build_options_spec.rb b/Library/Homebrew/test/build_options_spec.rb index 5acc12f30..1e6c9ea35 100644 --- a/Library/Homebrew/test/build_options_spec.rb +++ b/Library/Homebrew/test/build_options_spec.rb @@ -1,10 +1,10 @@ require "build_options" require "options" -RSpec::Matchers.alias_matcher :be_built_with, :be_with -RSpec::Matchers.alias_matcher :be_built_without, :be_without - describe BuildOptions do + alias_matcher :be_built_with, :be_with + alias_matcher :be_built_without, :be_without + subject { described_class.new(args, opts) } let(:bad_build) { described_class.new(bad_args, opts) } let(:args) { Options.create(%w[--with-foo --with-bar --without-qux]) } 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..569b831de 100644 --- a/Library/Homebrew/test/cask/cli_spec.rb +++ b/Library/Homebrew/test/cask/cli_spec.rb @@ -13,7 +13,14 @@ describe Hbc::CLI, :cask do ]) end - context ".process" do + context "when no option is specified" do + it "--binaries is true by default" do + command = Hbc::CLI::Install.new("some-cask") + expect(command.binaries?).to be true + end + end + + context "::run" do let(:noop_command) { double("CLI::Noop") } before do @@ -30,37 +37,28 @@ 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") - 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 diff --git a/Library/Homebrew/test/cask/download_strategy_spec.rb b/Library/Homebrew/test/cask/download_strategy_spec.rb index 91fe934be..27f1ad410 100644 --- a/Library/Homebrew/test/cask/download_strategy_spec.rb +++ b/Library/Homebrew/test/cask/download_strategy_spec.rb @@ -1,6 +1,6 @@ describe "download strategies", :cask do let(:url) { "http://example.com/cask.dmg" } - let(:url_options) { Hash.new } + let(:url_options) { {} } let(:cask) { instance_double(Hbc::Cask, token: "some-cask", url: Hbc::URL.new(url, url_options), diff --git a/Library/Homebrew/test/cask/dsl/appcast_spec.rb b/Library/Homebrew/test/cask/dsl/appcast_spec.rb new file mode 100644 index 000000000..b8903b1be --- /dev/null +++ b/Library/Homebrew/test/cask/dsl/appcast_spec.rb @@ -0,0 +1,74 @@ +require "cmd/cask" + +describe Hbc::DSL::Appcast do + subject { described_class.new(url, params) } + + let(:url) { "http://example.com" } + let(:uri) { Hbc::UnderscoreSupportingURI.parse(url) } + let(:params) { {} } + + describe "#to_s" do + it "returns the parsed URI string" do + expect(subject.to_s).to eq("http://example.com") + end + end + + describe "#to_yaml" do + let(:yaml) { [uri, params].to_yaml } + + context "with empty parameters" do + it "returns an YAML serialized array composed of the URI and parameters" do + expect(subject.to_yaml).to eq(yaml) + end + end + + context "with checkpoint in parameters" do + let(:params) { { checkpoint: "abc123" } } + + it "returns an YAML serialized array composed of the URI and parameters" do + expect(subject.to_yaml).to eq(yaml) + end + end + end + + describe "#calculate_checkpoint" do + before do + expect(Hbc::SystemCommand).to receive(:run).with(*cmd_args).and_return(cmd_result) + allow(cmd_result).to receive(:success?).and_return(cmd_success) + allow(cmd_result).to receive(:stdout).and_return(cmd_stdout) + end + + context "when server returns a successful HTTP status" do + let(:cmd_args) { ["/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", Hbc::URL::FAKE_USER_AGENT, "--fail", uri], print_stderr: false] } + let(:cmd_result) { double("Hbc::SystemCommand::Result") } + let(:cmd_success) { true } + let(:cmd_stdout) { "hello world" } + + it "generates the content digest hash and returns a hash with the command result and the digest hash for the checkpoint" do + expected_digest = Digest::SHA2.hexdigest(cmd_stdout) + expected_result = { + checkpoint: expected_digest, + command_result: cmd_result, + } + + expect(subject.calculate_checkpoint).to eq(expected_result) + end + end + + context "when server returns a non-successful HTTP status" do + let(:cmd_args) { ["/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", Hbc::URL::FAKE_USER_AGENT, "--fail", uri], print_stderr: false] } + let(:cmd_result) { double("Hbc::SystemCommand::Result") } + let(:cmd_success) { false } + let(:cmd_stdout) { "some error message from the server" } + + it "returns a hash with the command result and nil for the checkpoint" do + expected_result = { + checkpoint: nil, + command_result: cmd_result, + } + + expect(subject.calculate_checkpoint).to eq(expected_result) + end + end + end +end diff --git a/Library/Homebrew/test/cask/installer_spec.rb b/Library/Homebrew/test/cask/installer_spec.rb index 59d61bbdd..0ae7c14a5 100644 --- a/Library/Homebrew/test/cask/installer_spec.rb +++ b/Library/Homebrew/test/cask/installer_spec.rb @@ -161,6 +161,19 @@ describe Hbc::Installer, :cask do expect(Hbc.appdir.join("container-lzma--#{asset.version}")).to be_a_file end + it "works with gpg-based Casks" do + skip("gpg not installed") if which("gpg").nil? + asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-gpg.rb") + + allow(asset).to receive(:depends_on).and_return(empty_depends_on_stub) + shutup do + Hbc::Installer.new(asset).install + end + + expect(Hbc.caskroom.join("container-gpg", asset.version)).to be_a_directory + expect(Hbc.appdir.join("container")).to be_a_file + end + it "blows up on a bad checksum" do bad_checksum = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/bad-checksum.rb") expect { diff --git a/Library/Homebrew/test/cmd/--env_spec.rb b/Library/Homebrew/test/cmd/--env_spec.rb index 7dd84132a..9ccdaa6f1 100644 --- a/Library/Homebrew/test/cmd/--env_spec.rb +++ b/Library/Homebrew/test/cmd/--env_spec.rb @@ -9,7 +9,7 @@ describe "brew --env", :integration_test do describe "--shell=bash" do it "prints the Homebrew build environment variables in Bash syntax" do expect { brew "--env", "--shell=bash" } - .to output(/export CMAKE_PREFIX_PATH="#{Regexp.quote(HOMEBREW_PREFIX.to_s)}"/).to_stdout + .to output(/export CMAKE_PREFIX_PATH="#{Regexp.quote(HOMEBREW_PREFIX)}"/).to_stdout .and not_to_output.to_stderr .and be_a_success end @@ -18,7 +18,7 @@ describe "brew --env", :integration_test do describe "--shell=fish" do it "prints the Homebrew build environment variables in Fish syntax" do expect { brew "--env", "--shell=fish" } - .to output(/set [-]gx CMAKE_PREFIX_PATH "#{Regexp.quote(HOMEBREW_PREFIX.to_s)}"/).to_stdout + .to output(/set [-]gx CMAKE_PREFIX_PATH "#{Regexp.quote(HOMEBREW_PREFIX)}"/).to_stdout .and not_to_output.to_stderr .and be_a_success end @@ -27,7 +27,7 @@ describe "brew --env", :integration_test do describe "--shell=tcsh" do it "prints the Homebrew build environment variables in Tcsh syntax" do expect { brew "--env", "--shell=tcsh" } - .to output(/setenv CMAKE_PREFIX_PATH #{Regexp.quote(HOMEBREW_PREFIX.to_s)};/).to_stdout + .to output(/setenv CMAKE_PREFIX_PATH #{Regexp.quote(HOMEBREW_PREFIX)};/).to_stdout .and not_to_output.to_stderr .and be_a_success end diff --git a/Library/Homebrew/test/cmd/--version_spec.rb b/Library/Homebrew/test/cmd/--version_spec.rb index 8992629d7..8dc183882 100644 --- a/Library/Homebrew/test/cmd/--version_spec.rb +++ b/Library/Homebrew/test/cmd/--version_spec.rb @@ -1,7 +1,7 @@ describe "brew --version", :integration_test do it "prints the Homebrew version" do expect { brew "--version" } - .to output(/^Homebrew #{Regexp.escape(HOMEBREW_VERSION.to_s)}\n/).to_stdout + .to output(/^Homebrew #{Regexp.escape(HOMEBREW_VERSION)}\n/).to_stdout .and not_to_output.to_stderr .and be_a_success end diff --git a/Library/Homebrew/test/cmd/install_spec.rb b/Library/Homebrew/test/cmd/install_spec.rb index b819c17be..6fff44131 100644 --- a/Library/Homebrew/test/cmd/install_spec.rb +++ b/Library/Homebrew/test/cmd/install_spec.rb @@ -23,7 +23,7 @@ describe "brew install", :integration_test do .and be_a_success expect { brew "install", "testball1" } - .to output(/testball1\-0\.1 already installed/).to_stderr + .to output(/testball1\ 0\.1 is already installed/).to_stderr .and not_to_output.to_stdout .and be_a_success @@ -51,7 +51,7 @@ describe "brew install", :integration_test do install_and_rename_coretap_formula "testball1", "testball2" expect { brew "install", "testball2" } .to output(/testball1 already installed, it's just not migrated/).to_stderr - .and output(/You can migrate formula with `brew migrate testball2`/).to_stdout + .and not_to_output.to_stdout .and be_a_success end @@ -106,8 +106,8 @@ describe "brew install", :integration_test do end expect { brew "install", "testball1" } - .to output(/already installed, however linked version is/).to_stderr - .and output(/`brew switch testball1 2.0`/).to_stdout + .to output(/2.0 is already installed/).to_stderr + .and not_to_output.to_stdout .and be_a_success expect { brew "unlink", "testball1" } @@ -141,8 +141,8 @@ describe "brew install", :integration_test do EOS expect { brew "install", "testball1" } - .to output(/keg-only and another version is linked to opt/).to_stderr - .and output(/Use `brew install --force`/).to_stdout + .to output(/testball1 1.0 is already installed/).to_stderr + .and not_to_output.to_stdout .and be_a_success expect { brew "install", "testball1", "--force" } @@ -185,7 +185,7 @@ describe "brew install", :integration_test do .and be_a_success expect { brew "install", "testball1", "--HEAD", "--ignore-dependencies" } - .to output(/testball1\-HEAD\-d5eb689 already installed/).to_stderr + .to output(/testball1 HEAD\-d5eb689 is already installed/).to_stderr .and not_to_output.to_stdout .and be_a_success diff --git a/Library/Homebrew/test/cmd/style_spec.rb b/Library/Homebrew/test/cmd/style_spec.rb new file mode 100644 index 000000000..3c4c3f809 --- /dev/null +++ b/Library/Homebrew/test/cmd/style_spec.rb @@ -0,0 +1,34 @@ +require "cmd/style" + +describe "brew style" do + around(:each) do |example| + begin + FileUtils.ln_s HOMEBREW_LIBRARY_PATH, HOMEBREW_LIBRARY/"Homebrew" + FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop.yml", HOMEBREW_LIBRARY/".rubocop.yml" + + example.run + ensure + FileUtils.rm_f HOMEBREW_LIBRARY/"Homebrew" + FileUtils.rm_f HOMEBREW_LIBRARY/".rubocop.yml" + end + end + + describe "Homebrew::check_style_json" do + let(:dir) { mktmpdir } + + it "returns RubocopResults when RuboCop reports offenses" do + formula = dir/"my-formula.rb" + + formula.write <<-'EOS'.undent + class MyFormula < Formula + + end + EOS + + rubocop_result = Homebrew.check_style_json([formula]) + + expect(rubocop_result.file_offenses(formula.realpath.to_s).map(&:message)) + .to include("Extra empty line detected at class body beginning.") + end + end +end diff --git a/Library/Homebrew/test/compiler_failure_spec.rb b/Library/Homebrew/test/compiler_failure_spec.rb index b4fab0b27..47b35d3bc 100644 --- a/Library/Homebrew/test/compiler_failure_spec.rb +++ b/Library/Homebrew/test/compiler_failure_spec.rb @@ -1,8 +1,8 @@ require "compilers" -RSpec::Matchers.alias_matcher :fail_with, :be_fails_with - describe CompilerFailure do + alias_matcher :fail_with, :be_fails_with + describe "::create" do it "creates a failure when given a symbol" do failure = described_class.create(:clang) diff --git a/Library/Homebrew/test/dependable_spec.rb b/Library/Homebrew/test/dependable_spec.rb index b646b7634..172305aa0 100644 --- a/Library/Homebrew/test/dependable_spec.rb +++ b/Library/Homebrew/test/dependable_spec.rb @@ -1,8 +1,8 @@ require "dependable" -RSpec::Matchers.alias_matcher :be_a_build_dependency, :be_build - describe Dependable do + alias_matcher :be_a_build_dependency, :be_build + subject { double(tags: tags).extend(described_class) } let(:tags) { ["foo", "bar", :build] } diff --git a/Library/Homebrew/test/dependency_collector_spec.rb b/Library/Homebrew/test/dependency_collector_spec.rb index 82d117939..c25ea9cf9 100644 --- a/Library/Homebrew/test/dependency_collector_spec.rb +++ b/Library/Homebrew/test/dependency_collector_spec.rb @@ -1,8 +1,8 @@ require "dependency_collector" -RSpec::Matchers.alias_matcher :be_a_build_requirement, :be_build - describe DependencyCollector do + alias_matcher :be_a_build_requirement, :be_build + def find_dependency(name) subject.deps.find { |dep| dep.name == name } end diff --git a/Library/Homebrew/test/dependency_spec.rb b/Library/Homebrew/test/dependency_spec.rb index 4af779cc3..4f1e8d474 100644 --- a/Library/Homebrew/test/dependency_spec.rb +++ b/Library/Homebrew/test/dependency_spec.rb @@ -1,9 +1,9 @@ require "dependency" -RSpec::Matchers.alias_matcher :be_a_build_dependency, :be_build -RSpec::Matchers.alias_matcher :be_a_runtime_dependency, :be_run - describe Dependency do + alias_matcher :be_a_build_dependency, :be_build + alias_matcher :be_a_runtime_dependency, :be_run + describe "::new" do it "accepts a single tag" do dep = described_class.new("foo", %w[bar]) diff --git a/Library/Homebrew/test/dev-cmd/audit_spec.rb b/Library/Homebrew/test/dev-cmd/audit_spec.rb index c914a9a20..25a179342 100644 --- a/Library/Homebrew/test/dev-cmd/audit_spec.rb +++ b/Library/Homebrew/test/dev-cmd/audit_spec.rb @@ -1,10 +1,6 @@ require "dev-cmd/audit" require "formulary" -RSpec::Matchers.alias_matcher :have_data, :be_data -RSpec::Matchers.alias_matcher :have_end, :be_end -RSpec::Matchers.alias_matcher :have_trailing_newline, :be_trailing_newline - module Count def self.increment @count ||= 0 @@ -13,6 +9,10 @@ module Count end describe FormulaText do + alias_matcher :have_data, :be_data + alias_matcher :have_end, :be_end + alias_matcher :have_trailing_newline, :be_trailing_newline + let(:dir) { mktmpdir } def formula_text(name, body = nil, options = {}) @@ -305,23 +305,6 @@ describe FormulaAuditor do end end - specify "#audit_caveats" do - fa = formula_auditor "foo", <<-EOS.undent - class Foo < Formula - homepage "http://example.com/foo" - url "http://example.com/foo-1.0.tgz" - - def caveats - "setuid" - end - end - EOS - - fa.audit_caveats - expect(fa.problems) - .to eq(["Don't recommend setuid in the caveats, suggest sudo instead."]) - end - describe "#audit_keg_only_style" do specify "keg_only_needs_downcasing" do fa = formula_auditor "foo", <<-EOS.undent, strict: true @@ -385,131 +368,6 @@ describe FormulaAuditor do end end - describe "#audit_homepage" do - specify "homepage URLs" do - fa = formula_auditor "foo", <<-EOS.undent, online: true - class Foo < Formula - homepage "ftp://example.com/foo" - url "http://example.com/foo-1.0.tgz" - end - EOS - - fa.audit_homepage - expect(fa.problems) - .to eq(["The homepage should start with http or https (URL is #{fa.formula.homepage})."]) - - formula_homepages = { - "bar" => "http://www.freedesktop.org/wiki/bar", - "baz" => "http://www.freedesktop.org/wiki/Software/baz", - "qux" => "https://code.google.com/p/qux", - "quux" => "http://github.com/quux", - "corge" => "http://savannah.nongnu.org/corge", - "grault" => "http://grault.github.io/", - "garply" => "http://www.gnome.org/garply", - "sf1" => "http://foo.sourceforge.net/", - "sf2" => "http://foo.sourceforge.net", - "sf3" => "http://foo.sf.net/", - "sf4" => "http://foo.sourceforge.io/", - "waldo" => "http://www.gnu.org/waldo", - } - - formula_homepages.each do |name, homepage| - fa = formula_auditor name, <<-EOS.undent - class #{Formulary.class_s(name)} < Formula - homepage "#{homepage}" - url "http://example.com/#{name}-1.0.tgz" - end - EOS - - fa.audit_homepage - if homepage =~ %r{http:\/\/www\.freedesktop\.org} - if homepage =~ /Software/ - expect(fa.problems.first).to match( - "#{homepage} should be styled " \ - "`https://wiki.freedesktop.org/www/Software/project_name`", - ) - else - expect(fa.problems.first).to match( - "#{homepage} should be styled " \ - "`https://wiki.freedesktop.org/project_name`", - ) - end - elsif homepage =~ %r{https:\/\/code\.google\.com} - expect(fa.problems.first) - .to match("#{homepage} should end with a slash") - elsif homepage =~ /foo\.(sf|sourceforge)\.net/ - expect(fa.problems.first) - .to match("#{homepage} should be `https://foo.sourceforge.io/`") - else - expect(fa.problems.first) - .to match("Please use https:// for #{homepage}") - end - end - end - - specify "missing homepage" do - fa = formula_auditor "foo", <<-EOS.undent, online: true - class Foo < Formula - url "http://example.com/foo-1.0.tgz" - end - EOS - - fa.audit_homepage - expect(fa.problems.first).to match("Formula should have a homepage.") - end - end - - describe "#audit_text" do - specify "xcodebuild suggests symroot" do - fa = formula_auditor "foo", <<-EOS.undent - class Foo < Formula - url "http://example.com/foo-1.0.tgz" - homepage "http://example.com" - - def install - xcodebuild "-project", "meow.xcodeproject" - end - end - EOS - - fa.audit_text - expect(fa.problems.first) - .to match('xcodebuild should be passed an explicit "SYMROOT"') - end - - specify "bare xcodebuild also suggests symroot" do - fa = formula_auditor "foo", <<-EOS.undent - class Foo < Formula - url "http://example.com/foo-1.0.tgz" - homepage "http://example.com" - - def install - xcodebuild - end - end - EOS - - fa.audit_text - expect(fa.problems.first) - .to match('xcodebuild should be passed an explicit "SYMROOT"') - end - - specify "disallow go get usage" do - fa = formula_auditor "foo", <<-EOS.undent - class Foo <Formula - url "http://example.com/foo-1.0.tgz" - - def install - system "go", "get", "bar" - end - end - EOS - fa.audit_text - expect(fa.problems.first) - .to match("Formulae should not use `go get`. If non-vendored resources are required use `go_resource`s.") - end - end - describe "#audit_revision_and_version_scheme" do let(:origin_tap_path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" } let(:formula_subpath) { "Formula/foo#{@foo_version}.rb" } diff --git a/Library/Homebrew/test/dev-cmd/pull_spec.rb b/Library/Homebrew/test/dev-cmd/pull_spec.rb index 2ebe144bb..cfd786de0 100644 --- a/Library/Homebrew/test/dev-cmd/pull_spec.rb +++ b/Library/Homebrew/test/dev-cmd/pull_spec.rb @@ -14,7 +14,7 @@ describe "brew pull", :integration_test do end end - expect { brew "pull", "https://bot.brew.sh/job/Homebrew\%20Testing/1028/" } + expect { brew "pull", "https://jenkins.brew.sh/job/Homebrew\%20Testing/1028/" } .to output(/Testing URLs require `\-\-bottle`!/).to_stderr .and not_to_output.to_stdout .and be_a_failure diff --git a/Library/Homebrew/test/diagnostic_spec.rb b/Library/Homebrew/test/diagnostic_spec.rb index 6e2c09268..058b9823c 100644 --- a/Library/Homebrew/test/diagnostic_spec.rb +++ b/Library/Homebrew/test/diagnostic_spec.rb @@ -7,7 +7,7 @@ describe Homebrew::Diagnostic::Checks do end specify "#check_path_for_trailing_slashes" do - ENV["PATH"] += File::PATH_SEPARATOR + "/foo/bar/" + ENV["HOMEBREW_PATH"] += File::PATH_SEPARATOR + "/foo/bar/" expect(subject.check_path_for_trailing_slashes) .to match("Some directories in your path end in a slash") end @@ -43,8 +43,10 @@ describe Homebrew::Diagnostic::Checks do specify "#check_access_lock_dir" do begin + prev_mode = HOMEBREW_LOCK_DIR.stat.mode mode = HOMEBREW_LOCK_DIR.stat.mode & 0777 HOMEBREW_LOCK_DIR.chmod 0555 + expect(HOMEBREW_LOCK_DIR.stat.mode).not_to eq(prev_mode) expect(subject.check_access_lock_dir) .to match("#{HOMEBREW_LOCK_DIR} isn't writable.") @@ -88,13 +90,6 @@ describe Homebrew::Diagnostic::Checks do end end - specify "#check_homebrew_prefix" do - ENV.delete("JENKINS_HOME") - # the integration tests are run in a special prefix - expect(subject.check_homebrew_prefix) - .to match("Your Homebrew's prefix is not /usr/local.") - end - specify "#check_user_path_1" do bin = HOMEBREW_PREFIX/"bin" sep = File::PATH_SEPARATOR diff --git a/Library/Homebrew/test/formatter_spec.rb b/Library/Homebrew/test/formatter_spec.rb index 6357853d8..1a74e3405 100644 --- a/Library/Homebrew/test/formatter_spec.rb +++ b/Library/Homebrew/test/formatter_spec.rb @@ -4,11 +4,11 @@ require "utils/tty" describe Formatter do describe "::columns" do let(:input) { - [ - "aa", - "bbb", - "ccc", - "dd", + %w[ + aa + bbb + ccc + dd ] } subject { described_class.columns(input) } diff --git a/Library/Homebrew/test/formula_installer_bottle_spec.rb b/Library/Homebrew/test/formula_installer_bottle_spec.rb index 8409e1ac7..824cdb36d 100644 --- a/Library/Homebrew/test/formula_installer_bottle_spec.rb +++ b/Library/Homebrew/test/formula_installer_bottle_spec.rb @@ -5,9 +5,9 @@ require "tab" require "test/support/fixtures/testball" require "test/support/fixtures/testball_bottle" -RSpec::Matchers.alias_matcher :pour_bottle, :be_pour_bottle - describe FormulaInstaller do + alias_matcher :pour_bottle, :be_pour_bottle + matcher :be_poured_from_bottle do match(&:poured_from_bottle) end diff --git a/Library/Homebrew/test/formula_installer_spec.rb b/Library/Homebrew/test/formula_installer_spec.rb index efe2bf5a2..d309a17da 100644 --- a/Library/Homebrew/test/formula_installer_spec.rb +++ b/Library/Homebrew/test/formula_installer_spec.rb @@ -5,10 +5,10 @@ require "tab" require "test/support/fixtures/testball" require "test/support/fixtures/testball_bottle" -RSpec::Matchers.define_negated_matcher :need_bottle, :be_bottle_unneeded -RSpec::Matchers.alias_matcher :have_disabled_bottle, :be_bottle_disabled - describe FormulaInstaller do + define_negated_matcher :need_bottle, :be_bottle_unneeded + alias_matcher :have_disabled_bottle, :be_bottle_disabled + matcher :be_poured_from_bottle do match(&:poured_from_bottle) end diff --git a/Library/Homebrew/test/formula_spec.rb b/Library/Homebrew/test/formula_spec.rb index 1f98ca525..364dbfe98 100644 --- a/Library/Homebrew/test/formula_spec.rb +++ b/Library/Homebrew/test/formula_spec.rb @@ -1,19 +1,19 @@ require "test/support/fixtures/testball" require "formula" -RSpec::Matchers.alias_matcher :follow_installed_alias, :be_follow_installed_alias -RSpec::Matchers.alias_matcher :have_any_version_installed, :be_any_version_installed -RSpec::Matchers.alias_matcher :need_migration, :be_migration_needed +describe Formula do + alias_matcher :follow_installed_alias, :be_follow_installed_alias + alias_matcher :have_any_version_installed, :be_any_version_installed + alias_matcher :need_migration, :be_migration_needed -RSpec::Matchers.alias_matcher :have_changed_installed_alias_target, :be_installed_alias_target_changed -RSpec::Matchers.alias_matcher :supersede_an_installed_formula, :be_supersedes_an_installed_formula -RSpec::Matchers.alias_matcher :have_changed_alias, :be_alias_changed + alias_matcher :have_changed_installed_alias_target, :be_installed_alias_target_changed + alias_matcher :supersede_an_installed_formula, :be_supersedes_an_installed_formula + alias_matcher :have_changed_alias, :be_alias_changed -RSpec::Matchers.alias_matcher :have_option_defined, :be_option_defined -RSpec::Matchers.alias_matcher :have_test_defined, :be_test_defined -RSpec::Matchers.alias_matcher :pour_bottle, :be_pour_bottle + alias_matcher :have_option_defined, :be_option_defined + alias_matcher :have_test_defined, :be_test_defined + alias_matcher :pour_bottle, :be_pour_bottle -describe Formula do describe "::new" do let(:klass) do Class.new(described_class) do @@ -683,7 +683,7 @@ describe Formula do end expect(f5.deps.map(&:name)).to eq(["f3", "f4"]) - expect(f5.recursive_dependencies.map(&:name)).to eq(["f1", "f2", "f3", "f4"]) + expect(f5.recursive_dependencies.map(&:name)).to eq(%w[f1 f2 f3 f4]) expect(f5.runtime_dependencies.map(&:name)).to eq(["f1", "f4"]) end diff --git a/Library/Homebrew/test/formula_lock_spec.rb b/Library/Homebrew/test/lock_file_spec.rb index 9b5ece813..82c47a70a 100644 --- a/Library/Homebrew/test/formula_lock_spec.rb +++ b/Library/Homebrew/test/lock_file_spec.rb @@ -1,6 +1,6 @@ -require "formula_lock" +require "lock_file" -describe FormulaLock do +describe LockFile do subject { described_class.new("foo") } describe "#lock" do @@ -24,7 +24,7 @@ describe FormulaLock do expect { subject.unlock }.not_to raise_error end - it "unlocks a locked Formula" do + it "unlocks when locked" do subject.lock subject.unlock diff --git a/Library/Homebrew/test/migrator_spec.rb b/Library/Homebrew/test/migrator_spec.rb index 90ee9d8ff..900c10c02 100644 --- a/Library/Homebrew/test/migrator_spec.rb +++ b/Library/Homebrew/test/migrator_spec.rb @@ -44,9 +44,7 @@ describe Migrator do end after(:each) do - if !old_keg_record.parent.symlink? && old_keg_record.directory? - keg.unlink - end + keg.unlink if !old_keg_record.parent.symlink? && old_keg_record.directory? if new_keg_record.directory? new_keg = Keg.new(new_keg_record) diff --git a/Library/Homebrew/test/os/mac/dependency_collector_spec.rb b/Library/Homebrew/test/os/mac/dependency_collector_spec.rb index 21b15cd99..688149021 100644 --- a/Library/Homebrew/test/os/mac/dependency_collector_spec.rb +++ b/Library/Homebrew/test/os/mac/dependency_collector_spec.rb @@ -1,8 +1,8 @@ require "dependency_collector" -RSpec::Matchers.alias_matcher :need_tar_xz_dependency, :be_tar_needs_xz_dependency - describe DependencyCollector do + alias_matcher :need_tar_xz_dependency, :be_tar_needs_xz_dependency + after(:each) do described_class.clear_cache end diff --git a/Library/Homebrew/test/os/mac/diagnostic_spec.rb b/Library/Homebrew/test/os/mac/diagnostic_spec.rb index d2b38a332..787f80fec 100644 --- a/Library/Homebrew/test/os/mac/diagnostic_spec.rb +++ b/Library/Homebrew/test/os/mac/diagnostic_spec.rb @@ -39,4 +39,10 @@ describe Homebrew::Diagnostic::Checks do expect(subject.check_xcode_8_without_clt_on_el_capitan) .to match("You have Xcode 8 installed without the CLT") end + + specify "#check_homebrew_prefix" do + # the integration tests are run in a special prefix + expect(subject.check_homebrew_prefix) + .to match("Your Homebrew's prefix is not /usr/local.") + end end diff --git a/Library/Homebrew/test/pathname_spec.rb b/Library/Homebrew/test/pathname_spec.rb index 77cb6cfed..0bc19c5ac 100644 --- a/Library/Homebrew/test/pathname_spec.rb +++ b/Library/Homebrew/test/pathname_spec.rb @@ -104,7 +104,7 @@ describe Pathname do end it "preserves permissions" do - File.open(file, "w", 0100777).close + File.open(file, "w", 0100777) {} file.atomic_write("CONTENT") expect(file.stat.mode).to eq(0100777 & ~File.umask) end diff --git a/Library/Homebrew/test/requirement_spec.rb b/Library/Homebrew/test/requirement_spec.rb index 959041cf4..71372aa69 100644 --- a/Library/Homebrew/test/requirement_spec.rb +++ b/Library/Homebrew/test/requirement_spec.rb @@ -1,10 +1,10 @@ require "extend/ENV" require "requirement" -RSpec::Matchers.alias_matcher :have_a_default_formula, :be_a_default_formula -RSpec::Matchers.alias_matcher :be_a_build_requirement, :be_a_build - describe Requirement do + alias_matcher :have_a_default_formula, :be_a_default_formula + alias_matcher :be_a_build_requirement, :be_a_build + subject { klass.new } let(:klass) { Class.new(described_class) } diff --git a/Library/Homebrew/test/rubocops/caveats_cop_spec.rb b/Library/Homebrew/test/rubocops/caveats_cop_spec.rb new file mode 100644 index 000000000..d44808a5d --- /dev/null +++ b/Library/Homebrew/test/rubocops/caveats_cop_spec.rb @@ -0,0 +1,42 @@ +require "rubocop" +require "rubocop/rspec/support" +require_relative "../../extend/string" +require_relative "../../rubocops/caveats_cop" + +describe RuboCop::Cop::FormulaAudit::Caveats do + subject(:cop) { described_class.new } + + context "When auditing caveats" do + it "When there is setuid mentioned in caveats" do + source = <<-EOS.undent + class Foo < Formula + homepage "http://example.com/foo" + url "http://example.com/foo-1.0.tgz" + + def caveats + "setuid" + end + end + EOS + + expected_offenses = [{ message: "Don't recommend setuid in the caveats, suggest sudo instead.", + severity: :convention, + line: 6, + column: 5, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + def expect_offense(expected, actual) + expect(actual.message).to eq(expected[:message]) + expect(actual.severity).to eq(expected[:severity]) + expect(actual.line).to eq(expected[:line]) + expect(actual.column).to eq(expected[:column]) + end + end +end diff --git a/Library/Homebrew/test/rubocops/components_order_cop_spec.rb b/Library/Homebrew/test/rubocops/components_order_cop_spec.rb index 05ff53d8f..25467c635 100644 --- a/Library/Homebrew/test/rubocops/components_order_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/components_order_cop_spec.rb @@ -113,4 +113,51 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsOrder do expect(actual.column).to eq(expected[:column]) end end + + context "When auditing formula components order with autocorrect" do + it "When url precedes homepage" do + source = <<-EOS.undent + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + homepage "http://example.com" + end + EOS + correct_source = <<-EOS.undent + class Foo < Formula + homepage "http://example.com" + url "http://example.com/foo-1.0.tgz" + end + EOS + + corrected_source = autocorrect_source(cop, source) + expect(corrected_source).to eq(correct_source) + end + + it "When `resource` precedes `depends_on`" do + source = <<-EOS.undent + class Foo < Formula + url "https://example.com/foo-1.0.tgz" + + resource "foo2" do + url "https://example.com/foo-2.0.tgz" + end + + depends_on "openssl" + end + EOS + correct_source = <<-EOS.undent + class Foo < Formula + url "https://example.com/foo-1.0.tgz" + + depends_on "openssl" + + resource "foo2" do + url "https://example.com/foo-2.0.tgz" + end + end + EOS + corrected_source = autocorrect_source(cop, source) + expect(corrected_source).to eq(correct_source) + end + end end diff --git a/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb index 581667935..f6436d6a3 100644 --- a/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb @@ -31,7 +31,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do source = <<-EOS.undent class Foo < Formula url 'http://example.com/foo-1.0.tgz' - desc '#{"bar"*30}' + desc '#{"bar" * 30}' end EOS @@ -51,6 +51,31 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do end end + it "When desc is multiline string" do + source = <<-EOS.undent + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + desc '#{"bar" * 10}'\ + '#{"foo" * 21}' + end + EOS + + msg = <<-EOS.undent + Description is too long. "name: desc" should be less than 80 characters. + Length is calculated as Foo + desc. (currently 98) + EOS + expected_offenses = [{ message: msg, + severity: :convention, + line: 3, + column: 2, + source: source }] + + inspect_source(cop, source) + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + it "When wrong \"command-line\" usage in desc" do source = <<-EOS.undent class Foo < Formula @@ -95,7 +120,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do source = <<-EOS.undent class Foo < Formula url 'http://example.com/foo-1.0.tgz' - desc 'Foo' + desc 'Foo: foobar' end EOS diff --git a/Library/Homebrew/test/rubocops/homepage_cop_spec.rb b/Library/Homebrew/test/rubocops/homepage_cop_spec.rb new file mode 100644 index 000000000..c03efd825 --- /dev/null +++ b/Library/Homebrew/test/rubocops/homepage_cop_spec.rb @@ -0,0 +1,124 @@ +require "rubocop" +require "rubocop/rspec/support" +require_relative "../../extend/string" +require_relative "../../rubocops/homepage_cop" + +describe RuboCop::Cop::FormulaAudit::Homepage do + subject(:cop) { described_class.new } + + context "When auditing homepage" do + it "When there is no homepage" do + source = <<-EOS.undent + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + end + EOS + + expected_offenses = [{ message: "Formula should have a homepage.", + severity: :convention, + line: 1, + column: 0, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "Homepage with ftp" do + source = <<-EOS.undent + class Foo < Formula + homepage "ftp://example.com/foo" + url "http://example.com/foo-1.0.tgz" + end + EOS + + expected_offenses = [{ message: "The homepage should start with http or https (URL is ftp://example.com/foo).", + severity: :convention, + line: 2, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "Homepage URLs" do + formula_homepages = { + "bar" => "http://www.freedesktop.org/wiki/bar", + "baz" => "http://www.freedesktop.org/wiki/Software/baz", + "qux" => "https://code.google.com/p/qux", + "quux" => "http://github.com/quux", + "corge" => "http://savannah.nongnu.org/corge", + "grault" => "http://grault.github.io/", + "garply" => "http://www.gnome.org/garply", + "sf1" => "http://foo.sourceforge.net/", + "sf2" => "http://foo.sourceforge.net", + "sf3" => "http://foo.sf.net/", + "sf4" => "http://foo.sourceforge.io/", + "waldo" => "http://www.gnu.org/waldo", + } + + formula_homepages.each do |name, homepage| + source = <<-EOS.undent + class #{name.capitalize} < Formula + homepage "#{homepage}" + url "http://example.com/#{name}-1.0.tgz" + end + EOS + + inspect_source(cop, source) + if homepage =~ %r{http:\/\/www\.freedesktop\.org} + if homepage =~ /Software/ + expected_offenses = [{ message: "#{homepage} should be styled " \ + "`https://wiki.freedesktop.org/www/Software/project_name`", + severity: :convention, + line: 2, + column: 2, + source: source }] + else + expected_offenses = [{ message: "#{homepage} should be styled " \ + "`https://wiki.freedesktop.org/project_name`", + severity: :convention, + line: 2, + column: 2, + source: source }] + end + elsif homepage =~ %r{https:\/\/code\.google\.com} + expected_offenses = [{ message: "#{homepage} should end with a slash", + severity: :convention, + line: 2, + column: 2, + source: source }] + elsif homepage =~ /foo\.(sf|sourceforge)\.net/ + expected_offenses = [{ message: "#{homepage} should be `https://foo.sourceforge.io/`", + severity: :convention, + line: 2, + column: 2, + source: source }] + else + expected_offenses = [{ message: "Please use https:// for #{homepage}", + severity: :convention, + line: 2, + column: 2, + source: source }] + end + expected_offenses.zip([cop.offenses.last]).each do |expected, actual| + expect_offense(expected, actual) + end + end + end + + def expect_offense(expected, actual) + expect(actual.message).to eq(expected[:message]) + expect(actual.severity).to eq(expected[:severity]) + expect(actual.line).to eq(expected[:line]) + expect(actual.column).to eq(expected[:column]) + end + end +end diff --git a/Library/Homebrew/test/rubocops/text_cop_spec.rb b/Library/Homebrew/test/rubocops/text_cop_spec.rb new file mode 100644 index 000000000..b218e9c25 --- /dev/null +++ b/Library/Homebrew/test/rubocops/text_cop_spec.rb @@ -0,0 +1,261 @@ +require "rubocop" +require "rubocop/rspec/support" +require_relative "../../extend/string" +require_relative "../../rubocops/text_cop" + +describe RuboCop::Cop::FormulaAudit::Text do + subject(:cop) { described_class.new } + + context "When auditing formula text" do + it "When xcodebuild is called without SYMROOT" do + source = <<-EOS.undent + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + homepage "http://example.com" + + def install + xcodebuild "-project", "meow.xcodeproject" + end + end + EOS + + expected_offenses = [{ message: "xcodebuild should be passed an explicit \"SYMROOT\"", + severity: :convention, + line: 6, + column: 4, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "When xcodebuild is called without any args" do + source = <<-EOS.undent + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + homepage "http://example.com" + + def install + xcodebuild + end + end + EOS + + expected_offenses = [{ message: "xcodebuild should be passed an explicit \"SYMROOT\"", + severity: :convention, + line: 6, + column: 4, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "When go get is executed" do + source = <<-EOS.undent + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + homepage "http://example.com" + + def install + system "go", "get", "bar" + end + end + EOS + + expected_offenses = [{ message: "Formulae should not use `go get`. If non-vendored resources are required use `go_resource`s.", + severity: :convention, + line: 6, + column: 4, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "When xcodebuild is executed" do + source = <<-EOS.undent + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + homepage "http://example.com" + + def install + system "xcodebuild", "foo", "bar" + end + end + EOS + + expected_offenses = [{ message: "use \"xcodebuild *args\" instead of \"system 'xcodebuild', *args\"", + severity: :convention, + line: 6, + column: 4, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "When scons is executed" do + source = <<-EOS.undent + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + homepage "http://example.com" + + def install + system "scons", "foo", "bar" + end + end + EOS + + expected_offenses = [{ message: "use \"scons *args\" instead of \"system 'scons', *args\"", + severity: :convention, + line: 6, + column: 4, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "When plist_options are not defined when using a formula-defined plist" do + source = <<-EOS.undent + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + homepage "http://example.com" + + def install + system "xcodebuild", "foo", "bar" + end + + def plist; <<-EOS.undent + <?xml version="1.0" encoding="UTF-8"?> + <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> + <plist version="1.0"> + <dict> + <key>Label</key> + <string>org.nrpe.agent</string> + </dict> + </plist> + \EOS + end + end + EOS + + expected_offenses = [{ message: "Please set plist_options when using a formula-defined plist.", + severity: :convention, + line: 9, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "When language/go is require'd" do + source = <<-EOS.undent + require "language/go" + + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + homepage "http://example.com" + + def install + system "go", "get", "bar" + end + end + EOS + + expected_offenses = [{ message: "require \"language/go\" is unnecessary unless using `go_resource`s", + severity: :convention, + line: 1, + column: 0, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "When formula uses virtualenv and also `setuptools` resource" do + source = <<-EOS.undent + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + homepage "http://example.com" + + resource "setuptools" do + url "https://foo.com/foo.tar.gz" + sha256 "db0904a28253cfe53e7dedc765c71596f3c53bb8a866ae50123320ec1a7b73fd" + end + + def install + virtualenv_create(libexec) + end + end + EOS + + expected_offenses = [{ message: "Formulae using virtualenvs do not need a `setuptools` resource.", + severity: :convention, + line: 5, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "When Formula.factory(name) is used" do + source = <<-EOS.undent + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + homepage "http://example.com" + + def install + Formula.factory(name) + end + end + EOS + + expected_offenses = [{ message: "\"Formula.factory(name)\" is deprecated in favor of \"Formula[name]\"", + severity: :convention, + line: 6, + column: 4, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + def expect_offense(expected, actual) + expect(actual.message).to eq(expected[:message]) + expect(actual.severity).to eq(expected[:severity]) + expect(actual.line).to eq(expected[:line]) + expect(actual.column).to eq(expected[:column]) + end + end +end diff --git a/Library/Homebrew/test/sandbox_spec.rb b/Library/Homebrew/test/sandbox_spec.rb index 0d349f6eb..eafec4dd4 100644 --- a/Library/Homebrew/test/sandbox_spec.rb +++ b/Library/Homebrew/test/sandbox_spec.rb @@ -1,8 +1,8 @@ require "sandbox" -RSpec::Matchers.define_negated_matcher :not_matching, :matching - describe Sandbox do + define_negated_matcher :not_matching, :matching + let(:dir) { mktmpdir } let(:file) { dir/"foo" } diff --git a/Library/Homebrew/test/software_spec_spec.rb b/Library/Homebrew/test/software_spec_spec.rb index 5fd4f598a..e6eaeb204 100644 --- a/Library/Homebrew/test/software_spec_spec.rb +++ b/Library/Homebrew/test/software_spec_spec.rb @@ -1,9 +1,9 @@ require "software_spec" -RSpec::Matchers.alias_matcher :have_defined_resource, :be_resource_defined -RSpec::Matchers.alias_matcher :have_defined_option, :be_option_defined - describe SoftwareSpec do + alias_matcher :have_defined_resource, :be_resource_defined + alias_matcher :have_defined_option, :be_option_defined + let(:owner) { double(name: "some_name", full_name: "some_name", tap: "homebrew/core") } describe "#resource" do diff --git a/Library/Homebrew/test/string_spec.rb b/Library/Homebrew/test/string_spec.rb index d1b820b66..ce26d70d4 100644 --- a/Library/Homebrew/test/string_spec.rb +++ b/Library/Homebrew/test/string_spec.rb @@ -3,19 +3,19 @@ require "extend/string" describe String do describe "#undent" do it "removes leading whitespace, taking the first line as reference" do - string = <<-EOS.undent - hi -........my friend over - there + string = <<-EOS.unindent + hi + ........my friend over + there EOS expect(string).to eq("hi\n........my friend over\n there\n") end it "removes nothing if the text is not indented" do - string = <<-EOS.undent -hi -I'm not indented + string = <<-EOS.unindent + hi + I'm not indented EOS expect(string).to eq("hi\nI'm not indented\n") diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/container-gpg.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/container-gpg.rb new file mode 100644 index 000000000..630527ce2 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/container-gpg.rb @@ -0,0 +1,12 @@ +cask 'container-gpg' do + version '1.2.3' + sha256 :no_check + + url "file://#{TEST_FIXTURE_DIR}/cask/container.tar.xz.gpg" + gpg :embedded, key_id: 'B0976E51E5C047AD0FD051294E402EBF7C3C6A71' + + homepage 'https://example.com/container-gpg' + depends_on formula: 'gpg' + + app 'container' +end diff --git a/Library/Homebrew/test/support/fixtures/cask/container.tar.xz.gpg b/Library/Homebrew/test/support/fixtures/cask/container.tar.xz.gpg Binary files differnew file mode 100644 index 000000000..be250e851 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/container.tar.xz.gpg diff --git a/Library/Homebrew/test/support/fixtures/tarballs/testbottest-0.1.tbz b/Library/Homebrew/test/support/fixtures/tarballs/testbottest-0.1.tbz Binary files differdeleted file mode 100644 index 83f7ab1dd..000000000 --- a/Library/Homebrew/test/support/fixtures/tarballs/testbottest-0.1.tbz +++ /dev/null diff --git a/Library/Homebrew/test/support/fixtures/testbottest.rb b/Library/Homebrew/test/support/fixtures/testbottest.rb deleted file mode 100644 index f7695cab5..000000000 --- a/Library/Homebrew/test/support/fixtures/testbottest.rb +++ /dev/null @@ -1,14 +0,0 @@ -class Testbottest < Formula - desc "Minimal C program and Makefile used for testing Homebrew." - homepage "https://github.com/Homebrew/brew" - url "file://#{File.expand_path("..", __FILE__)}/tarballs/testbottest-0.1.tbz" - sha256 "78b54d8f31585c9773bed12b4aa4ab2ce458ebd044b9406cb24d40aa5107f082" - - def install - system "make", "install", "PREFIX=#{prefix}" - end - - test do - assert_equal "testbottest\n", shell_output("#{bin}/testbottest") - end -end diff --git a/Library/Homebrew/test/support/helper/spec/shared_examples/hbc_staged.rb b/Library/Homebrew/test/support/helper/spec/shared_examples/hbc_staged.rb index 31083ee58..1364c13a3 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_examples/hbc_staged.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_examples/hbc_staged.rb @@ -24,7 +24,7 @@ shared_examples Hbc::Staged do end it "can get the Info.plist file for the primary app" do - expect(staged.info_plist_file.to_s).to include Hbc.appdir.join("TestCask.app/Contents/Info.plist") + expect(staged.info_plist_file).to eq Hbc.appdir.join("TestCask.app/Contents/Info.plist") end it "can execute commands on the Info.plist file" do diff --git a/Library/Homebrew/test/tab_spec.rb b/Library/Homebrew/test/tab_spec.rb index 1b0836c93..93ae42ce4 100644 --- a/Library/Homebrew/test/tab_spec.rb +++ b/Library/Homebrew/test/tab_spec.rb @@ -1,9 +1,9 @@ require "tab" require "formula" -RSpec::Matchers.alias_matcher :be_built_with, :be_with - describe Tab do + alias_matcher :be_built_with, :be_with + matcher :be_poured_from_bottle do match do |actual| actual.poured_from_bottle == true diff --git a/Library/Homebrew/test/tap_spec.rb b/Library/Homebrew/test/tap_spec.rb index 50e4522af..27b5e0c4b 100644 --- a/Library/Homebrew/test/tap_spec.rb +++ b/Library/Homebrew/test/tap_spec.rb @@ -1,9 +1,9 @@ -RSpec::Matchers.alias_matcher :have_formula_file, :be_formula_file -RSpec::Matchers.alias_matcher :have_custom_remote, :be_custom_remote - describe Tap do include FileUtils + alias_matcher :have_formula_file, :be_formula_file + alias_matcher :have_custom_remote, :be_custom_remote + subject { described_class.new("Homebrew", "foo") } let(:path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" } let(:formula_file) { path/"Formula/foo.rb" } diff --git a/Library/Homebrew/test/utils_spec.rb b/Library/Homebrew/test/utils_spec.rb index be224990a..f3bf98486 100644 --- a/Library/Homebrew/test/utils_spec.rb +++ b/Library/Homebrew/test/utils_spec.rb @@ -188,14 +188,14 @@ describe "globally-scoped helper methods" do end specify "#which_editor" do - ENV["HOMEBREW_EDITOR"] = "vemate" + ENV["HOMEBREW_EDITOR"] = "vemate -w" ENV["HOMEBREW_PATH"] = dir editor = "#{dir}/vemate" FileUtils.touch editor FileUtils.chmod 0755, editor - expect(which_editor).to eql editor + expect(which_editor).to eq("vemate -w") end specify "#gzip" do |
