diff options
| author | Gautham Goli | 2017-10-12 00:29:19 +0530 |
|---|---|---|
| committer | Gautham Goli | 2017-10-13 19:50:46 +0530 |
| commit | 7fa51f71f1a8a21b905bafc1fb4106f0222d654f (patch) | |
| tree | 098d2477a8262a5770310fed4693da31c4392e1c /Library/Homebrew/test | |
| parent | afdd0e2437426ec85ff86e5b7562d3a6a69ba3e5 (diff) | |
| parent | 56458f03fcc68ef6d8ee3ee4a7c1d16021aa5800 (diff) | |
| download | brew-7fa51f71f1a8a21b905bafc1fb4106f0222d654f.tar.bz2 | |
Merge branch 'master' into audit_line_rubocop_part_4_rebase_attempt_1
Diffstat (limited to 'Library/Homebrew/test')
99 files changed, 1712 insertions, 831 deletions
diff --git a/Library/Homebrew/test/Gemfile b/Library/Homebrew/test/Gemfile index dbe76b51c..b6d1405ff 100644 --- a/Library/Homebrew/test/Gemfile +++ b/Library/Homebrew/test/Gemfile @@ -1,10 +1,12 @@ source "https://rubygems.org" +require_relative "../constants" + gem "parallel_tests" gem "rspec" gem "rspec-its", require: false gem "rspec-wait", require: false -gem "rubocop" +gem "rubocop", HOMEBREW_RUBOCOP_VERSION group :coverage do gem "codecov", require: false diff --git a/Library/Homebrew/test/Gemfile.lock b/Library/Homebrew/test/Gemfile.lock index ccfd91542..ba12d091d 100644 --- a/Library/Homebrew/test/Gemfile.lock +++ b/Library/Homebrew/test/Gemfile.lock @@ -9,15 +9,15 @@ GEM diff-lcs (1.3) docile (1.1.5) json (2.1.0) - parallel (1.11.2) - parallel_tests (2.14.1) + parallel (1.12.0) + parallel_tests (2.17.0) parallel parser (2.4.0.0) ast (~> 2.2) powerpack (0.1.1) rainbow (2.2.2) rake - rake (12.0.0) + rake (12.1.0) rspec (3.6.0) rspec-core (~> 3.6.0) rspec-expectations (~> 3.6.0) @@ -36,20 +36,20 @@ GEM rspec-support (3.6.0) rspec-wait (0.0.9) rspec (>= 3, < 4) - rubocop (0.49.1) + rubocop (0.50.0) parallel (~> 1.10) parser (>= 2.3.3.1, < 3.0) powerpack (~> 0.1) - rainbow (>= 1.99.1, < 3.0) + rainbow (>= 2.2.2, < 3.0) ruby-progressbar (~> 1.7) unicode-display_width (~> 1.0, >= 1.0.1) - ruby-progressbar (1.8.1) - simplecov (0.14.1) + ruby-progressbar (1.9.0) + simplecov (0.15.1) docile (~> 1.1.0) json (>= 1.8, < 3) simplecov-html (~> 0.10.0) - simplecov-html (0.10.0) - unicode-display_width (1.2.1) + simplecov-html (0.10.2) + unicode-display_width (1.3.0) url (0.3.2) PLATFORMS @@ -61,8 +61,8 @@ DEPENDENCIES rspec rspec-its rspec-wait - rubocop + rubocop (= 0.50.0) simplecov BUNDLED WITH - 1.14.6 + 1.15.4 diff --git a/Library/Homebrew/test/bottle_hooks_spec.rb b/Library/Homebrew/test/bottle_hooks_spec.rb index e70b558a1..eb6617380 100644 --- a/Library/Homebrew/test/bottle_hooks_spec.rb +++ b/Library/Homebrew/test/bottle_hooks_spec.rb @@ -8,7 +8,7 @@ describe Homebrew::Hooks::Bottles do let(:formula) do double( - bottle: nil, + bottled?: false, local_bottle_path: nil, bottle_disabled?: false, some_random_method: true, diff --git a/Library/Homebrew/test/cask/accessibility_spec.rb b/Library/Homebrew/test/cask/accessibility_spec.rb index 9e56f6bd3..b77bcb002 100644 --- a/Library/Homebrew/test/cask/accessibility_spec.rb +++ b/Library/Homebrew/test/cask/accessibility_spec.rb @@ -1,7 +1,7 @@ # TODO: this test should be named after the corresponding class, once # that class is abstracted from installer.rb. describe "Accessibility Access", :cask do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-accessibility-access.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-accessibility-access")) } let(:fake_system_command) { class_double(Hbc::SystemCommand) } let(:installer) { Hbc::Installer.new(cask, command: fake_system_command) } diff --git a/Library/Homebrew/test/cask/artifact/alt_target_spec.rb b/Library/Homebrew/test/cask/artifact/alt_target_spec.rb index 9e8d83bb4..847bf25fa 100644 --- a/Library/Homebrew/test/cask/artifact/alt_target_spec.rb +++ b/Library/Homebrew/test/cask/artifact/alt_target_spec.rb @@ -1,9 +1,13 @@ describe Hbc::Artifact::App, :cask do describe "activate to alternate target" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-alt-target.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-alt-target")) } let(:install_phase) { - -> { Hbc::Artifact::App.new(cask).install_phase } + lambda do + cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end + end } let(:source_path) { cask.staged_path.join("Caffeine.app") } diff --git a/Library/Homebrew/test/cask/artifact/app_spec.rb b/Library/Homebrew/test/cask/artifact/app_spec.rb index 0add472e2..4ead8b7f9 100644 --- a/Library/Homebrew/test/cask/artifact/app_spec.rb +++ b/Library/Homebrew/test/cask/artifact/app_spec.rb @@ -1,14 +1,14 @@ describe Hbc::Artifact::App, :cask do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("local-caffeine")) } let(:command) { Hbc::SystemCommand } let(:force) { false } - let(:app) { Hbc::Artifact::App.new(cask, command: command, force: force) } + let(:app) { cask.artifacts.find { |a| a.is_a?(described_class) } } let(:source_path) { cask.staged_path.join("Caffeine.app") } let(:target_path) { Hbc.appdir.join("Caffeine.app") } - let(:install_phase) { app.install_phase } - let(:uninstall_phase) { app.uninstall_phase } + let(:install_phase) { app.install_phase(command: command, force: force) } + let(:uninstall_phase) { app.uninstall_phase(command: command, force: force) } before(:each) do InstallHelper.install_without_artifacts(cask) @@ -105,8 +105,8 @@ describe Hbc::Artifact::App, :cask do describe "target is user-owned but contains read-only files" do before(:each) do - system "/usr/bin/touch", "--", "#{target_path}/foo" - system "/bin/chmod", "--", "0555", target_path + FileUtils.touch "#{target_path}/foo" + FileUtils.chmod 0555, target_path end it "overwrites the existing app" do @@ -138,7 +138,7 @@ describe Hbc::Artifact::App, :cask do end after(:each) do - system "/bin/chmod", "--", "0755", target_path + FileUtils.chmod 0755, target_path end end end @@ -206,8 +206,8 @@ describe Hbc::Artifact::App, :cask do end describe "summary" do - let(:description) { app.summary[:english_description] } - let(:contents) { app.summary[:contents] } + let(:description) { app.class.english_description } + let(:contents) { app.summarize_installed } it "returns the correct english_description" do expect(description).to eq("Apps") @@ -217,14 +217,13 @@ describe Hbc::Artifact::App, :cask do it "returns the path to the app" do install_phase - expect(contents).to eq(["#{target_path} (#{target_path.abv})"]) + expect(contents).to eq("#{target_path} (#{target_path.abv})") end end describe "app is missing" do it "returns a warning and the supposed path to the app" do - expect(contents.size).to eq(1) - expect(contents[0]).to match(/.*Missing App.*: #{target_path}/) + expect(contents).to match(/.*Missing App.*: #{target_path}/) end end end diff --git a/Library/Homebrew/test/cask/artifact/binary_spec.rb b/Library/Homebrew/test/cask/artifact/binary_spec.rb index ce00e3935..6a3f1da34 100644 --- a/Library/Homebrew/test/cask/artifact/binary_spec.rb +++ b/Library/Homebrew/test/cask/artifact/binary_spec.rb @@ -1,9 +1,10 @@ describe Hbc::Artifact::Binary, :cask do let(:cask) { - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-binary.rb").tap do |cask| + Hbc::CaskLoader.load(cask_path("with-binary")).tap do |cask| InstallHelper.install_without_artifacts(cask) end } + let(:artifacts) { cask.artifacts.select { |a| a.is_a?(described_class) } } let(:expected_path) { Hbc.binarydir.join("binary") } before(:each) do @@ -16,7 +17,7 @@ describe Hbc::Artifact::Binary, :cask do context "when --no-binaries is specified" do let(:cask) { - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-binary.rb") + Hbc::CaskLoader.load(cask_path("with-binary")) } it "doesn't link the binary when --no-binaries is specified" do @@ -26,7 +27,9 @@ describe Hbc::Artifact::Binary, :cask do end it "links the binary to the proper directory" do - Hbc::Artifact::Binary.new(cask).install_phase + artifacts.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end expect(expected_path).to be_a_symlink expect(expected_path.readlink).to exist @@ -34,7 +37,7 @@ describe Hbc::Artifact::Binary, :cask do context "when the binary is not executable" do let(:cask) { - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-non-executable-binary.rb").tap do |cask| + Hbc::CaskLoader.load(cask_path("with-non-executable-binary")).tap do |cask| InstallHelper.install_without_artifacts(cask) end } @@ -45,7 +48,9 @@ describe Hbc::Artifact::Binary, :cask do expect(FileUtils).to receive(:chmod) .with("+x", cask.staged_path.join("naked_non_executable")).and_call_original - Hbc::Artifact::Binary.new(cask).install_phase + artifacts.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end expect(expected_path).to be_a_symlink expect(expected_path.readlink).to be_executable @@ -56,7 +61,9 @@ describe Hbc::Artifact::Binary, :cask do FileUtils.touch expected_path expect { - Hbc::Artifact::Binary.new(cask).install_phase + artifacts.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end }.to raise_error(Hbc::CaskError) expect(expected_path).not_to be :symlink? @@ -65,7 +72,9 @@ describe Hbc::Artifact::Binary, :cask do it "clobbers an existing symlink" do expected_path.make_symlink("/tmp") - Hbc::Artifact::Binary.new(cask).install_phase + artifacts.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end expect(File.readlink(expected_path)).not_to eq("/tmp") end @@ -73,21 +82,27 @@ describe Hbc::Artifact::Binary, :cask do it "creates parent directory if it doesn't exist" do FileUtils.rmdir Hbc.binarydir - Hbc::Artifact::Binary.new(cask).install_phase + artifacts.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end expect(expected_path.exist?).to be true end context "binary is inside an app package" do let(:cask) { - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-embedded-binary.rb").tap do |cask| + Hbc::CaskLoader.load(cask_path("with-embedded-binary")).tap do |cask| InstallHelper.install_without_artifacts(cask) end } it "links the binary to the proper directory" do - Hbc::Artifact::App.new(cask).install_phase - Hbc::Artifact::Binary.new(cask).install_phase + cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::App) }.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end + artifacts.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end expect(expected_path).to be_a_symlink expect(expected_path.readlink).to exist diff --git a/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb b/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb index cb2ef9850..ea567abee 100644 --- a/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb +++ b/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb @@ -1,8 +1,12 @@ describe Hbc::Artifact::Artifact, :cask do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-generic-artifact.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-generic-artifact")) } let(:install_phase) { - -> { Hbc::Artifact::Artifact.new(cask).install_phase } + lambda do + cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end + end } let(:source_path) { cask.staged_path.join("Caffeine.app") } @@ -12,11 +16,11 @@ describe Hbc::Artifact::Artifact, :cask do InstallHelper.install_without_artifacts(cask) end - describe "with no target" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-generic-artifact-no-target.rb") } - - it "fails to install with no target" do - expect(install_phase).to raise_error(Hbc::CaskInvalidError) + context "without target" do + it "fails to load" do + expect { + Hbc::CaskLoader.load(cask_path("with-generic-artifact-no-target")) + }.to raise_error(Hbc::CaskInvalidError, /target required for Generic Artifact/) end end diff --git a/Library/Homebrew/test/cask/artifact/nested_container_spec.rb b/Library/Homebrew/test/cask/artifact/nested_container_spec.rb index be7ba5ff8..f9cd056f8 100644 --- a/Library/Homebrew/test/cask/artifact/nested_container_spec.rb +++ b/Library/Homebrew/test/cask/artifact/nested_container_spec.rb @@ -1,11 +1,13 @@ describe Hbc::Artifact::NestedContainer, :cask do describe "install" do it "extracts the specified paths as containers" do - cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/nested-app.rb").tap do |c| + cask = Hbc::CaskLoader.load(cask_path("nested-app")).tap do |c| InstallHelper.install_without_artifacts(c) end - Hbc::Artifact::NestedContainer.new(cask).install_phase + cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end expect(cask.staged_path.join("MyNestedApp.app")).to be_a_directory end diff --git a/Library/Homebrew/test/cask/artifact/pkg_spec.rb b/Library/Homebrew/test/cask/artifact/pkg_spec.rb index 3e62616ea..7f1b64d1a 100644 --- a/Library/Homebrew/test/cask/artifact/pkg_spec.rb +++ b/Library/Homebrew/test/cask/artifact/pkg_spec.rb @@ -1,5 +1,5 @@ describe Hbc::Artifact::Pkg, :cask do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-installable.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-installable")) } let(:fake_system_command) { class_double(Hbc::SystemCommand) } before(:each) do @@ -8,7 +8,7 @@ describe Hbc::Artifact::Pkg, :cask do describe "install_phase" do it "runs the system installer on the specified pkgs" do - pkg = Hbc::Artifact::Pkg.new(cask, command: fake_system_command) + pkg = cask.artifacts.find { |a| a.is_a?(described_class) } expect(fake_system_command).to receive(:run!).with( "/usr/sbin/installer", @@ -17,15 +17,15 @@ describe Hbc::Artifact::Pkg, :cask do print_stdout: true, ) - pkg.install_phase + pkg.install_phase(command: fake_system_command) end end describe "choices" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-choices.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-choices")) } it "passes the choice changes xml to the system installer" do - pkg = Hbc::Artifact::Pkg.new(cask, command: fake_system_command) + pkg = cask.artifacts.find { |a| a.is_a?(described_class) } file = double(path: Pathname.new("/tmp/choices.xml")) @@ -57,7 +57,7 @@ describe Hbc::Artifact::Pkg, :cask do print_stdout: true, ) - pkg.install_phase + pkg.install_phase(command: fake_system_command) end end end diff --git a/Library/Homebrew/test/cask/artifact/postflight_block_spec.rb b/Library/Homebrew/test/cask/artifact/postflight_block_spec.rb index 51b1431f0..18cc4ca91 100644 --- a/Library/Homebrew/test/cask/artifact/postflight_block_spec.rb +++ b/Library/Homebrew/test/cask/artifact/postflight_block_spec.rb @@ -11,7 +11,9 @@ describe Hbc::Artifact::PostflightBlock, :cask do end end - described_class.new(cask).install_phase + cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end expect(called).to be true expect(yielded_arg).to be_kind_of(Hbc::DSL::Postflight) @@ -30,7 +32,9 @@ describe Hbc::Artifact::PostflightBlock, :cask do end end - described_class.new(cask).uninstall_phase + cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact| + artifact.uninstall_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end expect(called).to be true expect(yielded_arg).to be_kind_of(Hbc::DSL::UninstallPostflight) diff --git a/Library/Homebrew/test/cask/artifact/preflight_block_spec.rb b/Library/Homebrew/test/cask/artifact/preflight_block_spec.rb index b13c4ab9d..405cdbd6f 100644 --- a/Library/Homebrew/test/cask/artifact/preflight_block_spec.rb +++ b/Library/Homebrew/test/cask/artifact/preflight_block_spec.rb @@ -11,7 +11,9 @@ describe Hbc::Artifact::PreflightBlock, :cask do end end - described_class.new(cask).install_phase + cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end expect(called).to be true expect(yielded_arg).to be_kind_of Hbc::DSL::Preflight @@ -30,7 +32,9 @@ describe Hbc::Artifact::PreflightBlock, :cask do end end - described_class.new(cask).uninstall_phase + cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact| + artifact.uninstall_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end expect(called).to be true expect(yielded_arg).to be_kind_of Hbc::DSL::UninstallPreflight diff --git a/Library/Homebrew/test/cask/artifact/suite_spec.rb b/Library/Homebrew/test/cask/artifact/suite_spec.rb index 8c217a9e0..80d3e917f 100644 --- a/Library/Homebrew/test/cask/artifact/suite_spec.rb +++ b/Library/Homebrew/test/cask/artifact/suite_spec.rb @@ -1,7 +1,13 @@ describe Hbc::Artifact::Suite, :cask do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-suite.rb") } - - let(:install_phase) { -> { Hbc::Artifact::Suite.new(cask).install_phase } } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-suite")) } + + let(:install_phase) { + lambda do + cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end + end + } let(:target_path) { Hbc.appdir.join("Caffeine") } let(:source_path) { cask.staged_path.join("Caffeine") } diff --git a/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb b/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb index a1fdd3b74..7f2ef75b3 100644 --- a/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb +++ b/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb @@ -1,9 +1,13 @@ describe Hbc::Artifact::App, :cask do describe "multiple apps" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-two-apps-correct.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-two-apps-correct")) } let(:install_phase) { - -> { Hbc::Artifact::App.new(cask).install_phase } + lambda do + cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end + end } let(:source_path_mini) { cask.staged_path.join("Caffeine Mini.app") } @@ -27,7 +31,7 @@ describe Hbc::Artifact::App, :cask do end describe "when apps are in a subdirectory" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-two-apps-subdir.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-two-apps-subdir")) } it "installs both apps using the proper target directory" do install_phase.call diff --git a/Library/Homebrew/test/cask/artifact/two_apps_incorrect_spec.rb b/Library/Homebrew/test/cask/artifact/two_apps_incorrect_spec.rb index 6427ec32c..cda5b4488 100644 --- a/Library/Homebrew/test/cask/artifact/two_apps_incorrect_spec.rb +++ b/Library/Homebrew/test/cask/artifact/two_apps_incorrect_spec.rb @@ -2,7 +2,7 @@ describe Hbc::Artifact::App, :cask do # FIXME: Doesn't actually raise because the `app` stanza is not evaluated on load. # it "must raise" do # lambda { - # Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-two-apps-incorrect.rb") + # Hbc::CaskLoader.load(cask_path("with-two-apps-incorrect")) # }.must_raise # # TODO: later give the user a nice exception for this case and check for it here # end diff --git a/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb b/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb index 8cd0b1e41..c6ff7d30e 100644 --- a/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb +++ b/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb @@ -1,8 +1,8 @@ describe Hbc::Artifact::Zap, :cask do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-installable.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-installable")) } let(:zap_artifact) { - Hbc::Artifact::Zap.new(cask) + cask.artifacts.find { |a| a.is_a?(described_class) } } before(:each) do diff --git a/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb b/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb index 0e522bc21..b9872ab9e 100644 --- a/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb +++ b/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb @@ -1,12 +1,12 @@ shared_examples "#uninstall_phase or #zap_phase" do - let(:artifact_name) { described_class.artifact_name } - let(:artifact) { described_class.new(cask, command: fake_system_command) } + let(:artifact_dsl_key) { described_class.dsl_key } + let(:artifact) { cask.artifacts.find { |a| a.is_a?(described_class) } } let(:fake_system_command) { Hbc::FakeSystemCommand } - subject { artifact.public_send(:"#{artifact_name}_phase") } + subject { artifact.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command) } context "using :launchctl" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_name}-launchctl.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-launchctl")) } let(:launchctl_list_cmd) { %w[/bin/launchctl list my.fancy.package.service] } let(:launchctl_remove_cmd) { %w[/bin/launchctl remove my.fancy.package.service] } let(:unknown_response) { "launchctl list returned unknown response\n" } @@ -61,7 +61,7 @@ shared_examples "#uninstall_phase or #zap_phase" do context "using :pkgutil" do let(:fake_system_command) { class_double(Hbc::SystemCommand) } - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_name}-pkgutil.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-pkgutil")) } let(:main_pkg_id) { "my.fancy.package.main" } let(:agent_pkg_id) { "my.fancy.package.agent" } @@ -85,7 +85,7 @@ shared_examples "#uninstall_phase or #zap_phase" do end context "using :kext" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_name}-kext.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-kext")) } let(:kext_id) { "my.fancy.package.kernelextension" } it "is supported" do @@ -110,7 +110,7 @@ shared_examples "#uninstall_phase or #zap_phase" do end context "using :quit" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_name}-quit.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-quit")) } let(:bundle_id) { "my.fancy.package.app" } let(:quit_application_script) do %Q(tell application id "#{bundle_id}" to quit) @@ -130,7 +130,7 @@ shared_examples "#uninstall_phase or #zap_phase" do end context "using :signal" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_name}-signal.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-signal")) } let(:bundle_id) { "my.fancy.package.app" } let(:signals) { %w[TERM KILL] } let(:unix_pids) { [12_345, 67_890] } @@ -149,6 +149,8 @@ shared_examples "#uninstall_phase or #zap_phase" do end [:delete, :trash].each do |directive| + next if directive == :trash && ENV["HOMEBREW_TESTS_COVERAGE"].nil? + context "using :#{directive}" do let(:dir) { TEST_TMPDIR } let(:absolute_path) { Pathname.new("#{dir}/absolute_path") } @@ -170,10 +172,10 @@ shared_examples "#uninstall_phase or #zap_phase" do end let(:fake_system_command) { Hbc::NeverSudoSystemCommand } - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_name}-#{directive}.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-#{directive}")) } before(:each) do - allow_any_instance_of(Hbc::Artifact::UninstallBase).to receive(:trash_paths) + allow_any_instance_of(Hbc::Artifact::AbstractUninstall).to receive(:trash_paths) .and_wrap_original do |method, *args| result = method.call(*args) FileUtils.rm_rf result.stdout.split("\0") @@ -196,7 +198,7 @@ shared_examples "#uninstall_phase or #zap_phase" do context "using :rmdir" do let(:fake_system_command) { Hbc::NeverSudoSystemCommand } - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_name}-rmdir.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-rmdir")) } let(:empty_directory) { Pathname.new("#{TEST_TMPDIR}/empty_directory_path") } let(:ds_store) { empty_directory.join(".DS_Store") } @@ -223,8 +225,8 @@ shared_examples "#uninstall_phase or #zap_phase" do [:script, :early_script].each do |script_type| context "using #{script_type.inspect}" do let(:fake_system_command) { Hbc::NeverSudoSystemCommand } - let(:token) { "with-#{artifact_name}-#{script_type}".tr("_", "-") } - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/#{token}.rb") } + let(:token) { "with-#{artifact_dsl_key}-#{script_type}".tr("_", "-") } + let(:cask) { Hbc::CaskLoader.load(cask_path(token.to_s)) } let(:script_pathname) { cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool") } it "is supported" do @@ -250,7 +252,7 @@ shared_examples "#uninstall_phase or #zap_phase" do end context "using :login_item" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_name}-login-item.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-login-item")) } it "is supported" do Hbc::FakeSystemCommand.expects_command( diff --git a/Library/Homebrew/test/cask/audit_spec.rb b/Library/Homebrew/test/cask/audit_spec.rb index ddc773e3e..7e140acb2 100644 --- a/Library/Homebrew/test/cask/audit_spec.rb +++ b/Library/Homebrew/test/cask/audit_spec.rb @@ -265,19 +265,14 @@ describe Hbc::Audit, :cask do end describe "generic artifact checks" do - context "with no target" do - let(:cask_token) { "generic-artifact-no-target" } - it { is_expected.to fail_with(/target required for generic artifact/) } - end - context "with relative target" do let(:cask_token) { "generic-artifact-relative-target" } - it { is_expected.to fail_with(/target must be absolute path for generic artifact/) } + it { is_expected.to fail_with(/target must be absolute path for Generic Artifact/) } end context "with absolute target" do let(:cask_token) { "generic-artifact-absolute-target" } - it { should_not fail_with(/target required for generic artifact/) } + it { should_not fail_with(/target required for Generic Artifact/) } end end diff --git a/Library/Homebrew/test/cask/cask_loader/from_content_loader_spec.rb b/Library/Homebrew/test/cask/cask_loader/from_content_loader_spec.rb new file mode 100644 index 000000000..e735d5eca --- /dev/null +++ b/Library/Homebrew/test/cask/cask_loader/from_content_loader_spec.rb @@ -0,0 +1,57 @@ +describe Hbc::CaskLoader::FromContentLoader do + alias_matcher :be_able_to_load, :be_can_load + + describe "::can_load?" do + it "returns true for Casks specified with `cask \"token\" do … end`" do + expect(described_class).to be_able_to_load <<~EOS + cask "token" do + end + EOS + end + + it "returns true for Casks specified with `cask \"token\" do; end`" do + expect(described_class).to be_able_to_load <<~EOS + cask "token" do; end + EOS + end + + it "returns true for Casks specified with `cask 'token' do … end`" do + expect(described_class).to be_able_to_load <<~EOS + cask 'token' do + end + EOS + end + + it "returns true for Casks specified with `cask 'token' do; end`" do + expect(described_class).to be_able_to_load <<~EOS + cask 'token' do; end + EOS + end + + it "returns true for Casks specified with `cask(\"token\") { … }`" do + expect(described_class).to be_able_to_load <<~EOS + cask("token") { + } + EOS + end + + it "returns true for Casks specified with `cask(\"token\") {}`" do + expect(described_class).to be_able_to_load <<~EOS + cask("token") {} + EOS + end + + it "returns true for Casks specified with `cask('token') { … }`" do + expect(described_class).to be_able_to_load <<~EOS + cask('token') { + } + EOS + end + + it "returns true for Casks specified with `cask('token') {}`" do + expect(described_class).to be_able_to_load <<~EOS + cask('token') {} + EOS + end + end +end diff --git a/Library/Homebrew/test/cask/cask_loader/from_uri_loader_spec.rb b/Library/Homebrew/test/cask/cask_loader/from_uri_loader_spec.rb new file mode 100644 index 000000000..df2de1f82 --- /dev/null +++ b/Library/Homebrew/test/cask/cask_loader/from_uri_loader_spec.rb @@ -0,0 +1,21 @@ +describe Hbc::CaskLoader::FromURILoader do + alias_matcher :be_able_to_load, :be_can_load + + describe "::can_load?" do + it "returns true when given an URI" do + expect(described_class).to be_able_to_load(URI("http://example.com/")) + end + + it "returns true when given a String which can be parsed to a URI" do + expect(described_class).to be_able_to_load("http://example.com/") + end + + it "returns false when given a String with Cask contents containing a URL" do + expect(described_class).not_to be_able_to_load <<~EOS + cask 'token' do + url 'http://example.com/' + end + EOS + end + end +end diff --git a/Library/Homebrew/test/cask/cask_spec.rb b/Library/Homebrew/test/cask/cask_spec.rb index a6ecc207f..5858a7c6d 100644 --- a/Library/Homebrew/test/cask/cask_spec.rb +++ b/Library/Homebrew/test/cask/cask_spec.rb @@ -171,4 +171,38 @@ describe Hbc::Cask, :cask do end end end + + describe "full_name" do + context "when it is a core cask" do + it "is the cask token" do + c = Hbc::CaskLoader.load("local-caffeine") + expect(c.full_name).to eq("local-caffeine") + end + end + + context "when it is from a non-core tap" do + it "returns the fully-qualified name of the cask" do + c = Hbc::CaskLoader.load("third-party/tap/third-party-cask") + expect(c.full_name).to eq("third-party/tap/third-party-cask") + end + end + + context "when it is from no known tap" do + it "retuns the cask token" do + file = Tempfile.new(%w[tapless-cask .rb]) + + begin + cask_name = File.basename(file.path, ".rb") + file.write "cask '#{cask_name}'" + file.close + + c = Hbc::CaskLoader.load(file.path) + expect(c.full_name).to eq(cask_name) + ensure + file.close + file.unlink + end + end + end + end end diff --git a/Library/Homebrew/test/cask/cli/audit_spec.rb b/Library/Homebrew/test/cask/cli/audit_spec.rb index 01f506c8c..da8bf1273 100644 --- a/Library/Homebrew/test/cask/cli/audit_spec.rb +++ b/Library/Homebrew/test/cask/cli/audit_spec.rb @@ -1,13 +1,19 @@ +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Audit, :cask do - let(:cask) { double("cask", token: nil) } + let(:cask) { Hbc::Cask.new(nil) } + + it_behaves_like "a command that handles invalid options" describe "selection of Casks to audit" do it "audits all Casks if no tokens are given" do + expect(cask).to be_a Hbc::Cask + allow(Hbc).to receive(:all).and_return([cask, cask]) expect(Hbc::Auditor).to receive(:audit).twice.and_return(true) - Hbc::CLI::Audit.run + described_class.run end it "audits specified Casks if tokens are given" do @@ -18,7 +24,7 @@ describe Hbc::CLI::Audit, :cask do .with(cask, audit_download: false, check_token_conflicts: false) .and_return(true) - Hbc::CLI::Audit.run(cask_token) + described_class.run(cask_token) end end @@ -29,7 +35,7 @@ describe Hbc::CLI::Audit, :cask do .with(cask, audit_download: false, check_token_conflicts: false) .and_return(true) - Hbc::CLI::Audit.run("casktoken") + described_class.run("casktoken") end it "download a Cask if --download flag is set" do @@ -38,7 +44,7 @@ describe Hbc::CLI::Audit, :cask do .with(cask, audit_download: true, check_token_conflicts: false) .and_return(true) - Hbc::CLI::Audit.run("casktoken", "--download") + described_class.run("casktoken", "--download") end end @@ -49,7 +55,7 @@ describe Hbc::CLI::Audit, :cask do .with(cask, audit_download: false, check_token_conflicts: false) .and_return(true) - Hbc::CLI::Audit.run("casktoken") + described_class.run("casktoken") end it "checks for token conflicts if --token-conflicts flag is set" do @@ -58,7 +64,7 @@ describe Hbc::CLI::Audit, :cask do .with(cask, audit_download: false, check_token_conflicts: true) .and_return(true) - Hbc::CLI::Audit.run("casktoken", "--token-conflicts") + described_class.run("casktoken", "--token-conflicts") end end end diff --git a/Library/Homebrew/test/cask/cli/cat_spec.rb b/Library/Homebrew/test/cask/cli/cat_spec.rb index b726a0b36..6b54a2e4b 100644 --- a/Library/Homebrew/test/cask/cli/cat_spec.rb +++ b/Library/Homebrew/test/cask/cli/cat_spec.rb @@ -1,4 +1,10 @@ +require_relative "shared_examples/requires_cask_token" +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Cat, :cask do + it_behaves_like "a command that requires a Cask token" + it_behaves_like "a command that handles invalid options" + describe "given a basic Cask" do let(:basic_cask_content) { <<-EOS.undent @@ -16,42 +22,19 @@ describe Hbc::CLI::Cat, :cask do it "displays the Cask file content about the specified Cask" do expect { - Hbc::CLI::Cat.run("basic-cask") + described_class.run("basic-cask") }.to output(basic_cask_content).to_stdout end it "can display multiple Casks" do expect { - Hbc::CLI::Cat.run("basic-cask", "basic-cask") + described_class.run("basic-cask", "basic-cask") }.to output(basic_cask_content * 2).to_stdout end - - it "fails when option is unknown" do - expect { - Hbc::CLI::Cat.run("--notavalidoption", "basic-cask") - }.to raise_error(/invalid option/) - end end it "raises an exception when the Cask does not exist" do - expect { Hbc::CLI::Cat.run("notacask") } - .to output(/is unavailable/).to_stderr - .and raise_error(Hbc::CaskError, "Cat incomplete.") - end - - describe "when no Cask is specified" do - it "raises an exception" do - expect { - Hbc::CLI::Cat.run - }.to raise_error(Hbc::CaskUnspecifiedError) - end - end - - describe "when no Cask is specified, but an invalid option" do - it "raises an exception" do - expect { - Hbc::CLI::Cat.run("--notavalidoption") - }.to raise_error(/invalid option/) - end + expect { described_class.run("notacask") } + .to raise_error(Hbc::CaskUnavailableError, /is unavailable/) end end diff --git a/Library/Homebrew/test/cask/cli/cleanup_spec.rb b/Library/Homebrew/test/cask/cli/cleanup_spec.rb index 64e3ef49f..7cf00352d 100644 --- a/Library/Homebrew/test/cask/cli/cleanup_spec.rb +++ b/Library/Homebrew/test/cask/cli/cleanup_spec.rb @@ -1,3 +1,5 @@ +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Cleanup, :cask do let(:cache_location) { Pathname.new(Dir.mktmpdir).realpath } let(:outdated_only) { false } @@ -12,6 +14,8 @@ describe Hbc::CLI::Cleanup, :cask do cache_location.rmtree end + it_behaves_like "a command that handles invalid options" + describe "cleanup" do let(:cask_token) { "caffeine" } let(:cask_tokens) { [cask_token] } diff --git a/Library/Homebrew/test/cask/cli/create_spec.rb b/Library/Homebrew/test/cask/cli/create_spec.rb index d77b0a2aa..60c03db75 100644 --- a/Library/Homebrew/test/cask/cli/create_spec.rb +++ b/Library/Homebrew/test/cask/cli/create_spec.rb @@ -1,3 +1,6 @@ +require_relative "shared_examples/requires_cask_token" +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Create, :cask do around(:each) do |example| begin @@ -13,6 +16,9 @@ describe Hbc::CLI::Create, :cask do allow_any_instance_of(described_class).to receive(:exec_editor) end + it_behaves_like "a command that requires a Cask token" + it_behaves_like "a command that handles invalid options" + it "opens the editor for the specified Cask" do command = described_class.new("new-cask") expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("new-cask")) @@ -39,7 +45,7 @@ describe Hbc::CLI::Create, :cask do it "raises an exception when more than one Cask is given" do expect { described_class.run("additional-cask", "another-cask") - }.to raise_error(/Only one Cask can be created at a time./) + }.to raise_error(/Only one Cask can be created at a time\./) end it "raises an exception when the Cask already exists" do @@ -53,26 +59,4 @@ describe Hbc::CLI::Create, :cask do expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("local-caff")) command.run end - - describe "when no Cask is specified" do - it "raises an exception" do - expect { - described_class.run - }.to raise_error(Hbc::CaskUnspecifiedError) - end - end - - context "when an invalid option is specified" do - it "raises an exception when no Cask is specified" do - expect { - described_class.run("--notavalidoption") - }.to raise_error(/invalid option/) - end - - it "raises an exception" do - expect { - described_class.run("--notavalidoption", "yet-another-cask") - }.to raise_error(/invalid option/) - end - end end diff --git a/Library/Homebrew/test/cask/cli/doctor_spec.rb b/Library/Homebrew/test/cask/cli/doctor_spec.rb index b24c777eb..e3967060e 100644 --- a/Library/Homebrew/test/cask/cli/doctor_spec.rb +++ b/Library/Homebrew/test/cask/cli/doctor_spec.rb @@ -1,4 +1,8 @@ +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Doctor, :cask do + it_behaves_like "a command that handles invalid options" + it "displays some nice info about the environment" do expect { Hbc::CLI::Doctor.run diff --git a/Library/Homebrew/test/cask/cli/edit_spec.rb b/Library/Homebrew/test/cask/cli/edit_spec.rb index 5d5cbf4b9..347522020 100644 --- a/Library/Homebrew/test/cask/cli/edit_spec.rb +++ b/Library/Homebrew/test/cask/cli/edit_spec.rb @@ -1,8 +1,14 @@ +require_relative "shared_examples/requires_cask_token" +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Edit, :cask do before(:each) do allow_any_instance_of(described_class).to receive(:exec_editor) end + it_behaves_like "a command that requires a Cask token" + it_behaves_like "a command that handles invalid options" + it "opens the editor for the specified Cask" do command = described_class.new("local-caffeine") expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("local-caffeine")) @@ -12,7 +18,7 @@ describe Hbc::CLI::Edit, :cask do it "raises an error when given more than one argument" do expect { described_class.new("local-caffeine", "local-transmission") - }.to raise_error(/Only one Cask can be created at a time./) + }.to raise_error(/Only one Cask can be edited at a time\./) end it "raises an exception when the Cask doesnt exist" do @@ -20,20 +26,4 @@ describe Hbc::CLI::Edit, :cask do described_class.run("notacask") }.to raise_error(Hbc::CaskUnavailableError) end - - describe "when no Cask is specified" do - it "raises an exception" do - expect { - described_class.run - }.to raise_error(Hbc::CaskUnspecifiedError) - end - end - - describe "when no Cask is specified, but an invalid option" do - it "raises an exception" do - expect { - described_class.run("--notavalidoption") - }.to raise_error(/invalid option/) - end - end end diff --git a/Library/Homebrew/test/cask/cli/fetch_spec.rb b/Library/Homebrew/test/cask/cli/fetch_spec.rb index f71c23fb6..67cf6e61d 100644 --- a/Library/Homebrew/test/cask/cli/fetch_spec.rb +++ b/Library/Homebrew/test/cask/cli/fetch_spec.rb @@ -1,14 +1,20 @@ +require_relative "shared_examples/requires_cask_token" +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Fetch, :cask do let(:local_transmission) { - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") + Hbc::CaskLoader.load(cask_path("local-transmission")) } let(:local_caffeine) { - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") + Hbc::CaskLoader.load(cask_path("local-caffeine")) } + it_behaves_like "a command that requires a Cask token" + it_behaves_like "a command that handles invalid options" + it "allows download the installer of a Cask" do - Hbc::CLI::Fetch.run("local-transmission", "local-caffeine") + described_class.run("local-transmission", "local-caffeine") expect(Hbc::CurlDownloadStrategy.new(local_transmission).cached_location).to exist expect(Hbc::CurlDownloadStrategy.new(local_caffeine).cached_location).to exist end @@ -19,7 +25,7 @@ describe Hbc::CLI::Fetch, :cask do Hbc::Download.new(local_transmission).perform old_ctime = File.stat(download_stategy.cached_location).ctime - Hbc::CLI::Fetch.run("local-transmission") + described_class.run("local-transmission") new_ctime = File.stat(download_stategy.cached_location).ctime expect(old_ctime.to_i).to eq(new_ctime.to_i) @@ -32,7 +38,7 @@ describe Hbc::CLI::Fetch, :cask do old_ctime = File.stat(download_stategy.cached_location).ctime sleep(1) - Hbc::CLI::Fetch.run("local-transmission", "--force") + described_class.run("local-transmission", "--force") download_stategy = Hbc::CurlDownloadStrategy.new(local_transmission) new_ctime = File.stat(download_stategy.cached_location).ctime @@ -41,23 +47,7 @@ describe Hbc::CLI::Fetch, :cask do it "properly handles Casks that are not present" do expect { - Hbc::CLI::Fetch.run("notacask") - }.to raise_error(Hbc::CaskError, "Fetch incomplete.") - end - - describe "when no Cask is specified" do - it "raises an exception" do - expect { - Hbc::CLI::Fetch.run - }.to raise_error(Hbc::CaskUnspecifiedError) - end - end - - describe "when no Cask is specified, but an invalid option" do - it "raises an exception" do - expect { - Hbc::CLI::Fetch.run("--notavalidoption") - }.to raise_error(/invalid option/) - end + described_class.run("notacask") + }.to raise_error(Hbc::CaskUnavailableError) end end diff --git a/Library/Homebrew/test/cask/cli/home_spec.rb b/Library/Homebrew/test/cask/cli/home_spec.rb index e985fb6cd..8960d2acc 100644 --- a/Library/Homebrew/test/cask/cli/home_spec.rb +++ b/Library/Homebrew/test/cask/cli/home_spec.rb @@ -1,8 +1,12 @@ +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Home, :cask do before do allow(described_class).to receive(:open_url) end + it_behaves_like "a command that handles invalid options" + it "opens the homepage for the specified Cask" do expect(described_class).to receive(:open_url).with("http://example.com/local-caffeine") described_class.run("local-caffeine") diff --git a/Library/Homebrew/test/cask/cli/info_spec.rb b/Library/Homebrew/test/cask/cli/info_spec.rb index bffe900ec..e24eead11 100644 --- a/Library/Homebrew/test/cask/cli/info_spec.rb +++ b/Library/Homebrew/test/cask/cli/info_spec.rb @@ -1,7 +1,13 @@ +require_relative "shared_examples/requires_cask_token" +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Info, :cask do + it_behaves_like "a command that requires a Cask token" + it_behaves_like "a command that handles invalid options" + it "displays some nice info about the specified Cask" do expect { - Hbc::CLI::Info.run("local-caffeine") + described_class.run("local-caffeine") }.to output(<<-EOS.undent).to_stdout local-caffeine: 1.2.3 http://example.com/local-caffeine @@ -10,7 +16,7 @@ describe Hbc::CLI::Info, :cask do ==> Name None ==> Artifacts - Caffeine.app (app) + Caffeine.app (App) EOS end @@ -24,7 +30,7 @@ describe Hbc::CLI::Info, :cask do ==> Name None ==> Artifacts - Caffeine.app (app) + Caffeine.app (App) local-transmission: 2.61 http://example.com/local-transmission Not installed @@ -32,26 +38,20 @@ describe Hbc::CLI::Info, :cask do ==> Name None ==> Artifacts - Transmission.app (app) + Transmission.app (App) EOS } it "displays the info" do expect { - Hbc::CLI::Info.run("local-caffeine", "local-transmission") + described_class.run("local-caffeine", "local-transmission") }.to output(expected_output).to_stdout end - - it "throws away stray options" do - expect { - Hbc::CLI::Info.run("--notavalidoption", "local-caffeine", "local-transmission") - }.to raise_error(/invalid option/) - end end it "should print caveats if the Cask provided one" do expect { - Hbc::CLI::Info.run("with-caveats") + described_class.run("with-caveats") }.to output(<<-EOS.undent).to_stdout with-caveats: 1.2.3 http://example.com/local-caffeine @@ -60,7 +60,7 @@ describe Hbc::CLI::Info, :cask do ==> Name None ==> Artifacts - Caffeine.app (app) + Caffeine.app (App) ==> Caveats Here are some things you might want to know. @@ -77,7 +77,7 @@ describe Hbc::CLI::Info, :cask do it 'should not print "Caveats" section divider if the caveats block has no output' do expect { - Hbc::CLI::Info.run("with-conditional-caveats") + described_class.run("with-conditional-caveats") }.to output(<<-EOS.undent).to_stdout with-conditional-caveats: 1.2.3 http://example.com/local-caffeine @@ -86,23 +86,39 @@ describe Hbc::CLI::Info, :cask do ==> Name None ==> Artifacts - Caffeine.app (app) + Caffeine.app (App) EOS end - describe "when no Cask is specified" do - it "raises an exception" do - expect { - Hbc::CLI::Info.run - }.to raise_error(Hbc::CaskUnspecifiedError) - end + it "prints languages specified in the Cask" do + expect { + described_class.run("with-languages") + }.to output(<<-EOS.undent).to_stdout + with-languages: 1.2.3 + http://example.com/local-caffeine + Not installed + From: https://github.com/caskroom/homebrew-spec/blob/master/Casks/with-languages.rb + ==> Name + None + ==> Languages + zh, en-US + ==> Artifacts + Caffeine.app (App) + EOS end - describe "when no Cask is specified, but an invalid option" do - it "raises an exception" do - expect { - Hbc::CLI::Info.run("--notavalidoption") - }.to raise_error(/invalid option/) - end + it 'does not print "Languages" section divider if the languages block has no output' do + expect { + described_class.run("without-languages") + }.to output(<<-EOS.undent).to_stdout + without-languages: 1.2.3 + http://example.com/local-caffeine + Not installed + From: https://github.com/caskroom/homebrew-spec/blob/master/Casks/without-languages.rb + ==> Name + None + ==> Artifacts + Caffeine.app (App) + EOS end end diff --git a/Library/Homebrew/test/cask/cli/install_spec.rb b/Library/Homebrew/test/cask/cli/install_spec.rb index 64feacce9..c918a3529 100644 --- a/Library/Homebrew/test/cask/cli/install_spec.rb +++ b/Library/Homebrew/test/cask/cli/install_spec.rb @@ -1,4 +1,10 @@ +require_relative "shared_examples/requires_cask_token" +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Install, :cask do + it_behaves_like "a command that requires a Cask token" + it_behaves_like "a command that handles invalid options" + it "displays the installation progress" do output = Regexp.new <<-EOS.undent ==> Downloading file:.*caffeine.zip @@ -9,103 +15,65 @@ describe Hbc::CLI::Install, :cask do EOS expect { - Hbc::CLI::Install.run("local-caffeine") + described_class.run("local-caffeine") }.to output(output).to_stdout end it "allows staging and activation of multiple Casks at once" do - Hbc::CLI::Install.run("local-transmission", "local-caffeine") + described_class.run("local-transmission", "local-caffeine") - expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed + expect(Hbc::CaskLoader.load(cask_path("local-transmission"))).to be_installed expect(Hbc.appdir.join("Transmission.app")).to be_a_directory - expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")).to be_installed + expect(Hbc::CaskLoader.load(cask_path("local-caffeine"))).to be_installed expect(Hbc.appdir.join("Caffeine.app")).to be_a_directory end it "skips double install (without nuking existing installation)" do - Hbc::CLI::Install.run("local-transmission") - Hbc::CLI::Install.run("local-transmission") - expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed + described_class.run("local-transmission") + described_class.run("local-transmission") + expect(Hbc::CaskLoader.load(cask_path("local-transmission"))).to be_installed end it "prints a warning message on double install" do - Hbc::CLI::Install.run("local-transmission") + described_class.run("local-transmission") expect { - Hbc::CLI::Install.run("local-transmission") + described_class.run("local-transmission") }.to output(/Warning: Cask 'local-transmission' is already installed./).to_stderr end it "allows double install with --force" do - Hbc::CLI::Install.run("local-transmission") + described_class.run("local-transmission") expect { expect { - Hbc::CLI::Install.run("local-transmission", "--force") + described_class.run("local-transmission", "--force") }.to output(/It seems there is already an App at.*overwriting\./).to_stderr }.to output(/local-transmission was successfully installed!/).to_stdout end it "skips dependencies with --skip-cask-deps" do - Hbc::CLI::Install.run("with-depends-on-cask-multiple", "--skip-cask-deps") - expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-cask-multiple.rb")).to be_installed - expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")).not_to be_installed - expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).not_to be_installed + described_class.run("with-depends-on-cask-multiple", "--skip-cask-deps") + expect(Hbc::CaskLoader.load(cask_path("with-depends-on-cask-multiple"))).to be_installed + expect(Hbc::CaskLoader.load(cask_path("local-caffeine"))).not_to be_installed + expect(Hbc::CaskLoader.load(cask_path("local-transmission"))).not_to be_installed end it "properly handles Casks that are not present" do expect { - Hbc::CLI::Install.run("notacask") - }.to raise_error(Hbc::CaskError, "Install incomplete.") + described_class.run("notacask") + }.to raise_error(Hbc::CaskUnavailableError) end it "returns a suggestion for a misspelled Cask" do expect { - begin - Hbc::CLI::Install.run("localcaffeine") - rescue Hbc::CaskError - nil - end - }.to output(/Cask 'localcaffeine' is unavailable: No Cask with this name exists\. Did you mean:\nlocal-caffeine/).to_stderr + described_class.run("localcaffeine") + }.to raise_error(Hbc::CaskUnavailableError, /Cask 'localcaffeine' is unavailable: No Cask with this name exists\. Did you mean “local-caffeine”?/) end it "returns multiple suggestions for a Cask fragment" do expect { - begin - Hbc::CLI::Install.run("local-caf") - rescue Hbc::CaskError - nil - end - }.to output(/Cask 'local-caf' is unavailable: No Cask with this name exists\. Did you mean one of:\nlocal-caffeine/).to_stderr - end - - describe "when no Cask is specified" do - with_options = lambda do |options| - it "raises an exception" do - expect { - Hbc::CLI::Install.run(*options) - }.to raise_error(Hbc::CaskUnspecifiedError) - end - end - - describe "without options" do - with_options.call([]) - end - - describe "with --force" do - with_options.call(["--force"]) - end - - describe "with --skip-cask-deps" do - with_options.call(["--skip-cask-deps"]) - end - - describe "with an invalid option" do - it "raises an error" do - expect { - Hbc::CLI::Install.run("--notavalidoption") - }.to raise_error(/invalid option/) - end - end + described_class.run("local") + }.to raise_error(Hbc::CaskUnavailableError, /Cask 'local' is unavailable: No Cask with this name exists\. Did you mean one of these\?\nlocal-caffeine\nlocal-transmission/) end end diff --git a/Library/Homebrew/test/cask/cli/list_spec.rb b/Library/Homebrew/test/cask/cli/list_spec.rb index ecca3035f..301ca9b89 100644 --- a/Library/Homebrew/test/cask/cli/list_spec.rb +++ b/Library/Homebrew/test/cask/cli/list_spec.rb @@ -1,4 +1,8 @@ +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::List, :cask do + it_behaves_like "a command that handles invalid options" + it "lists the installed Casks in a pretty fashion" do casks = %w[local-caffeine local-transmission].map { |c| Hbc::CaskLoader.load(c) } @@ -7,10 +11,30 @@ describe Hbc::CLI::List, :cask do end expect { - Hbc::CLI::List.run + described_class.run + }.to output(<<-EOS.undent).to_stdout + local-caffeine + local-transmission + EOS + end + + it "lists full names" do + casks = %w[ + local-caffeine + third-party/tap/third-party-cask + local-transmission + ].map { |c| Hbc::CaskLoader.load(c) } + + casks.each do |c| + InstallHelper.install_with_caskfile(c) + end + + expect { + described_class.run("--full-name") }.to output(<<-EOS.undent).to_stdout local-caffeine local-transmission + third-party/tap/third-party-cask EOS end @@ -29,29 +53,31 @@ describe Hbc::CLI::List, :cask do it "of all installed Casks" do expect { - Hbc::CLI::List.run("--versions") + described_class.run("--versions") }.to output(expected_output).to_stdout end it "of given Casks" do expect { - Hbc::CLI::List.run("--versions", "local-caffeine", "local-transmission") + described_class.run("--versions", "local-caffeine", "local-transmission") }.to output(expected_output).to_stdout end end describe "given a set of installed Casks" do - let(:caffeine) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") } - let(:transmission) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") } + let(:caffeine) { Hbc::CaskLoader.load(cask_path("local-caffeine")) } + let(:transmission) { Hbc::CaskLoader.load(cask_path("local-transmission")) } let(:casks) { [caffeine, transmission] } it "lists the installed files for those Casks" do casks.each(&InstallHelper.method(:install_without_artifacts_with_caskfile)) - Hbc::Artifact::App.new(transmission).install_phase + transmission.artifacts.select { |a| a.is_a?(Hbc::Artifact::App) }.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end expect { - Hbc::CLI::List.run("local-transmission", "local-caffeine") + described_class.run("local-transmission", "local-caffeine") }.to output(<<-EOS.undent).to_stdout ==> Apps #{Hbc.appdir.join("Transmission.app")} (#{Hbc.appdir.join("Transmission.app").abv}) diff --git a/Library/Homebrew/test/cask/cli/options_spec.rb b/Library/Homebrew/test/cask/cli/options_spec.rb index 98eb05f7e..82d830795 100644 --- a/Library/Homebrew/test/cask/cli/options_spec.rb +++ b/Library/Homebrew/test/cask/cli/options_spec.rb @@ -1,6 +1,6 @@ describe Hbc::CLI, :cask do it "supports setting the appdir" do - Hbc::CLI.new.process_options("help", "--appdir=/some/path/foo") + described_class.new.process_options("help", "--appdir=/some/path/foo") expect(Hbc.appdir).to eq(Pathname.new("/some/path/foo")) end @@ -8,13 +8,13 @@ describe Hbc::CLI, :cask do it "supports setting the appdir from ENV" do ENV["HOMEBREW_CASK_OPTS"] = "--appdir=/some/path/bar" - Hbc::CLI.new.process_options("help") + described_class.new.process_options("help") expect(Hbc.appdir).to eq(Pathname.new("/some/path/bar")) end it "supports setting the prefpanedir" do - Hbc::CLI.new.process_options("help", "--prefpanedir=/some/path/foo") + described_class.new.process_options("help", "--prefpanedir=/some/path/foo") expect(Hbc.prefpanedir).to eq(Pathname.new("/some/path/foo")) end @@ -22,13 +22,13 @@ describe Hbc::CLI, :cask do it "supports setting the prefpanedir from ENV" do ENV["HOMEBREW_CASK_OPTS"] = "--prefpanedir=/some/path/bar" - Hbc::CLI.new.process_options("help") + described_class.new.process_options("help") expect(Hbc.prefpanedir).to eq(Pathname.new("/some/path/bar")) end it "supports setting the qlplugindir" do - Hbc::CLI.new.process_options("help", "--qlplugindir=/some/path/foo") + described_class.new.process_options("help", "--qlplugindir=/some/path/foo") expect(Hbc.qlplugindir).to eq(Pathname.new("/some/path/foo")) end @@ -36,13 +36,13 @@ describe Hbc::CLI, :cask do it "supports setting the qlplugindir from ENV" do ENV["HOMEBREW_CASK_OPTS"] = "--qlplugindir=/some/path/bar" - Hbc::CLI.new.process_options("help") + described_class.new.process_options("help") expect(Hbc.qlplugindir).to eq(Pathname.new("/some/path/bar")) end it "supports setting the colorpickerdir" do - Hbc::CLI.new.process_options("help", "--colorpickerdir=/some/path/foo") + described_class.new.process_options("help", "--colorpickerdir=/some/path/foo") expect(Hbc.colorpickerdir).to eq(Pathname.new("/some/path/foo")) end @@ -50,13 +50,13 @@ describe Hbc::CLI, :cask do it "supports setting the colorpickerdir from ENV" do ENV["HOMEBREW_CASK_OPTS"] = "--colorpickerdir=/some/path/bar" - Hbc::CLI.new.process_options("help") + described_class.new.process_options("help") expect(Hbc.colorpickerdir).to eq(Pathname.new("/some/path/bar")) end it "supports setting the dictionarydir" do - Hbc::CLI.new.process_options("help", "--dictionarydir=/some/path/foo") + described_class.new.process_options("help", "--dictionarydir=/some/path/foo") expect(Hbc.dictionarydir).to eq(Pathname.new("/some/path/foo")) end @@ -64,13 +64,13 @@ describe Hbc::CLI, :cask do it "supports setting the dictionarydir from ENV" do ENV["HOMEBREW_CASK_OPTS"] = "--dictionarydir=/some/path/bar" - Hbc::CLI.new.process_options("help") + described_class.new.process_options("help") expect(Hbc.dictionarydir).to eq(Pathname.new("/some/path/bar")) end it "supports setting the fontdir" do - Hbc::CLI.new.process_options("help", "--fontdir=/some/path/foo") + described_class.new.process_options("help", "--fontdir=/some/path/foo") expect(Hbc.fontdir).to eq(Pathname.new("/some/path/foo")) end @@ -78,13 +78,13 @@ describe Hbc::CLI, :cask do it "supports setting the fontdir from ENV" do ENV["HOMEBREW_CASK_OPTS"] = "--fontdir=/some/path/bar" - Hbc::CLI.new.process_options("help") + described_class.new.process_options("help") expect(Hbc.fontdir).to eq(Pathname.new("/some/path/bar")) end it "supports setting the servicedir" do - Hbc::CLI.new.process_options("help", "--servicedir=/some/path/foo") + described_class.new.process_options("help", "--servicedir=/some/path/foo") expect(Hbc.servicedir).to eq(Pathname.new("/some/path/foo")) end @@ -92,13 +92,13 @@ describe Hbc::CLI, :cask do it "supports setting the servicedir from ENV" do ENV["HOMEBREW_CASK_OPTS"] = "--servicedir=/some/path/bar" - Hbc::CLI.new.process_options("help") + described_class.new.process_options("help") expect(Hbc.servicedir).to eq(Pathname.new("/some/path/bar")) end it "allows additional options to be passed through" do - rest = Hbc::CLI.new.process_options("edit", "foo", "--create", "--appdir=/some/path/qux") + rest = described_class.new.process_options("edit", "foo", "--create", "--appdir=/some/path/qux") expect(Hbc.appdir).to eq(Pathname.new("/some/path/qux")) expect(rest).to eq(%w[edit foo --create]) @@ -106,7 +106,7 @@ describe Hbc::CLI, :cask do describe "--help" do it "sets the Cask help method to true" do - command = Hbc::CLI.new("foo", "--help") + command = described_class.new("foo", "--help") expect(command.help?).to be true end end diff --git a/Library/Homebrew/test/cask/cli/outdated_spec.rb b/Library/Homebrew/test/cask/cli/outdated_spec.rb index 946092f89..5bbf18d21 100644 --- a/Library/Homebrew/test/cask/cli/outdated_spec.rb +++ b/Library/Homebrew/test/cask/cli/outdated_spec.rb @@ -1,11 +1,13 @@ +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Outdated, :cask do let(:installed) do [ - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb"), - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/outdated/local-caffeine.rb"), - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/outdated/local-transmission.rb"), - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/version-latest-string.rb"), - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/outdated/auto-updates.rb"), + Hbc::CaskLoader.load(cask_path("basic-cask")), + Hbc::CaskLoader.load(cask_path("outdated/local-caffeine")), + Hbc::CaskLoader.load(cask_path("outdated/local-transmission")), + Hbc::CaskLoader.load(cask_path("version-latest-string")), + Hbc::CaskLoader.load(cask_path("outdated/auto-updates")), ] end @@ -15,6 +17,8 @@ describe Hbc::CLI::Outdated, :cask do allow_any_instance_of(described_class).to receive(:verbose?).and_return(true) end + it_behaves_like "a command that handles invalid options" + describe 'without --greedy it ignores the Casks with "vesion latest" or "auto_updates true"' do it "checks all the installed Casks when no token is provided" do expect { @@ -70,7 +74,7 @@ describe Hbc::CLI::Outdated, :cask do end it 'does not include the Casks with "auto_updates true" when the version did not change' do - cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/auto-updates.rb") + cask = Hbc::CaskLoader.load(cask_path("auto-updates")) InstallHelper.install_with_caskfile(cask) expect { diff --git a/Library/Homebrew/test/cask/cli/reinstall_spec.rb b/Library/Homebrew/test/cask/cli/reinstall_spec.rb index 3a9c3e2f5..95294b695 100644 --- a/Library/Homebrew/test/cask/cli/reinstall_spec.rb +++ b/Library/Homebrew/test/cask/cli/reinstall_spec.rb @@ -1,6 +1,10 @@ +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Reinstall, :cask do + it_behaves_like "a command that handles invalid options" + it "displays the reinstallation progress" do - caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") + caffeine = Hbc::CaskLoader.load(cask_path("local-caffeine")) Hbc::Installer.new(caffeine).install @@ -23,16 +27,16 @@ describe Hbc::CLI::Reinstall, :cask do it "allows reinstalling a Cask" do Hbc::CLI::Install.run("local-transmission") - expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed + expect(Hbc::CaskLoader.load(cask_path("local-transmission"))).to be_installed Hbc::CLI::Reinstall.run("local-transmission") - expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed + expect(Hbc::CaskLoader.load(cask_path("local-transmission"))).to be_installed end it "allows reinstalling a non installed Cask" do - expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).not_to be_installed + expect(Hbc::CaskLoader.load(cask_path("local-transmission"))).not_to be_installed Hbc::CLI::Reinstall.run("local-transmission") - expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed + expect(Hbc::CaskLoader.load(cask_path("local-transmission"))).to be_installed end end diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index e237ad464..a4f796f3c 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -1,9 +1,15 @@ +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Search, :cask do before(:each) do allow(Tty).to receive(:width).and_return(0) end + it_behaves_like "a command that handles invalid options" + it "lists the available Casks that match the search term" do + allow(GitHub).to receive(:search_code).and_return([]) + expect { Hbc::CLI::Search.run("local") }.to output(<<-EOS.undent).to_stdout.as_tty @@ -14,24 +20,47 @@ describe Hbc::CLI::Search, :cask do end it "outputs a plain list when stdout is not a TTY" do + allow(GitHub).to receive(:search_code).and_return([]) + + expect { + Hbc::CLI::Search.run("local") + }.to output(<<-EOS.undent).to_stdout + local-caffeine + local-transmission + EOS + end + + it "returns matches even when online search failed" do + allow(GitHub).to receive(:search_code).and_raise(GitHub::Error.new("reason")) + expect { Hbc::CLI::Search.run("local") }.to output(<<-EOS.undent).to_stdout local-caffeine local-transmission EOS + .and output(/^Warning: Error searching on GitHub: reason/).to_stderr end it "shows that there are no Casks matching a search term that did not result in anything" do expect { Hbc::CLI::Search.run("foo-bar-baz") - }.to output("No Cask found for \"foo-bar-baz\".\n").to_stdout.as_tty + }.to output(<<-EOS.undent).to_stdout.as_tty + No Cask found for "foo-bar-baz". + EOS end - it "lists all available Casks with no search term" do - expect { - Hbc::CLI::Search.run - }.to output(/local-caffeine/).to_stdout.as_tty + it "doesn't output anything to non-TTY stdout when there are no matches" do + expect { Hbc::CLI::Search.run("foo-bar-baz") } + .to not_to_output.to_stdout + .and not_to_output.to_stderr + end + + it "lists all Casks available offline with no search term" do + allow(GitHub).to receive(:search_code).and_raise(GitHub::Error.new("reason")) + expect { Hbc::CLI::Search.run } + .to output(/local-caffeine/).to_stdout.as_tty + .and not_to_output.to_stderr end it "ignores hyphens in search terms" do @@ -55,19 +84,29 @@ describe Hbc::CLI::Search, :cask do it "accepts a regexp argument" do expect { Hbc::CLI::Search.run("/^local-c[a-z]ffeine$/") - }.to output("==> Regexp Matches\nlocal-caffeine\n").to_stdout.as_tty + }.to output(<<-EOS.undent).to_stdout.as_tty + ==> Regexp Matches + local-caffeine + EOS end - it "Returns both exact and partial matches" do + it "returns both exact and partial matches" do expect { Hbc::CLI::Search.run("test-opera") - }.to output(/^==> Exact Match\ntest-opera\n==> Partial Matches\ntest-opera-mail/).to_stdout.as_tty + }.to output(<<-EOS.undent).to_stdout.as_tty + ==> Exact Match + test-opera + ==> Partial Matches + test-opera-mail + EOS end it "does not search the Tap name" do expect { Hbc::CLI::Search.run("caskroom") - }.to output(/^No Cask found for "caskroom"\.\n/).to_stdout.as_tty + }.to output(<<-EOS.undent).to_stdout.as_tty + No Cask found for "caskroom". + EOS end it "doesn't highlight packages that aren't installed" do diff --git a/Library/Homebrew/test/cask/cli/shared_examples/invalid_option.rb b/Library/Homebrew/test/cask/cli/shared_examples/invalid_option.rb new file mode 100644 index 000000000..12a05be92 --- /dev/null +++ b/Library/Homebrew/test/cask/cli/shared_examples/invalid_option.rb @@ -0,0 +1,15 @@ +shared_examples "a command that handles invalid options" do + context "when an invalid option is specified" do + it "raises an exception when no Cask is specified" do + expect { + described_class.run("--not-a-valid-option") + }.to raise_error("invalid option: --not-a-valid-option") + end + + it "raises an exception when a Cask is specified" do + expect { + described_class.run("--not-a-valid-option", "basic-cask") + }.to raise_error("invalid option: --not-a-valid-option") + end + end +end diff --git a/Library/Homebrew/test/cask/cli/shared_examples/requires_cask_token.rb b/Library/Homebrew/test/cask/cli/shared_examples/requires_cask_token.rb new file mode 100644 index 000000000..dc1e471e5 --- /dev/null +++ b/Library/Homebrew/test/cask/cli/shared_examples/requires_cask_token.rb @@ -0,0 +1,9 @@ +shared_examples "a command that requires a Cask token" do + context "when no Cask is specified" do + it "raises an exception " do + expect { + described_class.run + }.to raise_error(Hbc::CaskUnspecifiedError, "This command requires a Cask token.") + end + end +end diff --git a/Library/Homebrew/test/cask/cli/style_spec.rb b/Library/Homebrew/test/cask/cli/style_spec.rb index 2007b87d7..12cd348a0 100644 --- a/Library/Homebrew/test/cask/cli/style_spec.rb +++ b/Library/Homebrew/test/cask/cli/style_spec.rb @@ -1,11 +1,13 @@ require "open3" require "rubygems" +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Style, :cask do let(:args) { [] } let(:cli) { described_class.new(*args) } - around(&:run) + it_behaves_like "a command that handles invalid options" describe "#run" do subject { cli.run } diff --git a/Library/Homebrew/test/cask/cli/uninstall_spec.rb b/Library/Homebrew/test/cask/cli/uninstall_spec.rb index 1a1c57e88..80b7edbd3 100644 --- a/Library/Homebrew/test/cask/cli/uninstall_spec.rb +++ b/Library/Homebrew/test/cask/cli/uninstall_spec.rb @@ -1,6 +1,12 @@ +require_relative "shared_examples/requires_cask_token" +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Uninstall, :cask do + it_behaves_like "a command that requires a Cask token" + it_behaves_like "a command that handles invalid options" + it "displays the uninstallation progress" do - caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") + caffeine = Hbc::CaskLoader.load(cask_path("local-caffeine")) Hbc::Installer.new(caffeine).install @@ -10,31 +16,29 @@ describe Hbc::CLI::Uninstall, :cask do EOS expect { - Hbc::CLI::Uninstall.run("local-caffeine") + described_class.run("local-caffeine") }.to output(output).to_stdout end it "shows an error when a bad Cask is provided" do - expect { Hbc::CLI::Uninstall.run("notacask") } - .to output(/is unavailable/).to_stderr - .and raise_error(Hbc::CaskError, "Uninstall incomplete.") + expect { described_class.run("notacask") } + .to raise_error(Hbc::CaskUnavailableError, /is unavailable/) end it "shows an error when a Cask is provided that's not installed" do - expect { Hbc::CLI::Uninstall.run("local-caffeine") } - .to output(/is not installed/).to_stderr - .and raise_error(Hbc::CaskError, "Uninstall incomplete.") + expect { described_class.run("local-caffeine") } + .to raise_error(Hbc::CaskNotInstalledError, /is not installed/) end it "tries anyway on a non-present Cask when --force is given" do expect { - Hbc::CLI::Uninstall.run("local-caffeine", "--force") + described_class.run("local-caffeine", "--force") }.not_to raise_error end it "can uninstall and unlink multiple Casks at once" do - caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") - transmission = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") + caffeine = Hbc::CaskLoader.load(cask_path("local-caffeine")) + transmission = Hbc::CaskLoader.load(cask_path("local-transmission")) Hbc::Installer.new(caffeine).install Hbc::Installer.new(transmission).install @@ -42,7 +46,7 @@ describe Hbc::CLI::Uninstall, :cask do expect(caffeine).to be_installed expect(transmission).to be_installed - Hbc::CLI::Uninstall.run("local-caffeine", "local-transmission") + described_class.run("local-caffeine", "local-transmission") expect(caffeine).not_to be_installed expect(Hbc.appdir.join("Transmission.app")).not_to exist @@ -51,7 +55,7 @@ describe Hbc::CLI::Uninstall, :cask do end it "calls `uninstall` before removing artifacts" do - cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-script-app.rb") + cask = Hbc::CaskLoader.load(cask_path("with-uninstall-script-app")) Hbc::Installer.new(cask).install @@ -59,7 +63,7 @@ describe Hbc::CLI::Uninstall, :cask do expect(Hbc.appdir.join("MyFancyApp.app")).to exist expect { - Hbc::CLI::Uninstall.run("with-uninstall-script-app") + described_class.run("with-uninstall-script-app") }.not_to raise_error expect(cask).not_to be_installed @@ -67,7 +71,7 @@ describe Hbc::CLI::Uninstall, :cask do end it "can uninstall Casks when the uninstall script is missing, but only when using `--force`" do - cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-script-app.rb") + cask = Hbc::CaskLoader.load(cask_path("with-uninstall-script-app")) Hbc::Installer.new(cask).install @@ -75,14 +79,13 @@ describe Hbc::CLI::Uninstall, :cask do Hbc.appdir.join("MyFancyApp.app").rmtree - expect { Hbc::CLI::Uninstall.run("with-uninstall-script-app") } - .to output(/does not exist/).to_stderr - .and raise_error(Hbc::CaskError, "Uninstall incomplete.") + expect { described_class.run("with-uninstall-script-app") } + .to raise_error(Hbc::CaskError, /uninstall script .* does not exist/) expect(cask).to be_installed expect { - Hbc::CLI::Uninstall.run("with-uninstall-script-app", "--force") + described_class.run("with-uninstall-script-app", "--force") }.not_to raise_error expect(cask).not_to be_installed @@ -115,13 +118,13 @@ describe Hbc::CLI::Uninstall, :cask do end it "uninstalls one version at a time" do - Hbc::CLI::Uninstall.run("versioned-cask") + described_class.run("versioned-cask") expect(caskroom_path.join(first_installed_version)).to exist expect(caskroom_path.join(last_installed_version)).not_to exist expect(caskroom_path).to exist - Hbc::CLI::Uninstall.run("versioned-cask") + described_class.run("versioned-cask") expect(caskroom_path.join(first_installed_version)).not_to exist expect(caskroom_path).not_to exist @@ -130,7 +133,7 @@ describe Hbc::CLI::Uninstall, :cask do it "displays a message when versions remain installed" do expect { expect { - Hbc::CLI::Uninstall.run("versioned-cask") + described_class.run("versioned-cask") }.not_to output.to_stderr }.to output(/#{token} #{first_installed_version} is still installed./).to_stdout end @@ -160,26 +163,10 @@ describe Hbc::CLI::Uninstall, :cask do end it "can still uninstall those Casks" do - Hbc::CLI::Uninstall.run("ive-been-renamed") + described_class.run("ive-been-renamed") expect(app).not_to exist expect(caskroom_path).not_to exist end end - - describe "when no Cask is specified" do - it "raises an exception" do - expect { - Hbc::CLI::Uninstall.run - }.to raise_error(Hbc::CaskUnspecifiedError) - end - end - - describe "when no Cask is specified, but an invalid option" do - it "raises an exception" do - expect { - Hbc::CLI::Uninstall.run("--notavalidoption") - }.to raise_error(/invalid option/) - end - end end diff --git a/Library/Homebrew/test/cask/cli/zap_spec.rb b/Library/Homebrew/test/cask/cli/zap_spec.rb index fdc5b4125..05c882854 100644 --- a/Library/Homebrew/test/cask/cli/zap_spec.rb +++ b/Library/Homebrew/test/cask/cli/zap_spec.rb @@ -1,13 +1,18 @@ +require_relative "shared_examples/requires_cask_token" +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Zap, :cask do + it_behaves_like "a command that requires a Cask token" + it_behaves_like "a command that handles invalid options" + it "shows an error when a bad Cask is provided" do - expect { Hbc::CLI::Zap.run("notacask") } - .to output(/is unavailable/).to_stderr - .and raise_error(Hbc::CaskError, "Zap incomplete.") + expect { described_class.run("notacask") } + .to raise_error(Hbc::CaskUnavailableError, /is unavailable/) end it "can zap and unlink multiple Casks at once" do - caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") - transmission = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") + caffeine = Hbc::CaskLoader.load(cask_path("local-caffeine")) + transmission = Hbc::CaskLoader.load(cask_path("local-transmission")) Hbc::Installer.new(caffeine).install Hbc::Installer.new(transmission).install @@ -15,7 +20,7 @@ describe Hbc::CLI::Zap, :cask do expect(caffeine).to be_installed expect(transmission).to be_installed - Hbc::CLI::Zap.run("local-caffeine", "local-transmission") + described_class.run("local-caffeine", "local-transmission") expect(caffeine).not_to be_installed expect(Hbc.appdir.join("Caffeine.app")).not_to be_a_symlink @@ -46,20 +51,4 @@ describe Hbc::CLI::Zap, :cask do # # with_zap.wont_be :installed? # end - - describe "when no Cask is specified" do - it "raises an exception" do - expect { - Hbc::CLI::Zap.run - }.to raise_error(Hbc::CaskUnspecifiedError) - end - end - - describe "when no Cask is specified, but an invalid option" do - it "raises an exception" do - expect { - Hbc::CLI::Zap.run("--notavalidoption") - }.to raise_error(/invalid option/) - end - end end diff --git a/Library/Homebrew/test/cask/conflicts_with_spec.rb b/Library/Homebrew/test/cask/conflicts_with_spec.rb new file mode 100644 index 000000000..81c22ded6 --- /dev/null +++ b/Library/Homebrew/test/cask/conflicts_with_spec.rb @@ -0,0 +1,23 @@ +describe "conflicts_with", :cask do + describe "conflicts_with cask" do + let(:local_caffeine) { + Hbc::CaskLoader.load(cask_path("local-caffeine")) + } + + let(:with_conflicts_with) { + Hbc::CaskLoader.load(cask_path("with-conflicts-with")) + } + + it "installs the dependency of a Cask and the Cask itself" do + Hbc::Installer.new(local_caffeine).install + + expect(local_caffeine).to be_installed + + expect { + Hbc::Installer.new(with_conflicts_with).install + }.to raise_error(Hbc::CaskConflictError, "Cask 'with-conflicts-with' conflicts with 'local-caffeine'.") + + expect(with_conflicts_with).not_to be_installed + end + end +end diff --git a/Library/Homebrew/test/cask/container/dmg_spec.rb b/Library/Homebrew/test/cask/container/dmg_spec.rb index 4f3f57071..df99a6264 100644 --- a/Library/Homebrew/test/cask/container/dmg_spec.rb +++ b/Library/Homebrew/test/cask/container/dmg_spec.rb @@ -1,7 +1,7 @@ describe Hbc::Container::Dmg, :cask do describe "#mount!" do it "does not store nil mounts for dmgs with extra data" do - transmission = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") + transmission = Hbc::CaskLoader.load(cask_path("local-transmission")) dmg = Hbc::Container::Dmg.new( transmission, diff --git a/Library/Homebrew/test/cask/depends_on_spec.rb b/Library/Homebrew/test/cask/depends_on_spec.rb index c603cf6e1..453a761f7 100644 --- a/Library/Homebrew/test/cask/depends_on_spec.rb +++ b/Library/Homebrew/test/cask/depends_on_spec.rb @@ -9,12 +9,15 @@ describe "Satisfy Dependencies and Requirements", :cask do describe "depends_on cask" do context "when depends_on cask is cyclic" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-cask-cyclic.rb") } - it { is_expected.to raise_error(Hbc::CaskCyclicDependencyError) } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-depends-on-cask-cyclic")) } + it { + is_expected.to raise_error(Hbc::CaskCyclicDependencyError, + "Cask 'with-depends-on-cask-cyclic' includes cyclic dependencies on other Casks: with-depends-on-cask-cyclic-helper") + } end context do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-cask.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-depends-on-cask")) } let(:dependency) { Hbc::CaskLoader.load(cask.depends_on.cask.first) } it "installs the dependency of a Cask and the Cask itself" do @@ -27,34 +30,34 @@ describe "Satisfy Dependencies and Requirements", :cask do describe "depends_on macos" do context "given an array" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-macos-array.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-depends-on-macos-array")) } it { is_expected.not_to raise_error } end - context "given a comparisson" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-macos-comparison.rb") } + context "given a comparison" do + let(:cask) { Hbc::CaskLoader.load(cask_path("with-depends-on-macos-comparison")) } it { is_expected.not_to raise_error } end context "given a string" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-macos-string.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-depends-on-macos-string")) } it { is_expected.not_to raise_error } end context "given a symbol" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-macos-symbol.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-depends-on-macos-symbol")) } it { is_expected.not_to raise_error } end context "when not satisfied" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-macos-failure.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-depends-on-macos-failure")) } it { is_expected.to raise_error(Hbc::CaskError) } end end describe "depends_on arch" do context "when satisfied" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-arch.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-depends-on-arch")) } it { is_expected.not_to raise_error } end end @@ -65,21 +68,21 @@ describe "Satisfy Dependencies and Requirements", :cask do end context "when satisfied" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-x11.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-depends-on-x11")) } let(:x11_installed) { true } it { is_expected.not_to raise_error } end context "when not satisfied" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-x11.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-depends-on-x11")) } let(:x11_installed) { false } it { is_expected.to raise_error(Hbc::CaskX11DependencyError) } end context "when depends_on x11: false" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-x11-false.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-depends-on-x11-false")) } let(:x11_installed) { false } it { is_expected.not_to raise_error } diff --git a/Library/Homebrew/test/cask/download_strategy_spec.rb b/Library/Homebrew/test/cask/download_strategy_spec.rb index 222352c07..17da1e36e 100644 --- a/Library/Homebrew/test/cask/download_strategy_spec.rb +++ b/Library/Homebrew/test/cask/download_strategy_spec.rb @@ -26,9 +26,12 @@ describe "download strategies", :cask do downloader.fetch expect(downloader).to have_received(:curl).with( + "--location", + "--remote-time", + "--continue-at", "-", + "--output", kind_of(Pathname), cask.url.to_s, - "-C", 0, - "-o", kind_of(Pathname) + user_agent: :default ) end @@ -36,25 +39,25 @@ describe "download strategies", :cask do let(:url_options) { { user_agent: "Mozilla/25.0.1" } } it "adds the appropriate curl args" do - curl_args = [] - allow(downloader).to receive(:curl) { |*args| curl_args = args } + expect(downloader).to receive(:safe_system) { |*args| + expect(args.each_cons(2)).to include(["--user-agent", "Mozilla/25.0.1"]) + } downloader.fetch - - expect(curl_args.each_cons(2)).to include(["-A", "Mozilla/25.0.1"]) end end context "with a generalized fake user agent" do + alias_matcher :a_string_matching, :match + let(:url_options) { { user_agent: :fake } } it "adds the appropriate curl args" do - curl_args = [] - allow(downloader).to receive(:curl) { |*args| curl_args = args } + expect(downloader).to receive(:safe_system) { |*args| + expect(args.each_cons(2).to_a).to include(["--user-agent", a_string_matching(/Mozilla.*Mac OS X 10.*AppleWebKit/)]) + } downloader.fetch - - expect(curl_args.each_cons(2)).to include(["-A", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10) https://caskroom.github.io"]) end end @@ -138,7 +141,7 @@ describe "download strategies", :cask do describe Hbc::SubversionDownloadStrategy do let(:url_options) { { using: :svn } } let(:fake_system_command) { class_double(Hbc::SystemCommand) } - let(:downloader) { Hbc::SubversionDownloadStrategy.new(cask, fake_system_command) } + let(:downloader) { Hbc::SubversionDownloadStrategy.new(cask, command: fake_system_command) } before do allow(fake_system_command).to receive(:run!) end @@ -147,7 +150,7 @@ describe "download strategies", :cask do allow(downloader).to receive(:compress) allow(downloader).to receive(:fetch_repo) - expect(downloader.fetch).to equal(downloader.tarball_path) + expect(downloader.fetch).to equal(downloader.cached_location) end it "calls fetch_repo with default arguments for a simple Cask" do @@ -237,44 +240,5 @@ describe "download strategies", :cask do ) end end - - it "runs tar to serialize svn downloads" do - # sneaky stub to remake the directory, since homebrew code removes it - # before tar is called - allow(downloader).to receive(:fetch_repo) { - downloader.cached_location.mkdir - } - - downloader.fetch - - expect(fake_system_command).to have_received(:run!).with( - "/usr/bin/tar", - hash_including(args: [ - '-s/^\\.//', - "--exclude", - ".svn", - "-cf", - downloader.tarball_path, - "--", - ".", - ]), - ) - end end - - # does not work yet, because (for unknown reasons), the tar command - # returns an error code when running under the test suite - # it 'creates a tarball matching the expected checksum' do - # cask = Hbc::CaskLoader.load('svn-download-check-cask') - # downloader = Hbc::SubversionDownloadStrategy.new(cask) - # # special mocking required for tar to have something to work with - # def downloader.fetch_repo(target, url, revision = nil, ignore_externals=false) - # target.mkpath - # FileUtils.touch(target.join('empty_file.txt')) - # File.utime(1000,1000,target.join('empty_file.txt')) - # end - # expect(downloader.fetch).to equal(downloader.tarball_path) - # d = Hbc::Download.new(cask) - # d.send(:_check_sums, downloader.tarball_path, cask.sums) - # end end diff --git a/Library/Homebrew/test/cask/dsl/appcast_spec.rb b/Library/Homebrew/test/cask/dsl/appcast_spec.rb index b8903b1be..bf703eba2 100644 --- a/Library/Homebrew/test/cask/dsl/appcast_spec.rb +++ b/Library/Homebrew/test/cask/dsl/appcast_spec.rb @@ -4,7 +4,7 @@ describe Hbc::DSL::Appcast do subject { described_class.new(url, params) } let(:url) { "http://example.com" } - let(:uri) { Hbc::UnderscoreSupportingURI.parse(url) } + let(:uri) { URI(url) } let(:params) { {} } describe "#to_s" do @@ -33,13 +33,18 @@ describe Hbc::DSL::Appcast do describe "#calculate_checkpoint" do before do - expect(Hbc::SystemCommand).to receive(:run).with(*cmd_args).and_return(cmd_result) + expect(Hbc::SystemCommand).to receive(:run) do |executable, **options| + expect(executable).to eq "/usr/bin/curl" + expect(options[:args]).to include(*cmd_args) + expect(options[:print_stderr]).to be false + cmd_result + end 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_args) { [HOMEBREW_USER_AGENT_FAKE_SAFARI, "--compressed", "--location", "--fail", uri] } let(:cmd_result) { double("Hbc::SystemCommand::Result") } let(:cmd_success) { true } let(:cmd_stdout) { "hello world" } @@ -56,7 +61,7 @@ describe Hbc::DSL::Appcast do 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_args) { [HOMEBREW_USER_AGENT_FAKE_SAFARI, "--compressed", "--location", "--fail", uri] } let(:cmd_result) { double("Hbc::SystemCommand::Result") } let(:cmd_success) { false } let(:cmd_stdout) { "some error message from the server" } diff --git a/Library/Homebrew/test/cask/dsl/caveats_spec.rb b/Library/Homebrew/test/cask/dsl/caveats_spec.rb index aa662e4d0..1b82d9821 100644 --- a/Library/Homebrew/test/cask/dsl/caveats_spec.rb +++ b/Library/Homebrew/test/cask/dsl/caveats_spec.rb @@ -1,7 +1,7 @@ require "test/support/helper/spec/shared_examples/hbc_dsl_base" describe Hbc::DSL::Caveats, :cask do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("basic-cask")) } let(:dsl) { Hbc::DSL::Caveats.new(cask) } it_behaves_like Hbc::DSL::Base diff --git a/Library/Homebrew/test/cask/dsl/postflight_spec.rb b/Library/Homebrew/test/cask/dsl/postflight_spec.rb index d2b080ca3..4ac3ae7cf 100644 --- a/Library/Homebrew/test/cask/dsl/postflight_spec.rb +++ b/Library/Homebrew/test/cask/dsl/postflight_spec.rb @@ -2,7 +2,7 @@ require "test/support/helper/spec/shared_examples/hbc_dsl_base" require "test/support/helper/spec/shared_examples/hbc_staged" describe Hbc::DSL::Postflight, :cask do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("basic-cask")) } let(:dsl) { Hbc::DSL::Postflight.new(cask, Hbc::FakeSystemCommand) } it_behaves_like Hbc::DSL::Base diff --git a/Library/Homebrew/test/cask/dsl/preflight_spec.rb b/Library/Homebrew/test/cask/dsl/preflight_spec.rb index b93be95ff..f78944c50 100644 --- a/Library/Homebrew/test/cask/dsl/preflight_spec.rb +++ b/Library/Homebrew/test/cask/dsl/preflight_spec.rb @@ -2,7 +2,7 @@ require "test/support/helper/spec/shared_examples/hbc_dsl_base" require "test/support/helper/spec/shared_examples/hbc_staged" describe Hbc::DSL::Preflight, :cask do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("basic-cask")) } let(:dsl) { Hbc::DSL::Preflight.new(cask, Hbc::FakeSystemCommand) } it_behaves_like Hbc::DSL::Base diff --git a/Library/Homebrew/test/cask/dsl/uninstall_postflight_spec.rb b/Library/Homebrew/test/cask/dsl/uninstall_postflight_spec.rb index f89a181ce..b2af700db 100644 --- a/Library/Homebrew/test/cask/dsl/uninstall_postflight_spec.rb +++ b/Library/Homebrew/test/cask/dsl/uninstall_postflight_spec.rb @@ -1,7 +1,7 @@ require "test/support/helper/spec/shared_examples/hbc_dsl_base" describe Hbc::DSL::UninstallPostflight, :cask do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("basic-cask")) } let(:dsl) { Hbc::DSL::UninstallPostflight.new(cask, Hbc::FakeSystemCommand) } it_behaves_like Hbc::DSL::Base diff --git a/Library/Homebrew/test/cask/dsl/uninstall_preflight_spec.rb b/Library/Homebrew/test/cask/dsl/uninstall_preflight_spec.rb index 15a0ea156..8e7fa47eb 100644 --- a/Library/Homebrew/test/cask/dsl/uninstall_preflight_spec.rb +++ b/Library/Homebrew/test/cask/dsl/uninstall_preflight_spec.rb @@ -2,7 +2,7 @@ require "test/support/helper/spec/shared_examples/hbc_dsl_base" require "test/support/helper/spec/shared_examples/hbc_staged" describe Hbc::DSL::UninstallPreflight, :cask do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("basic-cask")) } let(:dsl) { Hbc::DSL::UninstallPreflight.new(cask, Hbc::FakeSystemCommand) } it_behaves_like Hbc::DSL::Base diff --git a/Library/Homebrew/test/cask/dsl_spec.rb b/Library/Homebrew/test/cask/dsl_spec.rb index 7f2207a87..28cf6f4b2 100644 --- a/Library/Homebrew/test/cask/dsl_spec.rb +++ b/Library/Homebrew/test/cask/dsl_spec.rb @@ -1,5 +1,5 @@ describe Hbc::DSL, :cask do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/#{token}.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path(token.to_s)) } let(:token) { "basic-cask" } context "stanzas" do @@ -177,6 +177,36 @@ describe Hbc::DSL, :cask do expect(cask.call.sha256).to eq("xyz789") expect(cask.call.url.to_s).to eq("https://example.org/en-US.zip") end + + it "returns an empty array if no languages are specified" do + cask = lambda do + Hbc::Cask.new("cask-with-apps") do + url "https://example.org/file.zip" + end + end + + expect(cask.call.languages).to be_empty + end + + it "returns an array of available languages" do + cask = lambda do + Hbc::Cask.new("cask-with-apps") do + language "zh" do + sha256 "abc123" + "zh-CN" + end + + language "en-US", default: true do + sha256 "xyz789" + "en-US" + end + + url "https://example.org/file.zip" + end + end + + expect(cask.call.languages).to eq(["zh", "en-US"]) + end end describe "app stanza" do @@ -186,12 +216,12 @@ describe Hbc::DSL, :cask do app "Bar.app" end - expect(Array(cask.artifacts[:app])).to eq([["Foo.app"], ["Bar.app"]]) + expect(cask.artifacts.map(&:to_s)).to eq(["Foo.app (App)", "Bar.app (App)"]) end it "allow app stanzas to be empty" do cask = Hbc::Cask.new("cask-with-no-apps") - expect(Array(cask.artifacts[:app])).to eq([]) + expect(cask.artifacts).to be_empty end end @@ -219,7 +249,7 @@ describe Hbc::DSL, :cask do pkg "Bar.pkg" end - expect(Array(cask.artifacts[:pkg])).to eq([["Foo.pkg"], ["Bar.pkg"]]) + expect(cask.artifacts.map(&:to_s)).to eq(["Foo.pkg (Pkg)", "Bar.pkg (Pkg)"]) end end @@ -471,10 +501,10 @@ describe Hbc::DSL, :cask do let(:token) { "with-installer-script" } it "allows installer script to be specified" do - expect(cask.artifacts[:installer].first.script[:executable]).to eq("/usr/bin/true") - expect(cask.artifacts[:installer].first.script[:args]).to eq(["--flag"]) - expect(cask.artifacts[:installer].to_a[1].script[:executable]).to eq("/usr/bin/false") - expect(cask.artifacts[:installer].to_a[1].script[:args]).to eq(["--flag"]) + expect(cask.artifacts.to_a[0].path).to eq(Pathname("/usr/bin/true")) + expect(cask.artifacts.to_a[0].args[:args]).to eq(["--flag"]) + expect(cask.artifacts.to_a[1].path).to eq(Pathname("/usr/bin/false")) + expect(cask.artifacts.to_a[1].args[:args]).to eq(["--flag"]) end end @@ -482,7 +512,9 @@ describe Hbc::DSL, :cask do let(:token) { "with-installer-manual" } it "allows installer manual to be specified" do - expect(cask.artifacts[:installer].first.manual).to eq("Caffeine.app") + installer = cask.artifacts.first + expect(installer).to be_a(Hbc::Artifact::Installer::ManualInstaller) + expect(installer.path).to eq(cask.staged_path.join("Caffeine.app")) end end end @@ -492,7 +524,7 @@ describe Hbc::DSL, :cask do let(:token) { "stage-only" } it "allows stage_only stanza to be specified" do - expect(cask.artifacts[:stage_only].first).to eq([true]) + expect(cask.artifacts).to contain_exactly a_kind_of Hbc::Artifact::StageOnly end end @@ -513,12 +545,12 @@ describe Hbc::DSL, :cask do end end - describe "appdir" do + describe "#appdir" do context "interpolation of the appdir in stanzas" do let(:token) { "appdir-interpolation" } it "is allowed" do - expect(cask.artifacts[:binary].first).to eq(["#{Hbc.appdir}/some/path"]) + expect(cask.artifacts.first.source).to eq(Hbc.appdir/"some/path") end end @@ -531,10 +563,35 @@ describe Hbc::DSL, :cask do binary "#{appdir}/some/path" end - expect(cask.artifacts[:binary].first).to eq(["#{original_appdir}/some/path"]) + expect(cask.artifacts.first.source).to eq(original_appdir/"some/path") ensure Hbc.appdir = original_appdir end end end + + describe "#artifacts" do + it "sorts artifacts according to the preferable installation order" do + cask = Hbc::Cask.new("appdir-trailing-slash") do + postflight do + next + end + + preflight do + next + end + + binary "binary" + + app "App.app" + end + + expect(cask.artifacts.map(&:class).map(&:dsl_key)).to eq [ + :preflight, + :app, + :binary, + :postflight, + ] + end + end end diff --git a/Library/Homebrew/test/cask/installer_spec.rb b/Library/Homebrew/test/cask/installer_spec.rb index 6f7c6d3d7..2dc27f04c 100644 --- a/Library/Homebrew/test/cask/installer_spec.rb +++ b/Library/Homebrew/test/cask/installer_spec.rb @@ -5,7 +5,7 @@ describe Hbc::Installer, :cask do } it "downloads and installs a nice fresh Cask" do - caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") + caffeine = Hbc::CaskLoader.load(cask_path("local-caffeine")) Hbc::Installer.new(caffeine).install @@ -14,7 +14,7 @@ describe Hbc::Installer, :cask do end it "works with dmg-based Casks" do - asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-dmg.rb") + asset = Hbc::CaskLoader.load(cask_path("container-dmg")) Hbc::Installer.new(asset).install @@ -23,7 +23,7 @@ describe Hbc::Installer, :cask do end it "works with tar-gz-based Casks" do - asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-tar-gz.rb") + asset = Hbc::CaskLoader.load(cask_path("container-tar-gz")) Hbc::Installer.new(asset).install @@ -32,7 +32,7 @@ describe Hbc::Installer, :cask do end it "works with xar-based Casks" do - asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-xar.rb") + asset = Hbc::CaskLoader.load(cask_path("container-xar")) Hbc::Installer.new(asset).install @@ -41,7 +41,7 @@ describe Hbc::Installer, :cask do end it "works with pure bzip2-based Casks" do - asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-bzip2.rb") + asset = Hbc::CaskLoader.load(cask_path("container-bzip2")) Hbc::Installer.new(asset).install @@ -50,7 +50,7 @@ describe Hbc::Installer, :cask do end it "works with pure gzip-based Casks" do - asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-gzip.rb") + asset = Hbc::CaskLoader.load(cask_path("container-gzip")) Hbc::Installer.new(asset).install @@ -59,21 +59,21 @@ describe Hbc::Installer, :cask do end it "blows up on a bad checksum" do - bad_checksum = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/bad-checksum.rb") + bad_checksum = Hbc::CaskLoader.load(cask_path("bad-checksum")) expect { Hbc::Installer.new(bad_checksum).install }.to raise_error(Hbc::CaskSha256MismatchError) end it "blows up on a missing checksum" do - missing_checksum = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/missing-checksum.rb") + missing_checksum = Hbc::CaskLoader.load(cask_path("missing-checksum")) expect { Hbc::Installer.new(missing_checksum).install }.to raise_error(Hbc::CaskSha256MissingError) end it "installs fine if sha256 :no_check is used" do - no_checksum = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/no-checksum.rb") + no_checksum = Hbc::CaskLoader.load(cask_path("no-checksum")) Hbc::Installer.new(no_checksum).install @@ -81,14 +81,14 @@ describe Hbc::Installer, :cask do end it "fails to install if sha256 :no_check is used with --require-sha" do - no_checksum = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/no-checksum.rb") + no_checksum = Hbc::CaskLoader.load(cask_path("no-checksum")) expect { Hbc::Installer.new(no_checksum, require_sha: true).install }.to raise_error(Hbc::CaskNoShasumError) end it "installs fine if sha256 :no_check is used with --require-sha and --force" do - no_checksum = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/no-checksum.rb") + no_checksum = Hbc::CaskLoader.load(cask_path("no-checksum")) Hbc::Installer.new(no_checksum, require_sha: true, force: true).install @@ -96,7 +96,7 @@ describe Hbc::Installer, :cask do end it "prints caveats if they're present" do - with_caveats = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-caveats.rb") + with_caveats = Hbc::CaskLoader.load(cask_path("with-caveats")) expect { Hbc::Installer.new(with_caveats).install @@ -106,7 +106,7 @@ describe Hbc::Installer, :cask do end it "prints installer :manual instructions when present" do - with_installer_manual = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-installer-manual.rb") + with_installer_manual = Hbc::CaskLoader.load(cask_path("with-installer-manual")) expect { Hbc::Installer.new(with_installer_manual).install @@ -116,7 +116,7 @@ describe Hbc::Installer, :cask do end it "does not extract __MACOSX directories from zips" do - with_macosx_dir = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-macosx-dir.rb") + with_macosx_dir = Hbc::CaskLoader.load(cask_path("with-macosx-dir")) Hbc::Installer.new(with_macosx_dir).install @@ -124,7 +124,7 @@ describe Hbc::Installer, :cask do end it "allows already-installed Casks which auto-update to be installed if force is provided" do - with_auto_updates = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/auto-updates.rb") + with_auto_updates = Hbc::CaskLoader.load(cask_path("auto-updates")) expect(with_auto_updates).not_to be_installed @@ -137,7 +137,7 @@ describe Hbc::Installer, :cask do # unlike the CLI, the internal interface throws exception on double-install it "installer method raises an exception when already-installed Casks are attempted" do - transmission = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") + transmission = Hbc::CaskLoader.load(cask_path("local-transmission")) expect(transmission).not_to be_installed @@ -151,7 +151,7 @@ describe Hbc::Installer, :cask do end it "allows already-installed Casks to be installed if force is provided" do - transmission = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") + transmission = Hbc::CaskLoader.load(cask_path("local-transmission")) expect(transmission).not_to be_installed @@ -163,7 +163,7 @@ describe Hbc::Installer, :cask do end it "works naked-pkg-based Casks" do - naked_pkg = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-pkg.rb") + naked_pkg = Hbc::CaskLoader.load(cask_path("container-pkg")) Hbc::Installer.new(naked_pkg).install @@ -171,7 +171,7 @@ describe Hbc::Installer, :cask do end it "works properly with an overridden container :type" do - naked_executable = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/naked-executable.rb") + naked_executable = Hbc::CaskLoader.load(cask_path("naked-executable")) Hbc::Installer.new(naked_executable).install @@ -179,7 +179,7 @@ describe Hbc::Installer, :cask do end it "works fine with a nested container" do - nested_app = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/nested-app.rb") + nested_app = Hbc::CaskLoader.load(cask_path("nested-app")) Hbc::Installer.new(nested_app).install @@ -187,7 +187,7 @@ describe Hbc::Installer, :cask do end it "generates and finds a timestamped metadata directory for an installed Cask" do - caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") + caffeine = Hbc::CaskLoader.load(cask_path("local-caffeine")) Hbc::Installer.new(caffeine).install @@ -196,7 +196,7 @@ describe Hbc::Installer, :cask do end it "generates and finds a metadata subdirectory for an installed Cask" do - caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") + caffeine = Hbc::CaskLoader.load(cask_path("local-caffeine")) Hbc::Installer.new(caffeine).install @@ -208,7 +208,7 @@ describe Hbc::Installer, :cask do describe "uninstall" do it "fully uninstalls a Cask" do - caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") + caffeine = Hbc::CaskLoader.load(cask_path("local-caffeine")) installer = Hbc::Installer.new(caffeine) installer.install @@ -220,7 +220,7 @@ describe Hbc::Installer, :cask do end it "uninstalls all versions if force is set" do - caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") + caffeine = Hbc::CaskLoader.load(cask_path("local-caffeine")) mutated_version = caffeine.version + ".1" Hbc::Installer.new(caffeine).install diff --git a/Library/Homebrew/test/cask/staged_spec.rb b/Library/Homebrew/test/cask/staged_spec.rb index 73a909f35..0229018c7 100644 --- a/Library/Homebrew/test/cask/staged_spec.rb +++ b/Library/Homebrew/test/cask/staged_spec.rb @@ -3,7 +3,7 @@ # to be invoking bundle_identifier off of the installer instance. describe "Operations on staged Casks", :cask do describe "bundle ID" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("local-transmission")) } let(:installer) { Hbc::Installer.new(cask) } it "fetches the bundle ID from a staged cask" do installer.install diff --git a/Library/Homebrew/test/cask/underscore_supporting_uri_spec.rb b/Library/Homebrew/test/cask/underscore_supporting_uri_spec.rb deleted file mode 100644 index 49d3ea63f..000000000 --- a/Library/Homebrew/test/cask/underscore_supporting_uri_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -describe Hbc::UnderscoreSupportingURI, :cask do - describe "parse" do - it "works like normal on normal URLs" do - uri = Hbc::UnderscoreSupportingURI.parse("http://example.com/TestCask.dmg") - expect(uri).to eq(URI("http://example.com/TestCask.dmg")) - end - - it "works just fine on URIs with underscores" do - uri = Hbc::UnderscoreSupportingURI.parse("http://dl_dir.qq.com/qqfile/qq/QQforMac/QQ_V3.0.0.dmg") - expect(uri.host).to include("_") - expect(uri.to_s).to eq("http://dl_dir.qq.com/qqfile/qq/QQforMac/QQ_V3.0.0.dmg") - end - end -end diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index 4e5e42efa..da262c5ca 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -5,6 +5,7 @@ require "pathname" describe Homebrew::Cleanup do let(:ds_store) { Pathname.new("#{HOMEBREW_PREFIX}/Library/.DS_Store") } + let(:sec_in_a_day) { 60 * 60 * 24 } around(:each) do |example| begin @@ -104,14 +105,30 @@ describe Homebrew::Cleanup do expect(f4).to be_installed end - specify "::cleanup_logs" do - path = (HOMEBREW_LOGS/"delete_me") - path.mkpath - ARGV << "--prune=all" + describe "::cleanup_logs" do + let(:path) { (HOMEBREW_LOGS/"delete_me") } - described_class.cleanup_logs + before do + path.mkpath + end + + it "cleans all logs if prune all" do + ARGV << "--prune=all" + described_class.cleanup_logs + expect(path).not_to exist + end - expect(path).not_to exist + it "cleans up logs if older than 14 days" do + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - sec_in_a_day * 15) + described_class.cleanup_logs + expect(path).not_to exist + end + + it "does not clean up logs less than 14 days old" do + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - sec_in_a_day * 2) + described_class.cleanup_logs + expect(path).to exist + end end describe "::cleanup_cache" do @@ -124,6 +141,15 @@ describe Homebrew::Cleanup do expect(incomplete).not_to exist end + it "cleans up 'glide_home'" do + glide_home = (HOMEBREW_CACHE/"glide_home") + glide_home.mkpath + + described_class.cleanup_cache + + expect(glide_home).not_to exist + end + it "cleans up 'java_cache'" do java_cache = (HOMEBREW_CACHE/"java_cache") java_cache.mkpath @@ -141,5 +167,99 @@ describe Homebrew::Cleanup do expect(npm_cache).not_to exist end + + it "cleans up all files and directories" do + git = (HOMEBREW_CACHE/"gist--git") + gist = (HOMEBREW_CACHE/"gist") + svn = (HOMEBREW_CACHE/"gist--svn") + + git.mkpath + gist.mkpath + FileUtils.touch svn + + allow(ARGV).to receive(:value).with("prune").and_return("all") + + described_class.cleanup_cache + + expect(git).not_to exist + expect(gist).to exist + expect(svn).not_to exist + end + + it "does not clean up directories that are not VCS checkouts" do + git = (HOMEBREW_CACHE/"git") + git.mkpath + allow(ARGV).to receive(:value).with("prune").and_return("all") + + described_class.cleanup_cache + + expect(git).to exist + end + + it "cleans up VCS checkout directories with modified time < prune time" do + foo = (HOMEBREW_CACHE/"--foo") + foo.mkpath + allow(ARGV).to receive(:value).with("prune").and_return("1") + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - sec_in_a_day * 2) + described_class.cleanup_cache + expect(foo).not_to exist + end + + it "does not clean up VCS checkout directories with modified time >= prune time" do + foo = (HOMEBREW_CACHE/"--foo") + foo.mkpath + allow(ARGV).to receive(:value).with("prune").and_return("1") + described_class.cleanup_cache + expect(foo).to exist + end + + context "cleans old files in HOMEBREW_CACHE" do + let(:bottle) { (HOMEBREW_CACHE/"testball-0.0.1.bottle.tar.gz") } + let(:testball) { (HOMEBREW_CACHE/"testball-0.0.1") } + + before(:each) do + FileUtils.touch(bottle) + FileUtils.touch(testball) + (HOMEBREW_CELLAR/"testball"/"0.0.1").mkpath + FileUtils.touch(CoreTap.instance.formula_dir/"testball.rb") + end + + it "cleans up file if outdated" do + allow(Utils::Bottles).to receive(:file_outdated?).with(any_args).and_return(true) + described_class.cleanup_cache + expect(bottle).not_to exist + expect(testball).not_to exist + end + + it "cleans up file if ARGV has -s and formula not installed" do + ARGV << "-s" + described_class.cleanup_cache + expect(bottle).not_to exist + expect(testball).not_to exist + end + + it "cleans up file if stale" do + described_class.cleanup_cache + expect(bottle).not_to exist + expect(testball).not_to exist + end + end + end + + describe "::prune?" do + before do + foo.mkpath + end + + let(:foo) { HOMEBREW_CACHE/"foo" } + + it "returns true when path_modified_time < days_default" do + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - sec_in_a_day * 2) + expect(described_class.prune?(foo, days_default: "1")).to be_truthy + end + + it "returns false when path_modified_time >= days_default" do + expect(described_class.prune?(foo, days_default: "2")).to be_falsey + end end end diff --git a/Library/Homebrew/test/cmd/commands_spec.rb b/Library/Homebrew/test/cmd/commands_spec.rb index cf6f56740..46ed3ddcf 100644 --- a/Library/Homebrew/test/cmd/commands_spec.rb +++ b/Library/Homebrew/test/cmd/commands_spec.rb @@ -68,7 +68,7 @@ describe Homebrew do expect(cmds).to include("t1"), "Executable files should be included" expect(cmds).to include("t2"), "Executable Ruby files should be included" - expect(cmds).not_to include("t3"), "Executable files with a non Ruby extension shoudn't be included" + expect(cmds).not_to include("t3"), "Executable files with a non Ruby extension shouldn't be included" expect(cmds).not_to include("t4"), "Non-executable files shouldn't be included" end end diff --git a/Library/Homebrew/test/cmd/home_spec.rb b/Library/Homebrew/test/cmd/home_spec.rb index 5a4070492..cf9453af2 100644 --- a/Library/Homebrew/test/cmd/home_spec.rb +++ b/Library/Homebrew/test/cmd/home_spec.rb @@ -7,10 +7,10 @@ describe "brew home", :integration_test do end it "opens the homepage for a given Formula" do - setup_test_formula "testball" + setup_test_formula "testballhome" - expect { brew "home", "testball", "HOMEBREW_BROWSER" => "echo" } - .to output("#{Formula["testball"].homepage}\n").to_stdout + expect { brew "home", "testballhome", "HOMEBREW_BROWSER" => "echo" } + .to output("#{Formula["testballhome"].homepage}\n").to_stdout .and not_to_output.to_stderr .and be_a_success end diff --git a/Library/Homebrew/test/cmd/search_remote_tap_spec.rb b/Library/Homebrew/test/cmd/search_remote_tap_spec.rb index b0beb122c..eb256b924 100644 --- a/Library/Homebrew/test/cmd/search_remote_tap_spec.rb +++ b/Library/Homebrew/test/cmd/search_remote_tap_spec.rb @@ -2,6 +2,9 @@ require "cmd/search" describe Homebrew do specify "#search_taps" do + # Otherwise the tested method returns [], regardless of our stub + ENV.delete("HOMEBREW_NO_GITHUB_API") + json_response = { "items" => [ { diff --git a/Library/Homebrew/test/cmd/search_spec.rb b/Library/Homebrew/test/cmd/search_spec.rb index 06b7073d8..36ddde3e1 100644 --- a/Library/Homebrew/test/cmd/search_spec.rb +++ b/Library/Homebrew/test/cmd/search_spec.rb @@ -1,6 +1,7 @@ describe "brew search", :integration_test do before(:each) do setup_test_formula "testball" + setup_remote_tap "caskroom/cask" end it "lists all available Formulae when no argument is given" do @@ -13,7 +14,7 @@ describe "brew search", :integration_test do it "supports searching by name" do expect { brew "search", "testball" } .to output(/testball/).to_stdout - .and not_to_output.to_stderr + .and output(/Searching/).to_stderr .and be_a_success end @@ -24,6 +25,13 @@ describe "brew search", :integration_test do .and be_a_success end + it "falls back to a GitHub tap search when no formula is found", :needs_network do + expect { brew "search", "caskroom/cask/firefox" } + .to output(/firefox/).to_stdout + .and output(/Searching/).to_stderr + .and be_a_success + end + describe "--desc" do let(:desc_cache) { HOMEBREW_CACHE/"desc_cache.json" } @@ -44,8 +52,8 @@ describe "brew search", :integration_test do "fink" => "http://pdb.finkproject.org/pdb/browse.php?summary=testball", "debian" => "https://packages.debian.org/search?keywords=testball&searchon=names&suite=all§ion=all", "opensuse" => "https://software.opensuse.org/search?q=testball", - "fedora" => "https://admin.fedoraproject.org/pkgdb/packages/%2Atestball%2A/", - "ubuntu" => "http://packages.ubuntu.com/search?keywords=testball&searchon=names&suite=all§ion=all", + "fedora" => "https://apps.fedoraproject.org/packages/s/testball", + "ubuntu" => "https://packages.ubuntu.com/search?keywords=testball&searchon=names&suite=all§ion=all", }.each do |flag, url| specify "--#{flag}" do expect { brew "search", "--#{flag}", "testball", "HOMEBREW_BROWSER" => "echo" } diff --git a/Library/Homebrew/test/dependency_expansion_spec.rb b/Library/Homebrew/test/dependency_expansion_spec.rb index f955237a9..d6ecdf552 100644 --- a/Library/Homebrew/test/dependency_expansion_spec.rb +++ b/Library/Homebrew/test/dependency_expansion_spec.rb @@ -69,7 +69,7 @@ describe Dependency do end end - it "merges dependencies and perserves env_proc" do + it "merges dependencies and preserves env_proc" do env_proc = double dep = described_class.new("foo", [], env_proc) allow(dep).to receive(:to_formula).and_return(double(deps: [], name: "foo")) diff --git a/Library/Homebrew/test/dev-cmd/audit_spec.rb b/Library/Homebrew/test/dev-cmd/audit_spec.rb index 037865fdf..3e99bd06b 100644 --- a/Library/Homebrew/test/dev-cmd/audit_spec.rb +++ b/Library/Homebrew/test/dev-cmd/audit_spec.rb @@ -150,70 +150,6 @@ describe FormulaAuditor do end end - describe "#audit_class" do - specify "missing test" do - fa = formula_auditor "foo", <<-EOS.undent - class Foo < Formula - url "http://example.com/foo-1.0.tgz" - end - EOS - - fa.audit_class - expect(fa.problems).to eq([]) - - fa = formula_auditor "foo", <<-EOS.undent, strict: true - class Foo < Formula - url "http://example.com/foo-1.0.tgz" - end - EOS - - fa.audit_class - expect(fa.problems).to eq(["A `test do` test block should be added"]) - end - - specify "GithubGistFormula", :needs_compat do - ENV.delete("HOMEBREW_DEVELOPER") - - fa = formula_auditor "foo", <<-EOS.undent - class Foo < GithubGistFormula - url "http://example.com/foo-1.0.tgz" - end - EOS - - fa.audit_class - expect(fa.problems) - .to eq(["GithubGistFormula is deprecated, use Formula instead"]) - end - - specify "ScriptFileFormula", :needs_compat do - ENV.delete("HOMEBREW_DEVELOPER") - - fa = formula_auditor "foo", <<-EOS.undent - class Foo < ScriptFileFormula - url "http://example.com/foo-1.0.tgz" - end - EOS - - fa.audit_class - expect(fa.problems) - .to eq(["ScriptFileFormula is deprecated, use Formula instead"]) - end - - specify "AmazonWebServicesFormula", :needs_compat do - ENV.delete("HOMEBREW_DEVELOPER") - - fa = formula_auditor "foo", <<-EOS.undent - class Foo < AmazonWebServicesFormula - url "http://example.com/foo-1.0.tgz" - end - EOS - - fa.audit_class - expect(fa.problems) - .to eq(["AmazonWebServicesFormula is deprecated, use Formula instead"]) - end - end - describe "#line_problems" do specify "pkgshare" do fa = formula_auditor "foo", <<-EOS.undent, strict: true diff --git a/Library/Homebrew/test/download_strategies_spec.rb b/Library/Homebrew/test/download_strategies_spec.rb index 8c376a649..06d6fa855 100644 --- a/Library/Homebrew/test/download_strategies_spec.rb +++ b/Library/Homebrew/test/download_strategies_spec.rb @@ -200,6 +200,17 @@ describe GitDownloadStrategy do end end +describe CurlDownloadStrategy do + subject { described_class.new(name, resource) } + let(:name) { "foo" } + let(:url) { "http://example.com/foo.tar.gz" } + let(:resource) { double(Resource, url: url, mirrors: [], specs: { user: "download:123456" }, version: nil) } + + it "parses the opts and sets the corresponding args" do + expect(subject.send(:_curl_opts)).to eq(["--user", "download:123456"]) + end +end + describe DownloadStrategyDetector do describe "::detect" do subject { described_class.detect(url) } diff --git a/Library/Homebrew/test/exceptions_spec.rb b/Library/Homebrew/test/exceptions_spec.rb index 33547ea32..0a8313355 100644 --- a/Library/Homebrew/test/exceptions_spec.rb +++ b/Library/Homebrew/test/exceptions_spec.rb @@ -181,8 +181,8 @@ describe DuplicateResourceError do its(:to_s) { is_expected.to eq("Resource <resource foo> is defined more than once") } end -describe BottleVersionMismatchError do - subject { described_class.new("/foo.bottle.tar.gz", "1.0", formula, "1.1") } +describe BottleFormulaUnavailableError do + subject { described_class.new("/foo.bottle.tar.gz", "foo/1.0/.brew/foo.rb") } let(:formula) { double(Formula, full_name: "foo") } - its(:to_s) { is_expected.to match(/Bottle version mismatch/) } + its(:to_s) { is_expected.to match(/This bottle does not contain the formula file/) } end diff --git a/Library/Homebrew/test/formula_installer_spec.rb b/Library/Homebrew/test/formula_installer_spec.rb index 7365b2758..7b729312b 100644 --- a/Library/Homebrew/test/formula_installer_spec.rb +++ b/Library/Homebrew/test/formula_installer_spec.rb @@ -107,7 +107,7 @@ describe FormulaInstaller do end EOS - Formulary::FORMULAE.delete(dep_path) + Formulary.cache.delete(dep_path) dependency = Formulary.factory(dep_name) dependent = formula do diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index 234ebc93c..3180ad9a7 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -14,7 +14,7 @@ describe Formulary do bottle do cellar :any_skip_relocation root_url "file://#{bottle_dir}" - sha256 "9abc8ce779067e26556002c4ca6b9427b9874d25f0cafa7028e05b5c5c410cb4" => :#{Utils::Bottles.tag} + sha256 "d48bbbe583dcfbfa608579724fc6f0328b3cd316935c6ea22f134610aaf2952f" => :#{Utils::Bottles.tag} end def install diff --git a/Library/Homebrew/test/locale_spec.rb b/Library/Homebrew/test/locale_spec.rb index 9e4d09e83..9c684f0e7 100644 --- a/Library/Homebrew/test/locale_spec.rb +++ b/Library/Homebrew/test/locale_spec.rb @@ -9,6 +9,10 @@ describe Locale do expect(described_class.parse("zh-CN-Hans")).to eql(described_class.new("zh", "CN", "Hans")) end + it "correctly parses a string with a UN M.49 region code" do + expect(described_class.parse("es-419")).to eql(described_class.new("es", "419", nil)) + end + context "raises a ParserError when given" do it "an empty string" do expect { described_class.parse("") }.to raise_error(Locale::ParserError) diff --git a/Library/Homebrew/test/missing_formula_spec.rb b/Library/Homebrew/test/missing_formula_spec.rb index a48f12ecd..0a905004b 100644 --- a/Library/Homebrew/test/missing_formula_spec.rb +++ b/Library/Homebrew/test/missing_formula_spec.rb @@ -82,12 +82,6 @@ describe Homebrew::MissingFormula do it { is_expected.to be_blacklisted } end - context "clojure" do - subject { "clojure" } - - it { is_expected.to be_blacklisted } - end - context "gfortran" do subject { "gfortran" } diff --git a/Library/Homebrew/test/os/mac/diagnostic_spec.rb b/Library/Homebrew/test/os/mac/diagnostic_spec.rb index d6186e46b..83d95c2ef 100644 --- a/Library/Homebrew/test/os/mac/diagnostic_spec.rb +++ b/Library/Homebrew/test/os/mac/diagnostic_spec.rb @@ -47,15 +47,10 @@ describe Homebrew::Diagnostic::Checks do end specify "#check_ruby_version" do - allow(MacOS).to receive(:version).and_return(OS::Mac::Version.new("10.13")) - stub_const("RUBY_VERSION", "2.3.3p222") + allow(MacOS).to receive(:version).and_return(OS::Mac::Version.new("10.12")) + stub_const("RUBY_VERSION", "1.8.6") expect(subject.check_ruby_version) - .to match <<-EOS.undent - Ruby version 2.3.3p222 is unsupported on 10.13. Homebrew - is developed and tested on Ruby 2.0, and may not work correctly - on other Rubies. Patches are accepted as long as they don't cause breakage - on supported Rubies. - EOS + .to match "Ruby version 1.8.6 is unsupported on 10.12" end end diff --git a/Library/Homebrew/test/pathname_spec.rb b/Library/Homebrew/test/pathname_spec.rb index 0bc19c5ac..69314e5f4 100644 --- a/Library/Homebrew/test/pathname_spec.rb +++ b/Library/Homebrew/test/pathname_spec.rb @@ -295,7 +295,7 @@ describe FileUtils do let(:dst) { mktmpdir } describe "#mkdir" do - it "creates indermediate directories" do + it "creates intermediate directories" do described_class.mkdir dst/"foo/bar/baz" do expect(dst/"foo/bar/baz").to exist, "foo/bar/baz was not created" expect(dst/"foo/bar/baz").to be_a_directory, "foo/bar/baz was not a directory structure" diff --git a/Library/Homebrew/test/requirement_spec.rb b/Library/Homebrew/test/requirement_spec.rb index 71372aa69..11a3da8f4 100644 --- a/Library/Homebrew/test/requirement_spec.rb +++ b/Library/Homebrew/test/requirement_spec.rb @@ -48,7 +48,7 @@ describe Requirement do it { is_expected.to be_fatal } end - context "#fatal is ommitted" do + context "#fatal is omitted" do it { is_expected.not_to be_fatal } end end @@ -184,7 +184,7 @@ describe Requirement do it { is_expected.to have_a_default_formula } end - context "#default_formula ommitted" do + context "#default_formula omitted" do it { is_expected.not_to have_a_default_formula } end end diff --git a/Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb b/Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb index 563f7ad4b..b1afdc3f9 100644 --- a/Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb @@ -24,7 +24,7 @@ describe RuboCop::Cop::FormulaAuditStrict::BottleBlock do column: 4, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -60,7 +60,7 @@ describe RuboCop::Cop::FormulaAuditStrict::BottleBlock do end EOS - new_source = autocorrect_source(cop, source) + new_source = autocorrect_source(source) expect(new_source).to eq(corrected_source) end end diff --git a/Library/Homebrew/test/rubocops/caveats_cop_spec.rb b/Library/Homebrew/test/rubocops/caveats_cop_spec.rb index d44808a5d..4dbe65cfb 100644 --- a/Library/Homebrew/test/rubocops/caveats_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/caveats_cop_spec.rb @@ -25,7 +25,7 @@ describe RuboCop::Cop::FormulaAudit::Caveats do column: 5, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) diff --git a/Library/Homebrew/test/rubocops/checksum_cop_spec.rb b/Library/Homebrew/test/rubocops/checksum_cop_spec.rb index 644152c32..2f508bbf5 100644 --- a/Library/Homebrew/test/rubocops/checksum_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/checksum_cop_spec.rb @@ -34,7 +34,7 @@ describe RuboCop::Cop::FormulaAudit::Checksum do column: 14, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -68,7 +68,7 @@ describe RuboCop::Cop::FormulaAudit::Checksum do column: 14, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -102,7 +102,7 @@ describe RuboCop::Cop::FormulaAudit::Checksum do column: 31, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -142,7 +142,7 @@ describe RuboCop::Cop::FormulaAudit::ChecksumCase do column: 20, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -175,7 +175,7 @@ describe RuboCop::Cop::FormulaAudit::ChecksumCase do column: 12, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -215,7 +215,7 @@ describe RuboCop::Cop::FormulaAudit::ChecksumCase do end EOS - new_source = autocorrect_source(cop, source) + new_source = autocorrect_source(source) expect(new_source).to eq(corrected_source) end end diff --git a/Library/Homebrew/test/rubocops/class_cop_spec.rb b/Library/Homebrew/test/rubocops/class_cop_spec.rb new file mode 100644 index 000000000..59252587c --- /dev/null +++ b/Library/Homebrew/test/rubocops/class_cop_spec.rb @@ -0,0 +1,81 @@ +require "rubocop" +require "rubocop/rspec/support" +require_relative "../../extend/string" +require_relative "../../rubocops/class_cop" + +describe RuboCop::Cop::FormulaAudit::ClassName do + subject(:cop) { described_class.new } + + context "When auditing formula" do + it "with deprecated inheritance" do + formulas = [{ + "class" => "GithubGistFormula", + }, { + "class" => "ScriptFileFormula", + }, { + "class" => "AmazonWebServicesFormula", + }] + + formulas.each do |formula| + source = <<-EOS.undent + class Foo < #{formula["class"]} + url 'http://example.com/foo-1.0.tgz' + end + EOS + + expected_offenses = [{ message: "#{formula["class"]} is deprecated, use Formula instead", + severity: :convention, + line: 1, + column: 12, + source: source }] + + inspect_source(source) + + expected_offenses.zip(cop.offenses.reverse).each do |expected, actual| + expect_offense(expected, actual) + end + end + end + + it "with deprecated inheritance and autocorrect" do + source = <<-EOS.undent + class Foo < AmazonWebServicesFormula + url 'http://example.com/foo-1.0.tgz' + end + EOS + corrected_source = <<-EOS.undent + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + end + EOS + + new_source = autocorrect_source(source) + expect(new_source).to eq(corrected_source) + end + end +end + +describe RuboCop::Cop::FormulaAuditStrict::Test do + subject(:cop) { described_class.new } + + context "When auditing formula" do + it "without a test block" do + source = <<-EOS.undent + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + end + EOS + expected_offenses = [{ message: described_class::MSG, + severity: :convention, + line: 1, + column: 0, + source: source }] + + inspect_source(source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + 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 25467c635..f093f4927 100644 --- a/Library/Homebrew/test/rubocops/components_order_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/components_order_cop_spec.rb @@ -21,7 +21,7 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsOrder do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -47,7 +47,7 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsOrder do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -74,7 +74,7 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsOrder do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -99,7 +99,7 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsOrder do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -129,7 +129,7 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsOrder do end EOS - corrected_source = autocorrect_source(cop, source) + corrected_source = autocorrect_source(source) expect(corrected_source).to eq(correct_source) end @@ -156,7 +156,7 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsOrder do end end EOS - corrected_source = autocorrect_source(cop, source) + corrected_source = autocorrect_source(source) expect(corrected_source).to eq(correct_source) end end diff --git a/Library/Homebrew/test/rubocops/components_redundancy_cop_spec.rb b/Library/Homebrew/test/rubocops/components_redundancy_cop_spec.rb index fd635a126..9fbe15904 100644 --- a/Library/Homebrew/test/rubocops/components_redundancy_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/components_redundancy_cop_spec.rb @@ -23,7 +23,7 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsRedundancy do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -46,7 +46,7 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsRedundancy do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -70,7 +70,7 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsRedundancy do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) diff --git a/Library/Homebrew/test/rubocops/conflicts_cop_spec.rb b/Library/Homebrew/test/rubocops/conflicts_cop_spec.rb index 4fbab6c9e..8874ecc96 100644 --- a/Library/Homebrew/test/rubocops/conflicts_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/conflicts_cop_spec.rb @@ -22,7 +22,7 @@ describe RuboCop::Cop::FormulaAudit::Conflicts do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source, "/homebrew-core/Formula/foo@2.0.rb") expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -36,7 +36,7 @@ describe RuboCop::Cop::FormulaAudit::Conflicts do desc 'Bar' end EOS - inspect_source(cop, source) + inspect_source(source, "/homebrew-core/Formula/foo@2.0.rb") expect(cop.offenses).to eq([]) 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 74ce478fb..ac8893e18 100644 --- a/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb @@ -20,7 +20,7 @@ describe RuboCop::Cop::FormulaAuditStrict::DescLength do column: 0, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -37,7 +37,7 @@ describe RuboCop::Cop::FormulaAuditStrict::DescLength do msg = <<-EOS.undent Description is too long. "name: desc" should be less than 80 characters. - Length is calculated as Foo + desc. (currently 95) + Length is calculated as foo + desc. (currently 95) EOS expected_offenses = [{ message: msg, severity: :convention, @@ -45,7 +45,7 @@ describe RuboCop::Cop::FormulaAuditStrict::DescLength do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source, "/homebrew-core/Formula/foo.rb") expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end @@ -62,7 +62,7 @@ describe RuboCop::Cop::FormulaAuditStrict::DescLength do msg = <<-EOS.undent Description is too long. "name: desc" should be less than 80 characters. - Length is calculated as Foo + desc. (currently 98) + Length is calculated as foo + desc. (currently 98) EOS expected_offenses = [{ message: msg, severity: :convention, @@ -70,7 +70,7 @@ describe RuboCop::Cop::FormulaAuditStrict::DescLength do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source, "/homebrew-core/Formula/foo.rb") expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end @@ -96,7 +96,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do column: 8, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end @@ -116,7 +116,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do column: 8, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end @@ -136,7 +136,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do column: 8, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end @@ -156,7 +156,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do column: 8, source: source }] - inspect_source(cop, source) + inspect_source(source, "/homebrew-core/Formula/foo.rb") expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end @@ -176,7 +176,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do end EOS - corrected_source = autocorrect_source(cop, source) + corrected_source = autocorrect_source(source, "/homebrew-core/Formula/foo.rb") expect(corrected_source).to eq(correct_source) end end diff --git a/Library/Homebrew/test/rubocops/homepage_cop_spec.rb b/Library/Homebrew/test/rubocops/homepage_cop_spec.rb index c03efd825..6c7f248ba 100644 --- a/Library/Homebrew/test/rubocops/homepage_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/homepage_cop_spec.rb @@ -20,7 +20,7 @@ describe RuboCop::Cop::FormulaAudit::Homepage do column: 0, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -41,7 +41,7 @@ describe RuboCop::Cop::FormulaAudit::Homepage do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -72,7 +72,7 @@ describe RuboCop::Cop::FormulaAudit::Homepage do end EOS - inspect_source(cop, source) + inspect_source(source) if homepage =~ %r{http:\/\/www\.freedesktop\.org} if homepage =~ /Software/ expected_offenses = [{ message: "#{homepage} should be styled " \ diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 6f1f8a48c..962827ca3 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -42,7 +42,7 @@ describe RuboCop::Cop::FormulaAudit::Lines do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses.reverse).each do |expected, actual| expect_offense(expected, actual) @@ -50,12 +50,6 @@ describe RuboCop::Cop::FormulaAudit::Lines do 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 describe RuboCop::Cop::FormulaAudit::ClassInheritance do @@ -76,19 +70,13 @@ describe RuboCop::Cop::FormulaAudit::ClassInheritance do column: 10, source: source }] - inspect_source(cop, source) + inspect_source(source, '/homebrew-core/Formula/foo.rb') expected_offenses.zip(cop.offenses).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 describe RuboCop::Cop::FormulaAudit::Comments do @@ -104,13 +92,13 @@ describe RuboCop::Cop::FormulaAudit::Comments do end EOS - expected_offenses = [{ message: "Commented cmake call found", + expected_offenses = [{ message: "Please remove default template comments", severity: :convention, line: 4, column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -132,7 +120,7 @@ describe RuboCop::Cop::FormulaAudit::Comments do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -148,25 +136,19 @@ describe RuboCop::Cop::FormulaAudit::Comments do end EOS - expected_offenses = [{ message: 'Commented-out dep "foo"', + expected_offenses = [{ message: 'Commented-out dependency "foo"', severity: :convention, line: 4, column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).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 describe RuboCop::Cop::FormulaAudit::Miscellaneous do @@ -188,7 +170,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -212,7 +194,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -237,7 +219,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 4, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -264,7 +246,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 7, source: source }] - inspect_source(cop, source, "/homebrew-core/") + inspect_source(source, "/homebrew-core/") expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -292,7 +274,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -317,7 +299,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -342,7 +324,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -358,14 +340,16 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - expected_offenses = [{ message: "`skip_clean :all` is deprecated; brew no longer strips symbols\n" \ - "\tPass explicit paths to prevent Homebrew from removing empty folders.", + expected_offenses = [{ message: <<-EOS.undent.chomp, + `skip_clean :all` is deprecated; brew no longer strips symbols + Pass explicit paths to prevent Homebrew from removing empty folders. + EOS severity: :convention, line: 4, column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -383,19 +367,34 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - expected_offenses = [{ message: "macOS has been 64-bit only so build.universal? is deprecated.", + expected_offenses = [{ message: "macOS has been 64-bit only since 10.6 so build.universal? is deprecated.", severity: :convention, line: 4, column: 5, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end end + it "with build.universal? exempted formula" do + source = <<-EOS.undent + class Wine < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + if build.universal? + "foo" + end + end + EOS + + inspect_source(source, "/homebrew-core/Formula/wine.rb") + expect(cop.offenses).to eq([]) + end + it "with ENV.universal_binary" do source = <<-EOS.undent class Foo < Formula @@ -413,14 +412,14 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 5, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end end - it "with ENV.universal_binary" do + it "with ENV.universal_binary 2" do source = <<-EOS.undent class Foo < Formula desc "foo" @@ -437,7 +436,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 5, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -459,13 +458,26 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 10, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end end + it "with ruby-macho alternatives audit exempted formula" do + source = <<-EOS.undent + class Cctools < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + system "install_name_tool", "-id" + end + EOS + + inspect_source(source, "/homebrew-core/Formula/cctools.rb") + expect(cop.offenses).to eq([]) + end + it "with npm install without language::Node args" do source = <<-EOS.undent class Foo < Formula @@ -478,16 +490,29 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expected_offenses = [{ message: "Use Language::Node for npm install args", severity: :convention, line: 4, - column: 17, + column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end end + it "with npm install without language::Node args in kibana" do + source = <<-EOS.undent + class KibanaAT44 < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + system "npm", "install" + end + EOS + + inspect_source(source, "/homebrew-core/Formula/kibana@4.4.rb") + expect(cop.offenses).to eq([]) + end + it "with assert include" do source = <<-EOS.undent class Foo < Formula @@ -503,7 +528,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 9, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -525,12 +550,13 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 13, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end end + it "with old style OS check" do source = <<-EOS.undent class Foo < Formula @@ -546,7 +572,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 21, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -569,12 +595,13 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 13, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end end + it "with system call to fileUtils Method" do source = <<-EOS.undent class Foo < Formula @@ -590,12 +617,13 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 10, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end end + it "with a top-level function def " do source = <<-EOS.undent def test @@ -613,7 +641,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 0, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -637,7 +665,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 18, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -661,7 +689,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 18, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -685,7 +713,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 14, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -709,7 +737,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 14, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -733,7 +761,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 30, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -757,7 +785,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 27, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -781,7 +809,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 30, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -805,7 +833,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 30, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -829,7 +857,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 14, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -853,7 +881,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 22, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -877,7 +905,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 12, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -901,7 +929,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 12, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -925,7 +953,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 28, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -949,7 +977,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 28, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -973,7 +1001,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 17, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -997,7 +1025,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 18, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -1021,12 +1049,13 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 47, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end end + it "with formula path shortcut long form 3" do source = <<-EOS.undent class Foo < Formula @@ -1044,7 +1073,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 46, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -1066,7 +1095,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 24, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -1088,7 +1117,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 10, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -1110,7 +1139,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 13, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -1134,7 +1163,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 5, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -1158,7 +1187,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 4, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -1182,7 +1211,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 26, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -1206,7 +1235,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 14, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -1228,7 +1257,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -1250,7 +1279,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -1272,18 +1301,11 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).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 diff --git a/Library/Homebrew/test/rubocops/options_cop_spec.rb b/Library/Homebrew/test/rubocops/options_cop_spec.rb index b89b3d9b5..c27389a68 100644 --- a/Library/Homebrew/test/rubocops/options_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/options_cop_spec.rb @@ -21,7 +21,7 @@ describe RuboCop::Cop::FormulaAudit::Options do column: 10, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -48,7 +48,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Options do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -72,7 +72,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Options do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -95,7 +95,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Options do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -122,7 +122,7 @@ describe RuboCop::Cop::NewFormulaAudit::Options do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) diff --git a/Library/Homebrew/test/rubocops/patches_cop_spec.rb b/Library/Homebrew/test/rubocops/patches_cop_spec.rb index 4bd79bf35..4f9ca2df8 100644 --- a/Library/Homebrew/test/rubocops/patches_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/patches_cop_spec.rb @@ -13,7 +13,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do url 'http://example.com/foo-1.0.tgz' end EOS - inspect_source(cop, source) + inspect_source(source) expect(cop.offenses).to eq([]) end @@ -28,13 +28,13 @@ describe RuboCop::Cop::FormulaAudit::Patches do end EOS - expected_offenses = [{ message: "Use the patch DSL instead of defining a 'patches' method", - severity: :convention, - line: 4, - column: 2, - source: source }] + expected_offenses = [{ message: "Use the patch DSL instead of defining a 'patches' method", + severity: :convention, + line: 4, + column: 2, + source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -48,6 +48,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do "http://trac.macports.org/export/102865/trunk/dports/mail/uudeview/files/inews.c.patch", "http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=patch-libunac1.txt;att=1;bug=623340", "https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch", + "https://github.com/dlang/dub/pull/1221.patch", ] patch_urls.each do |patch_url| source = <<-EOS.undent @@ -60,42 +61,65 @@ describe RuboCop::Cop::FormulaAudit::Patches do end EOS - inspect_source(cop, source) - if patch_url =~ %r{/raw\.github\.com/} - expected_offenses = [{ message: "GitHub/Gist patches should specify a revision:\n#{patch_url}", - severity: :convention, - line: 5, - column: 12, - source: source }] + inspect_source(source) + expected_offense = if patch_url =~ %r{/raw\.github\.com/} + [{ message: <<-EOS.undent.chomp, + GitHub/Gist patches should specify a revision: + #{patch_url} + EOS + severity: :convention, + line: 5, + column: 12, + source: source }] elsif patch_url =~ %r{macports/trunk} - expected_offenses = [{ message: "MacPorts patches should specify a revision instead of trunk:\n#{patch_url}", - severity: :convention, - line: 5, - column: 33, - source: source }] + [{ message: <<-EOS.undent.chomp, + MacPorts patches should specify a revision instead of trunk: + #{patch_url} + EOS + severity: :convention, + line: 5, + column: 33, + source: source }] elsif patch_url =~ %r{^http://trac\.macports\.org} - expected_offenses = [{ message: "Patches from MacPorts Trac should be https://, not http:\n#{patch_url}", - severity: :convention, - line: 5, - column: 5, - source: source }] + [{ message: <<-EOS.undent.chomp, + Patches from MacPorts Trac should be https://, not http: + #{patch_url} + EOS + severity: :convention, + line: 5, + column: 5, + source: source }] elsif patch_url =~ %r{^http://bugs\.debian\.org} - expected_offenses = [{ message: "Patches from Debian should be https://, not http:\n#{patch_url}", - severity: :convention, - line: 5, - column: 5, - source: source }] + [{ message: <<-EOS.undent.chomp, + Patches from Debian should be https://, not http: + #{patch_url} + EOS + severity: :convention, + line: 5, + column: 5, + source: source }] elsif patch_url =~ %r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)} - expected_offenses = [{ message: "use GitHub pull request URLs:\n"\ - " https://github.com/foo/foo-bar/pull/100.patch\n"\ - "Rather than patch-diff:\n"\ - " https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch\n", - severity: :convention, - line: 5, - column: 5, - source: source }] + [{ message: <<-EOS.undent, + use GitHub pull request URLs: + https://github.com/foo/foo-bar/pull/100.patch + Rather than patch-diff: + https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch + EOS + severity: :convention, + line: 5, + column: 5, + source: source }] + elsif patch_url =~ %r{https?://github\.com/.+/.+/(?:commit|pull)/[a-fA-F0-9]*.(?:patch|diff)} + [{ message: <<-EOS.undent, + GitHub patches should use the full_index parameter: + #{patch_url}?full_index=1 + EOS + severity: :convention, + line: 5, + column: 5, + source: source }] end - expected_offenses.zip([cop.offenses.last]).each do |expected, actual| + expected_offense.zip([cop.offenses.last]).each do |expected, actual| expect_offense(expected, actual) end end @@ -116,19 +140,21 @@ describe RuboCop::Cop::FormulaAudit::Patches do end EOS - expected_offenses = [{ message: "Use the patch DSL instead of defining a 'patches' method", - severity: :convention, - line: 4, - column: 2, - source: source }, - { message: "Patches from MacPorts Trac should be https://, not http:\n"\ - "http://trac.macports.org/export/68507/trunk/dports/net/trafshow/files/", - severity: :convention, - line: 8, - column: 26, - source: source }] + expected_offenses = [{ message: "Use the patch DSL instead of defining a 'patches' method", + severity: :convention, + line: 4, + column: 2, + source: source }, + { message: <<-EOS.undent.chomp, + Patches from MacPorts Trac should be https://, not http: + http://trac.macports.org/export/68507/trunk/dports/net/trafshow/files/ + EOS + severity: :convention, + line: 8, + column: 26, + source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -157,42 +183,56 @@ describe RuboCop::Cop::FormulaAudit::Patches do end EOS - inspect_source(cop, source) - if patch_url =~ %r{/raw\.github\.com/} - expected_offenses = [{ message: "GitHub/Gist patches should specify a revision:\n#{patch_url}", - severity: :convention, - line: 5, - column: 16, - source: source }] + inspect_source(source) + expected_offense = if patch_url =~ %r{/raw\.github\.com/} + [{ message: <<-EOS.undent.chomp, + GitHub/Gist patches should specify a revision: + #{patch_url} + EOS + severity: :convention, + line: 5, + column: 16, + source: source }] elsif patch_url =~ %r{macports/trunk} - expected_offenses = [{ message: "MacPorts patches should specify a revision instead of trunk:\n#{patch_url}", - severity: :convention, - line: 5, - column: 37, - source: source }] + [{ message: <<-EOS.undent.chomp, + MacPorts patches should specify a revision instead of trunk: + #{patch_url} + EOS + severity: :convention, + line: 5, + column: 37, + source: source }] elsif patch_url =~ %r{^http://trac\.macports\.org} - expected_offenses = [{ message: "Patches from MacPorts Trac should be https://, not http:\n#{patch_url}", - severity: :convention, - line: 5, - column: 9, - source: source }] + [{ message: <<-EOS.undent.chomp, + Patches from MacPorts Trac should be https://, not http: + #{patch_url} + EOS + severity: :convention, + line: 5, + column: 9, + source: source }] elsif patch_url =~ %r{^http://bugs\.debian\.org} - expected_offenses = [{ message: "Patches from Debian should be https://, not http:\n#{patch_url}", - severity: :convention, - line: 5, - column: 9, - source: source }] + [{ message: <<-EOS.undent.chomp, + Patches from Debian should be https://, not http: + #{patch_url} + EOS + severity: :convention, + line: 5, + column: 9, + source: source }] elsif patch_url =~ %r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)} - expected_offenses = [{ message: "use GitHub pull request URLs:\n"\ - " https://github.com/foo/foo-bar/pull/100.patch\n"\ - "Rather than patch-diff:\n"\ - " https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch\n", - severity: :convention, - line: 5, - column: 9, - source: source }] + [{ message: <<-EOS.undent, + use GitHub pull request URLs: + https://github.com/foo/foo-bar/pull/100.patch + Rather than patch-diff: + https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch + EOS + severity: :convention, + line: 5, + column: 9, + source: source }] end - expected_offenses.zip([cop.offenses.last]).each do |expected, actual| + expected_offense.zip([cop.offenses.last]).each do |expected, actual| expect_offense(expected, actual) end end diff --git a/Library/Homebrew/test/rubocops/text_cop_spec.rb b/Library/Homebrew/test/rubocops/text_cop_spec.rb index b218e9c25..490801770 100644 --- a/Library/Homebrew/test/rubocops/text_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/text_cop_spec.rb @@ -7,6 +7,54 @@ describe RuboCop::Cop::FormulaAudit::Text do subject(:cop) { described_class.new } context "When auditing formula text" do + it "with both openssl and libressl optional dependencies" do + source = <<-EOS.undent + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + homepage "http://example.com" + + depends_on "openssl" + depends_on "libressl" => :optional + end + EOS + + expected_offenses = [{ message: "Formulae should not depend on both OpenSSL and LibreSSL (even optionally).", + severity: :convention, + line: 6, + column: 2, + source: source }] + + inspect_source(source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with both openssl and libressl dependencies" do + source = <<-EOS.undent + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + homepage "http://example.com" + + depends_on "openssl" + depends_on "libressl" + end + EOS + + expected_offenses = [{ message: "Formulae should not depend on both OpenSSL and LibreSSL (even optionally).", + severity: :convention, + line: 6, + column: 2, + source: source }] + + inspect_source(source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + it "When xcodebuild is called without SYMROOT" do source = <<-EOS.undent class Foo < Formula @@ -25,7 +73,7 @@ describe RuboCop::Cop::FormulaAudit::Text do column: 4, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -50,7 +98,7 @@ describe RuboCop::Cop::FormulaAudit::Text do column: 4, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -75,7 +123,7 @@ describe RuboCop::Cop::FormulaAudit::Text do column: 4, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -100,7 +148,7 @@ describe RuboCop::Cop::FormulaAudit::Text do column: 4, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -125,7 +173,7 @@ describe RuboCop::Cop::FormulaAudit::Text do column: 4, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -162,7 +210,7 @@ describe RuboCop::Cop::FormulaAudit::Text do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -189,7 +237,7 @@ describe RuboCop::Cop::FormulaAudit::Text do column: 0, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -219,7 +267,7 @@ describe RuboCop::Cop::FormulaAudit::Text do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -244,7 +292,7 @@ describe RuboCop::Cop::FormulaAudit::Text do column: 4, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) diff --git a/Library/Homebrew/test/rubocops/urls_cop_spec.rb b/Library/Homebrew/test/rubocops/urls_cop_spec.rb index 280da6314..ad939a1a2 100644 --- a/Library/Homebrew/test/rubocops/urls_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/urls_cop_spec.rb @@ -54,8 +54,10 @@ describe RuboCop::Cop::FormulaAudit::Urls do "col" => 2, }, { "url" => "http://prdownloads.sourceforge.net/foo/foo-1.tar.gz", - "msg" => "Don't use prdownloads in SourceForge urls (url is http://prdownloads.sourceforge.net/foo/foo-1.tar.gz).\n" \ - "\tSee: http://librelist.com/browser/homebrew/2011/1/12/prdownloads-is-bad/", + "msg" => <<-EOS.undent.chomp, + Don't use prdownloads in SourceForge urls (url is http://prdownloads.sourceforge.net/foo/foo-1.tar.gz). + See: http://librelist.com/browser/homebrew/2011/1/12/prdownloads-is-bad/ + EOS "col" => 2, }, { "url" => "http://foo.dl.sourceforge.net/sourceforge/foozip/foozip_1.0.tar.bz2", @@ -67,8 +69,11 @@ describe RuboCop::Cop::FormulaAudit::Urls do "col" => 2, }, { "url" => "http://http.debian.net/debian/dists/foo/", - "msg" => "Please use a secure mirror for Debian URLs.\nWe recommend:\n"\ - " https://mirrors.ocf.berkeley.edu/debian/dists/foo/\n", + "msg" => <<-EOS.undent, + Please use a secure mirror for Debian URLs. + We recommend: + https://mirrors.ocf.berkeley.edu/debian/dists/foo/ + EOS "col" => 2, }, { "url" => "http://foo.googlecode.com/files/foo-1.0.zip", @@ -96,8 +101,12 @@ describe RuboCop::Cop::FormulaAudit::Urls do "col" => 2, }, { "url" => "https://codeload.github.com/foo/bar/tar.gz/v0.1.1", - "msg" => "Use GitHub archive URLs:\n https://github.com/foo/bar/archive/v0.1.1.tar.gz\n"\ - "Rather than codeload:\n https://codeload.github.com/foo/bar/tar.gz/v0.1.1\n", + "msg" => <<-EOS.undent, + Use GitHub archive URLs: + https://github.com/foo/bar/archive/v0.1.1.tar.gz + Rather than codeload: + https://codeload.github.com/foo/bar/tar.gz/v0.1.1 + EOS "col" => 2, }, { "url" => "https://central.maven.org/maven2/com/bar/foo/1.1/foo-1.1.jar", @@ -117,7 +126,7 @@ describe RuboCop::Cop::FormulaAudit::Urls do column: formula["col"], source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses.reverse).each do |expected, actual| expect_offense(expected, actual) @@ -151,7 +160,7 @@ describe RuboCop::Cop::FormulaAudit::Urls do column: formula["col"], source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses.reverse).each do |expected, actual| expect_offense(expected, actual) @@ -174,7 +183,7 @@ describe RuboCop::Cop::FormulaAudit::Urls do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses.reverse).each do |expected, actual| expect_offense(expected, actual) @@ -213,13 +222,13 @@ describe RuboCop::Cop::FormulaAuditStrict::PyPiUrls do column: formula["col"], source: source }] - inspect_source(cop, source) + inspect_source(source) # Check for expected offenses expected_offenses.zip(cop.offenses.reverse).each do |expected, actual| expect_offense(expected, actual) end # Check for expected auto corrected source - new_source = autocorrect_source(cop, source) + new_source = autocorrect_source(source) expect(new_source).to eq(corrected_source) end end diff --git a/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.yosemite.bottle.tar.gz b/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.yosemite.bottle.tar.gz Binary files differindex d88838a94..62ea6c264 100644 --- a/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.yosemite.bottle.tar.gz +++ b/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.yosemite.bottle.tar.gz diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-conflicts-with.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-conflicts-with.rb index ab3631743..13d1fc4fc 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/with-conflicts-with.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-conflicts-with.rb @@ -5,7 +5,7 @@ cask 'with-conflicts-with' do url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip" homepage 'http://example.com/with-conflicts-with' - conflicts_with formula: 'unar' + conflicts_with cask: 'local-caffeine' app 'Caffeine.app' end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-languages.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-languages.rb new file mode 100644 index 000000000..90ff63846 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-languages.rb @@ -0,0 +1,18 @@ +cask 'with-languages' do + version '1.2.3' + + language "zh" do + sha256 "abc123" + "zh-CN" + end + + language "en-US", default: true do + sha256 "xyz789" + "en-US" + end + + url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip" + homepage 'http://example.com/local-caffeine' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/without-languages.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/without-languages.rb new file mode 100644 index 000000000..4c0ce955a --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/without-languages.rb @@ -0,0 +1,9 @@ +cask 'without-languages' do + version '1.2.3' + sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94' + + url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip" + homepage 'http://example.com/local-caffeine' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/test/support/fixtures/testball_bottle.rb b/Library/Homebrew/test/support/fixtures/testball_bottle.rb index 9453255e6..5a6be7c5f 100644 --- a/Library/Homebrew/test/support/fixtures/testball_bottle.rb +++ b/Library/Homebrew/test/support/fixtures/testball_bottle.rb @@ -6,7 +6,7 @@ class TestballBottle < Formula stable.bottle do cellar :any_skip_relocation root_url "file://#{TEST_FIXTURE_DIR}/bottles" - sha256 "9abc8ce779067e26556002c4ca6b9427b9874d25f0cafa7028e05b5c5c410cb4" => Utils::Bottles.tag + sha256 "d48bbbe583dcfbfa608579724fc6f0328b3cd316935c6ea22f134610aaf2952f" => Utils::Bottles.tag end cxxstdlib_check :skip end diff --git a/Library/Homebrew/test/support/fixtures/third-party/Casks/third-party-cask.rb b/Library/Homebrew/test/support/fixtures/third-party/Casks/third-party-cask.rb new file mode 100644 index 000000000..d7add0522 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/third-party/Casks/third-party-cask.rb @@ -0,0 +1,9 @@ +cask 'third-party-cask' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url 'http://example.com/ThirdParty.dmg' + homepage 'http://example.com/' + + app 'ThirdParty.app' +end diff --git a/Library/Homebrew/test/support/helper/fixtures.rb b/Library/Homebrew/test/support/helper/fixtures.rb index 716fe2008..460fb4aef 100644 --- a/Library/Homebrew/test/support/helper/fixtures.rb +++ b/Library/Homebrew/test/support/helper/fixtures.rb @@ -8,6 +8,10 @@ module Test def bundle_path(name) Pathname.new("#{TEST_FIXTURE_DIR}/mach/#{name}.bundle") end + + def cask_path(name) + Pathname.new("#{TEST_FIXTURE_DIR}/cask/Casks/#{name}.rb") + end end end end diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb b/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb index c51d339a7..fc83149d0 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb @@ -18,6 +18,7 @@ HOMEBREW_CASK_DIRS = [ RSpec.shared_context "Homebrew-Cask" do around(:each) do |example| + third_party_tap = Tap.fetch("third-party", "tap") begin dirs = HOMEBREW_CASK_DIRS.map do |dir| Pathname.new(TEST_TMPDIR).join("cask-#{dir}").tap do |path| @@ -31,11 +32,18 @@ RSpec.shared_context "Homebrew-Cask" do FileUtils.ln_sf TEST_FIXTURE_DIR.join("cask"), tap.path end + third_party_tap.tap do |tap| + FileUtils.mkdir_p tap.path.dirname + FileUtils.ln_sf TEST_FIXTURE_DIR.join("third-party"), tap.path + end + example.run ensure FileUtils.rm_rf dirs Hbc.default_tap.path.unlink FileUtils.rm_rf Hbc.default_tap.path.parent + third_party_tap.path.unlink + FileUtils.rm_rf third_party_tap.path.parent end end end diff --git a/Library/Homebrew/test/utils/analytics_spec.rb b/Library/Homebrew/test/utils/analytics_spec.rb new file mode 100644 index 000000000..bb6cda0b1 --- /dev/null +++ b/Library/Homebrew/test/utils/analytics_spec.rb @@ -0,0 +1,88 @@ +require "utils/analytics" +require "formula_installer" + +describe Utils::Analytics do + describe "::os_prefix_ci" do + context "when anonymous_os_prefix_ci is not set" do + before(:each) do + described_class.clear_anonymous_os_prefix_ci_cache + end + + it "returns OS_VERSION and prefix when HOMEBREW_PREFIX is not /usr/local" do + stub_const("HOMEBREW_PREFIX", "blah") + expect(described_class.os_prefix_ci).to include("#{OS_VERSION}, non-/usr/local") + end + + it "includes CI when ENV['CI'] is set" do + ENV["CI"] = "true" + expect(described_class.os_prefix_ci).to include("CI") + end + + it "does not include prefix when HOMEBREW_PREFIX is /usr/local" do + stub_const("HOMEBREW_PREFIX", "/usr/local") + expect(described_class.os_prefix_ci).not_to include("non-/usr/local") + end + end + end + + describe "::report_event" do + let(:f) { formula { url "foo-1.0" } } + let(:options) { FormulaInstaller.new(f).display_options(f) } + let(:action) { "#{f.full_name} #{options}".strip } + + context "when ENV vars is set" do + it "returns nil when HOMEBREW_NO_ANALYTICS is true" do + ENV["HOMEBREW_NO_ANALYTICS"] = "true" + expect(described_class.report_event("install", action)).to be_nil + end + + it "returns nil when HOMEBREW_NO_ANALYTICS_THIS_RUN is true" do + ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "true" + expect(described_class.report_event("install", action)).to be_nil + end + + it "returns nil when HOMEBREW_ANALYTICS_DEBUG is true" do + ENV.delete("HOMEBREW_NO_ANALYTICS_THIS_RUN") + ENV.delete("HOMEBREW_NO_ANALYTICS") + ENV["HOMEBREW_ANALYTICS_DEBUG"] = "true" + expect(described_class.report_event("install", action)).to be_nil + end + end + end + + describe "::report_build_error" do + context "when tap is installed" do + let(:err) { BuildError.new(f, "badprg", %w[arg1 arg2], {}) } + let(:f) { formula { url "foo-1.0" } } + + it "reports event if BuildError raised for a formula with a public remote repository" do + allow_any_instance_of(Tap).to receive(:custom_remote?).and_return(false) + expect(described_class).to respond_to(:report_event) + described_class.report_build_error(err) + end + + it "does not report event if BuildError raised for a formula with a private remote repository" do + expect(described_class.report_build_error(err)).to be_nil + end + end + + context "when formula does not have a tap" do + let(:err) { BuildError.new(f, "badprg", %w[arg1 arg2], {}) } + let(:f) { double(Formula, name: "foo", path: "blah", tap: nil) } + + it "does not report event if BuildError is raised" do + expect(described_class.report_build_error(err)).to be_nil + end + end + + context "when tap for a formula is not installed" do + let(:err) { BuildError.new(f, "badprg", %w[arg1 arg2], {}) } + let(:f) { double(Formula, name: "foo", path: "blah", tap: CoreTap.instance) } + + it "does not report event if BuildError is raised" do + allow_any_instance_of(Pathname).to receive(:directory?).and_return(false) + expect(described_class.report_build_error(err)).to be_nil + end + end + end +end diff --git a/Library/Homebrew/test/utils/git_spec.rb b/Library/Homebrew/test/utils/git_spec.rb new file mode 100644 index 000000000..48fc1338e --- /dev/null +++ b/Library/Homebrew/test/utils/git_spec.rb @@ -0,0 +1,150 @@ +require "utils/git" + +describe Git do + before(:each) do + git = HOMEBREW_SHIMS_PATH/"scm/git" + + HOMEBREW_CACHE.cd do + system git, "init" + + File.open(file, "w") { |f| f.write("blah") } + system git, "add", HOMEBREW_CACHE/file + system git, "commit", "-m", "'File added'" + @h1 = `git rev-parse HEAD` + + File.open(file, "w") { |f| f.write("brew") } + system git, "add", HOMEBREW_CACHE/file + system git, "commit", "-m", "'written to File'" + @h2 = `git rev-parse HEAD` + end + end + + let(:file) { "blah.rb" } + let(:hash1) { @h1[0..6] } + let(:hash2) { @h2[0..6] } + + describe "#last_revision_commit_of_file" do + it "gives last revision commit when before_commit is nil" do + expect( + described_class.last_revision_commit_of_file(HOMEBREW_CACHE, file), + ).to eq(hash1) + end + + it "gives revision commit based on before_commit when it is not nil" do + expect( + described_class.last_revision_commit_of_file(HOMEBREW_CACHE, + file, + before_commit: hash2), + ).to eq(hash2) + end + end + + describe "#last_revision_of_file" do + it "returns last revision of file" do + expect( + described_class.last_revision_of_file(HOMEBREW_CACHE, + HOMEBREW_CACHE/file), + ).to eq("blah") + end + + it "returns last revision of file based on before_commit" do + expect( + described_class.last_revision_of_file(HOMEBREW_CACHE, HOMEBREW_CACHE/file, + before_commit: "0..3"), + ).to eq("brew") + end + end +end + +describe Utils do + before(:each) do + described_class.clear_git_available_cache + end + + describe "::git_available?" do + it "returns true if git --version command succeeds" do + expect(described_class.git_available?).to be_truthy + end + + it "returns false if git --version command does not succeed" do + stub_const("HOMEBREW_SHIMS_PATH", HOMEBREW_PREFIX/"bin/shim") + expect(described_class.git_available?).to be_falsey + end + end + + describe "::git_path" do + it "returns nil when git is not available" do + stub_const("HOMEBREW_SHIMS_PATH", HOMEBREW_PREFIX/"bin/shim") + expect(described_class.git_path).to eq(nil) + end + + it "returns path of git when git is available" do + expect(described_class.git_path).to end_with("git") + end + end + + describe "::git_version" do + it "returns nil when git is not available" do + stub_const("HOMEBREW_SHIMS_PATH", HOMEBREW_PREFIX/"bin/shim") + expect(described_class.git_path).to eq(nil) + end + + it "returns version of git when git is available" do + expect(described_class.git_version).not_to be_nil + end + end + + describe "::ensure_git_installed!" do + it "returns nil if git already available" do + expect(described_class.ensure_git_installed!).to be_nil + end + + context "when git is not already available" do + before do + stub_const("HOMEBREW_SHIMS_PATH", HOMEBREW_PREFIX/"bin/shim") + end + + it "can't install brewed git if homebrew/core is unavailable" do + allow_any_instance_of(Pathname).to receive(:directory?).and_return(false) + expect { described_class.ensure_git_installed! }.to raise_error("Git is unavailable") + end + + it "raises error if can't install git" do + stub_const("HOMEBREW_BREW_FILE", HOMEBREW_PREFIX/"bin/brew") + expect { described_class.ensure_git_installed! }.to raise_error("Git is unavailable") + end + + it "installs git" do + allow(Homebrew).to receive(:_system).with(any_args).and_return(true) + described_class.ensure_git_installed! + end + end + end + + describe "::git_remote_exists" do + it "returns true when git is not available" do + stub_const("HOMEBREW_SHIMS_PATH", HOMEBREW_PREFIX/"bin/shim") + expect(described_class.git_remote_exists("blah")).to be_truthy + end + + context "when git is available" do + it "returns true when git remote exists", :needs_network do + git = HOMEBREW_SHIMS_PATH/"scm/git" + url = "https://github.com/Homebrew/homebrew.github.io" + repo = HOMEBREW_CACHE/"hey" + repo.mkpath + + repo.cd do + system git, "init" + system git, "remote", "add", "origin", url + end + + expect(described_class.git_remote_exists(url)).to be_truthy + end + + it "returns false when git remote does not exist" do + expect(described_class.git_remote_exists("blah")).to be_falsey + end + end + end +end diff --git a/Library/Homebrew/test/utils/github_spec.rb b/Library/Homebrew/test/utils/github_spec.rb index 9b539262f..a132894f9 100644 --- a/Library/Homebrew/test/utils/github_spec.rb +++ b/Library/Homebrew/test/utils/github_spec.rb @@ -2,12 +2,38 @@ require "utils/github" describe GitHub do describe "::search_code", :needs_network do - it "searches code" do - results = subject.search_code("repo:Homebrew/brew", "path:/", "filename:readme", "language:markdown") + it "queries GitHub code with the passed parameters" do + results = subject.search_code(repo: "Homebrew/brew", path: "/", + filename: "readme", language: "markdown") expect(results.count).to eq(1) expect(results.first["name"]).to eq("README.md") expect(results.first["path"]).to eq("README.md") end end + + describe "::query_string" do + it "builds a query with the given hash parameters formatted as key:value" do + query = subject.query_string(user: "Homebrew", repo: "brew") + expect(query).to eq("q=user%3AHomebrew+repo%3Abrew&per_page=100") + end + + it "adds a variable number of top-level string parameters to the query when provided" do + query = subject.query_string("value1", "value2", user: "Homebrew") + expect(query).to eq("q=value1+value2+user%3AHomebrew&per_page=100") + end + + it "turns array values into multiple key:value parameters" do + query = subject.query_string(user: ["Homebrew", "caskroom"]) + expect(query).to eq("q=user%3AHomebrew+user%3Acaskroom&per_page=100") + end + end + + describe "::search_issues", :needs_network do + it "queries GitHub issues with the passed parameters" do + results = subject.search_issues("brew search", repo: "Homebrew/brew", author: "avetamine", is: "closed") + expect(results).not_to be_empty + expect(results.last["title"]).to eq("brew search : 422 Unprocessable Entity") + end + end end diff --git a/Library/Homebrew/test/utils/svn_spec.rb b/Library/Homebrew/test/utils/svn_spec.rb new file mode 100644 index 000000000..4edb365a0 --- /dev/null +++ b/Library/Homebrew/test/utils/svn_spec.rb @@ -0,0 +1,39 @@ +require "utils/svn" + +describe Utils do + describe "#self.svn_available?" do + before(:each) do + described_class.clear_svn_version_cache + end + + it "returns svn version if svn available" do + expect(described_class.svn_available?).to be_truthy + end + end + + describe "#self.svn_remote_exists" do + it "returns true when svn is not available" do + allow(Utils).to receive(:svn_available?).and_return(false) + expect(described_class.svn_remote_exists("blah")).to be_truthy + end + + context "when svn is available" do + before do + allow(Utils).to receive(:svn_available?).and_return(true) + end + + it "returns false when remote does not exist" do + expect(described_class.svn_remote_exists(HOMEBREW_CACHE/"install")).to be_falsey + end + + it "returns true when remote exists", :needs_network do + remote = "http://github.com/Homebrew/install" + svn = HOMEBREW_SHIMS_PATH/"scm/svn" + + HOMEBREW_CACHE.cd { system svn, "checkout", remote } + + expect(described_class.svn_remote_exists(HOMEBREW_CACHE/"install")).to be_truthy + end + end + end +end diff --git a/Library/Homebrew/test/utils_spec.rb b/Library/Homebrew/test/utils_spec.rb index 37bd83c4f..3b5355b15 100644 --- a/Library/Homebrew/test/utils_spec.rb +++ b/Library/Homebrew/test/utils_spec.rb @@ -296,4 +296,33 @@ describe "globally-scoped helper methods" do expect(ENV["PATH"]).not_to eq("/bin") end end + + describe "#tap_and_name_comparison" do + describe "both strings are only names" do + it "alphabetizes the strings" do + expect(%w[a b].sort(&tap_and_name_comparison)).to eq(%w[a b]) + expect(%w[b a].sort(&tap_and_name_comparison)).to eq(%w[a b]) + end + end + + describe "both strings include tap" do + it "alphabetizes the strings" do + expect(%w[a/z/z b/z/z].sort(&tap_and_name_comparison)).to eq(%w[a/z/z b/z/z]) + expect(%w[b/z/z a/z/z].sort(&tap_and_name_comparison)).to eq(%w[a/z/z b/z/z]) + + expect(%w[z/a/z z/b/z].sort(&tap_and_name_comparison)).to eq(%w[z/a/z z/b/z]) + expect(%w[z/b/z z/a/z].sort(&tap_and_name_comparison)).to eq(%w[z/a/z z/b/z]) + + expect(%w[z/z/a z/z/b].sort(&tap_and_name_comparison)).to eq(%w[z/z/a z/z/b]) + expect(%w[z/z/b z/z/a].sort(&tap_and_name_comparison)).to eq(%w[z/z/a z/z/b]) + end + end + + describe "only one string includes tap" do + it "prefers the string without tap" do + expect(%w[a/z/z z].sort(&tap_and_name_comparison)).to eq(%w[z a/z/z]) + expect(%w[z a/z/z].sort(&tap_and_name_comparison)).to eq(%w[z a/z/z]) + end + end + end end diff --git a/Library/Homebrew/test/version_spec.rb b/Library/Homebrew/test/version_spec.rb index cee57e935..d0393afa6 100644 --- a/Library/Homebrew/test/version_spec.rb +++ b/Library/Homebrew/test/version_spec.rb @@ -241,8 +241,18 @@ describe Version do describe "::detect" do matcher :be_detected_from do |url, specs = {}| - match do |version| - Version.detect(url, specs) == version + detected = Version.detect(url, specs) + + match do |expected| + detected == expected + end + + failure_message do |expected| + message = <<-EOS + expected: %s + detected: %s + EOS + format(message, expected, detected) end end @@ -639,6 +649,11 @@ describe Version do .to be_detected_from("ftp://gcc.gnu.org/pub/gcc/snapshots/6-20151227/gcc-6-20151227.tar.bz2") end + specify "semver in middle of URL" do + expect(Version.create("7.1.10")) + .to be_detected_from("https://php.net/get/php-7.1.10.tar.gz/from/this/mirror") + end + specify "from URL" do expect(Version.create("1.2.3")) .to be_detected_from("http://github.com/foo/bar.git", tag: "v1.2.3") |
