repo
stringlengths
5
92
file_url
stringlengths
80
287
file_path
stringlengths
5
197
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:37:27
2026-01-04 17:58:21
truncated
bool
2 classes
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/services_spec.rb
Library/Homebrew/test/cmd/services_spec.rb
# frozen_string_literal: true require "cmd/services" require "cmd/shared_examples/args_parse" RSpec.describe Homebrew::Cmd::Services, :needs_daemon_manager do it_behaves_like "parseable arguments" it "allows controlling services", :integration_test do expect { brew "services", "list" } .to not_to_output.to_stderr .and not_to_output.to_stdout .and be_a_success end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/command-not-found-init_spec.rb
Library/Homebrew/test/cmd/command-not-found-init_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "cmd/command-not-found-init" RSpec.describe Homebrew::Cmd::CommandNotFoundInit do it_behaves_like "parseable arguments" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/fetch_spec.rb
Library/Homebrew/test/cmd/fetch_spec.rb
# frozen_string_literal: true require "cmd/fetch" require "cmd/shared_examples/args_parse" RSpec.describe Homebrew::Cmd::FetchCmd do it_behaves_like "parseable arguments" it "downloads the Formula's URL", :integration_test do setup_test_formula "testball" expect { brew "fetch", "testball" }.to be_a_success expect(HOMEBREW_CACHE/"testball--0.1.tbz").to be_a_symlink expect(HOMEBREW_CACHE/"testball--0.1.tbz").to exist end it "concurrently downloads formula URLs", :integration_test do setup_test_formula "testball1" setup_test_formula "testball2" expect { brew "fetch", "testball1", "testball2", "HOMEBREW_DOWNLOAD_CONCURRENCY" => "2" }.to be_a_success expect(HOMEBREW_CACHE/"testball1--0.1.tbz").to be_a_symlink expect(HOMEBREW_CACHE/"testball1--0.1.tbz").to exist expect(HOMEBREW_CACHE/"testball2--0.1.tbz").to be_a_symlink expect(HOMEBREW_CACHE/"testball2--0.1.tbz").to exist end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/upgrade_spec.rb
Library/Homebrew/test/cmd/upgrade_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "cmd/upgrade" require "cmd/shared_examples/reinstall_pkgconf_if_needed" RSpec.describe Homebrew::Cmd::UpgradeCmd do include FileUtils it_behaves_like "parseable arguments" it "upgrades a Formula", :integration_test do formula_name = "testball_bottle" formula_rack = HOMEBREW_CELLAR/formula_name setup_test_formula formula_name (formula_rack/"0.0.1/foo").mkpath expect { brew "upgrade" }.to be_a_success expect(formula_rack/"0.1").to be_a_directory expect(formula_rack/"0.0.1").not_to exist uninstall_test_formula formula_name # links newer version when upgrade was interrupted (formula_rack/"0.1/foo").mkpath expect { brew "upgrade" }.to be_a_success expect(formula_rack/"0.1").to be_a_directory expect(HOMEBREW_PREFIX/"opt/#{formula_name}").to be_a_symlink expect(HOMEBREW_PREFIX/"var/homebrew/linked/#{formula_name}").to be_a_symlink uninstall_test_formula formula_name # upgrades with asking for user prompts (formula_rack/"0.0.1/foo").mkpath expect { brew "upgrade", "--ask" } .to output(/.*Formula\s*\(1\):\s*#{formula_name}.*/).to_stdout .and output(/✔︎.*/m).to_stderr expect(formula_rack/"0.1").to be_a_directory expect(formula_rack/"0.0.1").not_to exist uninstall_test_formula formula_name # refuses to upgrade a forbidden formula (formula_rack/"0.0.1/foo").mkpath expect { brew "upgrade", formula_name, { "HOMEBREW_FORBIDDEN_FORMULAE" => formula_name } } .to not_to_output(%r{#{formula_rack}/0\.1}o).to_stdout .and output(/#{formula_name} was forbidden/).to_stderr .and be_a_failure expect(formula_rack/"0.1").not_to exist end it_behaves_like "reinstall_pkgconf_if_needed" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/commands_spec.rb
Library/Homebrew/test/cmd/commands_spec.rb
# frozen_string_literal: true require "cmd/commands" require "cmd/shared_examples/args_parse" RSpec.describe Homebrew::Cmd::CommandsCmd do it_behaves_like "parseable arguments" it "prints a list of all available commands", :integration_test do expect { brew "commands" } .to output(/Built-in commands/).to_stdout .and not_to_output.to_stderr .and be_a_success end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/list_spec.rb
Library/Homebrew/test/cmd/list_spec.rb
# frozen_string_literal: true require "cmd/list" require "cmd/shared_examples/args_parse" RSpec.describe Homebrew::Cmd::List do let(:formulae) { %w[bar foo qux] } it_behaves_like "parseable arguments" it "prints all installed formulae", :integration_test do formulae.each do |f| (HOMEBREW_CELLAR/f/"1.0/somedir").mkpath end expect { brew "list", "--formula" } .to output("#{formulae.join("\n")}\n").to_stdout .and not_to_output.to_stderr .and be_a_success end it "prints all installed formulae and casks", :integration_test do expect { brew_sh "list" } .to be_a_success .and not_to_output.to_stderr end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/docs_spec.rb
Library/Homebrew/test/cmd/docs_spec.rb
# frozen_string_literal: true require "cmd/docs" require "cmd/shared_examples/args_parse" RSpec.describe Homebrew::Cmd::Docs do it_behaves_like "parseable arguments" it "opens the docs page", :integration_test do expect { brew "docs", "HOMEBREW_BROWSER" => "echo" } .to output("https://docs.brew.sh\n").to_stdout .and not_to_output.to_stderr .and be_a_success end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/tap-info_spec.rb
Library/Homebrew/test/cmd/tap-info_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "cmd/tap-info" RSpec.describe Homebrew::Cmd::TapInfo do it_behaves_like "parseable arguments" it "gets information for a given Tap", :integration_test, :needs_network do setup_test_tap expect { brew "tap-info", "--json=v1", "--installed" } .to output(%r{https://github\.com/Homebrew/homebrew-foo}).to_stdout .and not_to_output.to_stderr .and be_a_success end it "display brief statistics for all installed taps", :integration_test, :needs_network do expect { brew "tap-info" } .to output(/\d+ taps?, \d+ private/).to_stdout .and not_to_output.to_stderr .and be_a_success end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/link_spec.rb
Library/Homebrew/test/cmd/link_spec.rb
# frozen_string_literal: true require "cmd/link" require "cmd/shared_examples/args_parse" RSpec.describe Homebrew::Cmd::Link do it_behaves_like "parseable arguments" it "links a given Formula", :integration_test do setup_test_formula "testball", tab_attributes: { installed_on_request: true } Formula["testball"].any_installed_keg.unlink Formula["testball"].bin.mkpath FileUtils.touch Formula["testball"].bin/"testfile" expect { brew "link", "testball" } .to output(/Linking/).to_stdout .and not_to_output.to_stderr .and be_a_success expect(HOMEBREW_PREFIX/"bin/testfile").to be_a_file end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/developer_spec.rb
Library/Homebrew/test/cmd/developer_spec.rb
# frozen_string_literal: true require "cmd/developer" require "cmd/shared_examples/args_parse" RSpec.describe Homebrew::Cmd::Developer do it_behaves_like "parseable arguments" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/casks_spec.rb
Library/Homebrew/test/cmd/casks_spec.rb
# frozen_string_literal: true RSpec.describe "brew casks", type: :system do it "prints all installed Casks", :integration_test do expect { brew_sh "casks" } .to be_a_success .and not_to_output.to_stderr end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/help_spec.rb
Library/Homebrew/test/cmd/help_spec.rb
# frozen_string_literal: true require "cmd/help" require "cmd/shared_examples/args_parse" RSpec.describe Homebrew::Cmd::HelpCmd, :integration_test do it_behaves_like "parseable arguments" describe "help" do it "prints help for a documented Ruby command" do expect { brew "help", "cat" } .to output(/^Usage: brew cat/).to_stdout .and not_to_output.to_stderr .and be_a_success end end describe "cat" do it "prints help when no argument is given" do expect { brew "cat" } .to output(/^Usage: brew cat/).to_stderr .and not_to_output.to_stdout .and be_a_failure end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/tap_spec.rb
Library/Homebrew/test/cmd/tap_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "cmd/tap" RSpec.describe Homebrew::Cmd::TapCmd do it_behaves_like "parseable arguments" it "taps a given Tap", :integration_test do path = setup_test_tap expect { brew "tap", "homebrew/bar", path/".git" } .to output(/Tapped/).to_stderr .and be_a_success end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/setup-ruby_spec.rb
Library/Homebrew/test/cmd/setup-ruby_spec.rb
# frozen_string_literal: true RSpec.describe "brew setup-ruby", type: :system do it "installs and configures Homebrew's Ruby", :integration_test do expect { brew_sh "setup-ruby" } .to output("").to_stdout .and not_to_output.to_stderr .and be_a_success end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/custom-external-command_spec.rb
Library/Homebrew/test/cmd/custom-external-command_spec.rb
# frozen_string_literal: true RSpec.describe "brew custom-external-command", :integration_test, type: :system do it "is supported" do mktmpdir do |path| cmd = "custom-external-command-#{rand}" file = path/"brew-#{cmd}" file.write <<~SH #!/bin/sh echo 'I am #{cmd}.' SH FileUtils.chmod "+x", file expect { brew cmd, "PATH" => "#{path}#{File::PATH_SEPARATOR}#{ENV.fetch("PATH")}" } .to output("I am #{cmd}.\n").to_stdout .and not_to_output.to_stderr .and be_a_success end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/update-report_spec.rb
Library/Homebrew/test/cmd/update-report_spec.rb
# frozen_string_literal: true require "cmd/update-report" require "formula_versions" require "yaml" require "cmd/shared_examples/args_parse" require "cmd/shared_examples/reinstall_pkgconf_if_needed" RSpec.describe Homebrew::Cmd::UpdateReport do it_behaves_like "parseable arguments" it_behaves_like "reinstall_pkgconf_if_needed" describe Reporter do let(:tap) { CoreTap.instance } let(:reporter_class) do Class.new(described_class) do def initialize(tap) @tap = tap ENV["HOMEBREW_UPDATE_BEFORE#{tap.repository_var_suffix}"] = "12345678" ENV["HOMEBREW_UPDATE_AFTER#{tap.repository_var_suffix}"] = "abcdef00" super end end end let(:reporter) { reporter_class.new(tap) } let(:hub) { ReporterHub.new } def perform_update(fixture_name = "") allow(Formulary).to receive(:factory).and_return(instance_double(Formula, pkg_version: "1.0")) allow(FormulaVersions).to receive(:new).and_return(instance_double(FormulaVersions, formula_at_revision: "2.0")) diff = YAML.load_file("#{TEST_FIXTURE_DIR}/updater_fixture.yaml")[fixture_name] allow(reporter).to receive(:diff).and_return(diff || "") hub.add(reporter) if reporter.updated? end specify "without revision variable" do ENV.delete_if { |k, _v| k.start_with? "HOMEBREW_UPDATE" } expect do described_class.new(tap) end.to raise_error(Reporter::ReporterRevisionUnsetError) end specify "without any changes" do perform_update expect(hub).to be_empty end specify "without Formula changes" do perform_update("update_git_diff_output_without_formulae_changes") expect(hub.select_formula_or_cask(:M)).to be_empty expect(hub.select_formula_or_cask(:A)).to be_empty expect(hub.select_formula_or_cask(:D)).to be_empty end specify "with Formula changes" do perform_update("update_git_diff_output_with_formulae_changes") expect(hub.select_formula_or_cask(:M)).to eq(%w[xar yajl]) expect(hub.select_formula_or_cask(:A)).to eq(%w[antiword bash-completion ddrescue dict lua]) end specify "with removed Formulae" do perform_update("update_git_diff_output_with_removed_formulae") expect(hub.select_formula_or_cask(:D)).to eq(%w[libgsasl]) end specify "with changed file type" do perform_update("update_git_diff_output_with_changed_filetype") expect(hub.select_formula_or_cask(:M)).to eq(%w[elixir]) expect(hub.select_formula_or_cask(:A)).to eq(%w[libbson]) expect(hub.select_formula_or_cask(:D)).to eq(%w[libgsasl]) end specify "with renamed Formula" do allow(tap).to receive(:formula_renames).and_return("cv" => "progress") perform_update("update_git_diff_output_with_formula_rename") expect(hub.select_formula_or_cask(:A)).to be_empty expect(hub.select_formula_or_cask(:D)).to be_empty expect(hub.instance_variable_get(:@hash)[:R]).to eq([["cv", "progress"]]) end context "when updating a Tap other than the core Tap" do let(:tap) { Tap.fetch("foo", "bar") } before do (tap.path/"Formula").mkpath end after do FileUtils.rm_r(tap.path.parent) end specify "with restructured Tap" do perform_update("update_git_diff_output_with_restructured_tap") expect(hub.select_formula_or_cask(:A)).to be_empty expect(hub.select_formula_or_cask(:D)).to be_empty expect(hub.instance_variable_get(:@hash)[:R]).to be_nil end specify "with renamed Formula and restructured Tap" do allow(tap).to receive(:formula_renames).and_return("xchat" => "xchat2") perform_update("update_git_diff_output_with_formula_rename_and_restructuring") expect(hub.select_formula_or_cask(:A)).to be_empty expect(hub.select_formula_or_cask(:D)).to be_empty expect(hub.instance_variable_get(:@hash)[:R]).to eq([%w[foo/bar/xchat foo/bar/xchat2]]) end specify "with simulated 'homebrew/php' restructuring" do perform_update("update_git_diff_simulate_homebrew_php_restructuring") expect(hub.select_formula_or_cask(:A)).to be_empty expect(hub.select_formula_or_cask(:D)).to be_empty expect(hub.instance_variable_get(:@hash)[:R]).to be_nil end specify "with Formula changes" do perform_update("update_git_diff_output_with_tap_formulae_changes") expect(hub.select_formula_or_cask(:A)).to eq(%w[foo/bar/lua]) expect(hub.select_formula_or_cask(:M)).to eq(%w[foo/bar/git]) expect(hub.instance_variable_get(:@hash)[:R]).to be_nil end specify "with formula migrated to cask in same tap" do # Setup a tap with both formulae and casks (tap.path/"Formula").mkpath (tap.path/"Casks").mkpath (tap.path/"tap_migrations.json").write <<~JSON { "old-formula": "foo/bar/new-cask" } JSON # Mock that the tap has a cask with the migration target name allow(tap).to receive(:cask_tokens).and_return(["new-cask"]) reporter_instance = reporter_class.new(tap) allow(reporter_instance).to receive(:report).and_return({ D: ["foo/bar/old-formula"] }) # Verify the migration would be detected as formula-to-cask migration expect(tap.tap_migrations).to eq({ "old-formula" => "foo/bar/new-cask" }) expect(tap.cask_tokens).to include("new-cask") end end describe "#diff" do context "when using the API" do subject(:reporter) do described_class.new(tap, api_names_txt: Pathname("formula_names.txt"), api_names_before_txt: Pathname("formula_names_before.txt"), api_dir_prefix: HOMEBREW_CACHE/"api") end it "ignore lines that haven't changed" do expect(Utils).to receive(:popen_read).and_return(<<~DIFF) foo +bar -baz DIFF expect(reporter.send(:diff)).to eq(<<~DIFF.strip) A api/bar.rb D api/baz.rb DIFF end it "handles moved lines" do expect(Utils).to receive(:popen_read).and_return(<<~DIFF) +baz foo +bar +baz -bar -baz DIFF expect(reporter.send(:diff)).to eq(<<~DIFF.strip) A api/baz.rb DIFF end end end end describe ReporterHub do let(:hub) { described_class.new } before do ENV["HOMEBREW_NO_COLOR"] = "1" allow(hub).to receive(:select_formula_or_cask).and_return([]) end it "dumps new formulae report" do allow(hub).to receive(:select_formula_or_cask).with(:A).and_return(["foo", "bar", "baz"]) allow(hub).to receive_messages(installed?: false, all_formula_json: [ { "name" => "foo", "desc" => "foobly things" }, { "name" => "baz", "desc" => "baz desc" }, ]) expect { hub.dump }.to output(<<~EOS).to_stdout ==> New Formulae bar baz: baz desc foo: foobly things EOS end it "dumps new casks report" do allow(hub).to receive(:select_formula_or_cask).with(:AC).and_return(["cask1", "cask2", "foo/tap/cask3"]) allow(hub).to receive_messages(cask_installed?: false, all_cask_json: [ { "token" => "cask1", "desc" => "desc1" }, { "token" => "cask3", "desc" => "desc3" }, ]) allow(Cask::Caskroom).to receive(:any_casks_installed?).and_return(true) expect { hub.dump }.to output(<<~EOS).to_stdout ==> New Casks cask1: desc1 cask2 cask3 EOS end it "dumps deleted installed formulae and casks report" do allow(hub).to receive(:select_formula_or_cask).with(:D).and_return(["baz", "foo", "bar"]) allow(hub).to receive(:installed?).with("baz").and_return(true) allow(hub).to receive(:installed?).with("foo").and_return(true) allow(hub).to receive(:installed?).with("bar").and_return(true) allow(hub).to receive(:select_formula_or_cask).with(:A).and_return([]) allow(hub).to receive(:select_formula_or_cask).with(:DC).and_return(["cask2", "cask1"]) allow(hub).to receive(:cask_installed?).with("cask1").and_return(true) allow(hub).to receive(:cask_installed?).with("cask2").and_return(true) allow(Homebrew::SimulateSystem).to receive(:simulating_or_running_on_linux?).and_return(false) expect { hub.dump }.to output(<<~EOS).to_stdout ==> Deleted Installed Formulae bar baz foo ==> Deleted Installed Casks cask1 cask2 EOS end it "dumps outdated formulae and casks report" do allow(Formula).to receive(:installed).and_return([ instance_double(Formula, name: "foo", outdated?: true), instance_double(Formula, name: "bar", outdated?: true), ]) allow(Cask::Caskroom).to receive(:casks).and_return([ instance_double(Cask::Cask, token: "baz", outdated?: true), instance_double(Cask::Cask, token: "qux", outdated?: true), ]) expect { hub.dump }.to output(<<~EOS).to_stdout ==> Outdated Formulae bar foo ==> Outdated Casks baz qux You have 2 outdated formulae and 2 outdated casks installed. You can upgrade them with brew upgrade or list them with brew outdated. EOS end it "prints nothing if there are no changes" do allow(Formula).to receive(:installed).and_return([]) allow(Cask::Caskroom).to receive(:casks).and_return([]) expect { hub.dump }.not_to output.to_stdout end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/shellenv_spec.rb
Library/Homebrew/test/cmd/shellenv_spec.rb
# frozen_string_literal: true RSpec.describe "brew shellenv", type: :system do it "prints export statements", :integration_test do expect { brew_sh "shellenv" } .to output(/.*/).to_stdout .and not_to_output.to_stderr .and be_a_success end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/cleanup_spec.rb
Library/Homebrew/test/cmd/cleanup_spec.rb
# frozen_string_literal: true require "cmd/cleanup" require "cmd/shared_examples/args_parse" RSpec.describe Homebrew::Cmd::CleanupCmd do before do FileUtils.mkdir_p HOMEBREW_LIBRARY/"Homebrew/vendor/" FileUtils.touch HOMEBREW_LIBRARY/"Homebrew/vendor/portable-ruby-version" end after do FileUtils.rm_rf HOMEBREW_LIBRARY/"Homebrew" end it_behaves_like "parseable arguments" describe "--prune=all", :integration_test do it "removes all files in Homebrew's cache" do (HOMEBREW_CACHE/"test").write "test" expect { brew "cleanup", "--prune=all" } .to output(%r{#{Regexp.escape(HOMEBREW_CACHE)}/test}o).to_stdout .and not_to_output.to_stderr .and be_a_success end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/readall_spec.rb
Library/Homebrew/test/cmd/readall_spec.rb
# frozen_string_literal: true require "cmd/readall" require "cmd/shared_examples/args_parse" RSpec.describe Homebrew::Cmd::ReadallCmd do it_behaves_like "parseable arguments" it "imports all Formulae for a given Tap", :integration_test do formula_file = setup_test_formula "testball" alias_file = CoreTap.instance.alias_dir/"foobar" alias_file.parent.mkpath FileUtils.ln_s formula_file, alias_file expect { brew "readall", "--aliases", "--syntax", CoreTap.instance.name } .to be_a_success .and not_to_output.to_stdout .and not_to_output.to_stderr end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/--env_spec.rb
Library/Homebrew/test/cmd/--env_spec.rb
# frozen_string_literal: true require "cmd/--env" require "cmd/shared_examples/args_parse" RSpec.describe Homebrew::Cmd::Env do it_behaves_like "parseable arguments" describe "--shell=bash", :integration_test do it "prints the Homebrew build environment variables in Bash syntax" do expect { brew "--env", "--shell=bash" } .to output(/export CMAKE_PREFIX_PATH="#{Regexp.quote(HOMEBREW_PREFIX)}"/).to_stdout .and not_to_output.to_stderr .and be_a_success end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/alias_spec.rb
Library/Homebrew/test/cmd/alias_spec.rb
# frozen_string_literal: true require "cmd/alias" require "cmd/shared_examples/args_parse" RSpec.describe Homebrew::Cmd::Alias do it_behaves_like "parseable arguments" it "sets an alias", :integration_test do expect { brew "alias", "foo-test=bar" } .to not_to_output.to_stdout .and not_to_output.to_stderr .and be_a_success expect { brew "alias" } .to output(/brew alias foo-test='bar'/).to_stdout .and not_to_output.to_stderr .and be_a_success end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/uninstall_spec.rb
Library/Homebrew/test/cmd/uninstall_spec.rb
# frozen_string_literal: true require "cmd/uninstall" require "cmd/shared_examples/args_parse" RSpec.describe Homebrew::Cmd::UninstallCmd do it_behaves_like "parseable arguments" it "uninstalls a given Formula", :integration_test do setup_test_formula "testball", tab_attributes: { installed_on_request: true } expect(HOMEBREW_CELLAR/"testball").to exist expect { brew "uninstall", "--force", "testball" } .to output(/Uninstalling testball/).to_stdout .and not_to_output.to_stderr .and be_a_success expect(HOMEBREW_CELLAR/"testball").not_to exist end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/log_spec.rb
Library/Homebrew/test/cmd/log_spec.rb
# frozen_string_literal: true require "cmd/log" require "cmd/shared_examples/args_parse" RSpec.describe Homebrew::Cmd::Log do it_behaves_like "parseable arguments" it "shows the Git log for a given Formula", :integration_test do setup_test_formula "testball" core_tap = CoreTap.instance core_tap.path.cd do system "git", "init" system "git", "add", "--all" system "git", "commit", "-m", "This is a test commit for Testball" end core_tap_url = "file://#{core_tap.path}" shallow_tap = Tap.fetch("homebrew", "shallow") system "git", "clone", "--depth=1", core_tap_url, shallow_tap.path expect { brew "log", "#{shallow_tap}/testball" } .to output(/This is a test commit for Testball/).to_stdout .and output(%r{Warning: homebrew/shallow is a shallow clone}).to_stderr .and be_a_success expect(shallow_tap.path/".git/shallow").to exist, "A shallow clone should have been created." end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/config_spec.rb
Library/Homebrew/test/cmd/config_spec.rb
# frozen_string_literal: true require "cmd/config" require "cmd/shared_examples/args_parse" RSpec.describe Homebrew::Cmd::Config do it_behaves_like "parseable arguments" it "prints information about the current Homebrew configuration", :integration_test do expect { brew "config" } .to output(/HOMEBREW_VERSION: #{Regexp.escape HOMEBREW_VERSION}/o).to_stdout .and not_to_output.to_stderr .and be_a_success end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/which-formula_spec.rb
Library/Homebrew/test/cmd/which-formula_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "cmd/which-formula" RSpec.describe Homebrew::Cmd::WhichFormula do it_behaves_like "parseable arguments" describe "which_formula" do before do # Override DATABASE_FILE to use test environment's HOMEBREW_CACHE test_db_file = HOMEBREW_CACHE/"api"/described_class::ENDPOINT stub_const("#{described_class}::DATABASE_FILE", test_db_file) db = described_class::DATABASE_FILE db.dirname.mkpath db.write(<<~EOS) foo(1.0.0):foo2 foo3 bar(1.2.3): baz(10.4):baz EOS end it "prints the formula name for a given binary", :integration_test do expect { brew_sh "which-formula", "--skip-update", "foo2" }.to output("foo\n").to_stdout expect { brew_sh "which-formula", "--skip-update", "baz" }.to output("baz\n").to_stdout expect { brew_sh "which-formula", "--skip-update", "bar" }.not_to output.to_stdout end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/postinstall_spec.rb
Library/Homebrew/test/cmd/postinstall_spec.rb
# frozen_string_literal: true require "cmd/postinstall" require "cmd/shared_examples/args_parse" RSpec.describe Homebrew::Cmd::Postinstall do it_behaves_like "parseable arguments" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/outdated_spec.rb
Library/Homebrew/test/cmd/outdated_spec.rb
# frozen_string_literal: true require "cmd/outdated" require "cmd/shared_examples/args_parse" RSpec.describe Homebrew::Cmd::Outdated do it_behaves_like "parseable arguments" it "outputs JSON", :integration_test do setup_test_formula "testball" (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath expected_json = JSON.pretty_generate({ formulae: [{ name: "testball", installed_versions: ["0.0.1"], current_version: "0.1", pinned: false, pinned_version: nil, }], casks: [], }) expect { brew "outdated", "--json=v2" } .to output("#{expected_json}\n").to_stdout .and be_a_success end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/unlink_spec.rb
Library/Homebrew/test/cmd/unlink_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "cmd/unlink" RSpec.describe Homebrew::Cmd::UnlinkCmd do it_behaves_like "parseable arguments" it "unlinks a Formula", :integration_test do install_test_formula "testball" expect { brew "unlink", "testball" } .to output(/Unlinking /).to_stdout .and not_to_output.to_stderr .and be_a_success end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/info_spec.rb
Library/Homebrew/test/cmd/info_spec.rb
# frozen_string_literal: true require "cmd/info" require "cmd/shared_examples/args_parse" RSpec.describe Homebrew::Cmd::Info do RSpec::Matchers.define :a_json_string do match do |actual| JSON.parse(actual) true rescue JSON::ParserError false end end it_behaves_like "parseable arguments" it "prints as json with the --json=v1 flag", :integration_test do setup_test_formula "testball" expect { brew "info", "testball", "--json=v1" } .to output(a_json_string).to_stdout .and not_to_output.to_stderr .and be_a_success end it "prints as json with the --json=v2 flag", :integration_test do setup_test_formula "testball" expect { brew "info", "testball", "--json=v2" } .to output(a_json_string).to_stdout .and not_to_output.to_stderr .and be_a_success end describe "::github_remote_path" do let(:remote) { "https://github.com/Homebrew/homebrew-core" } specify "returns correct URLs" do expect(described_class.new([]).github_remote_path(remote, "Formula/git.rb")) .to eq("https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/git.rb") expect(described_class.new([]).github_remote_path("#{remote}.git", "Formula/git.rb")) .to eq("https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/git.rb") expect(described_class.new([]).github_remote_path("git@github.com:user/repo", "foo.rb")) .to eq("https://github.com/user/repo/blob/HEAD/foo.rb") expect(described_class.new([]).github_remote_path("https://mywebsite.com", "foo/bar.rb")) .to eq("https://mywebsite.com/foo/bar.rb") end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/untap_spec.rb
Library/Homebrew/test/cmd/untap_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "cmd/untap" RSpec.describe Homebrew::Cmd::Untap do let(:class_instance) { described_class.new(%w[arg1]) } it_behaves_like "parseable arguments" it "untaps a given Tap", :integration_test do setup_test_tap expect { brew "untap", "homebrew/foo" } .to output(/Untapped/).to_stderr .and not_to_output.to_stdout .and be_a_success end describe "#installed_formulae_for", :integration_test do shared_examples "finds installed formulae in tap", :no_api do def load_formula(name:, with_formula_file: false, mock_install: false) formula = if with_formula_file path = setup_test_formula(name, tap:) Formulary.factory(path) else formula(name, tap:) do url "https://brew.sh/#{name}-1.0.tgz" end end if mock_install keg_path = HOMEBREW_CELLAR/name/"1.2.3" keg_path.mkpath tab_path = keg_path/AbstractTab::FILENAME tab_path.write <<~JSON { "source": { "tap": "#{tap}" } } JSON end formula end let!(:currently_installed_formula) do load_formula(name: "current_install", with_formula_file: true, mock_install: true) end before do # Formula that is available from a tap but not installed. load_formula(name: "no_install", with_formula_file: true) # Formula that was installed from a tap but is no longer available from that tap. load_formula(name: "legacy_install", mock_install: true) tap.clear_cache end it "returns the expected formulae" do expect(class_instance.installed_formulae_for(tap:).map(&:full_name)) .to eq([currently_installed_formula.full_name]) end end context "with core tap" do let(:tap) { CoreTap.instance } include_examples "finds installed formulae in tap" end context "with non-core tap" do let(:tap) { Tap.fetch("homebrew", "foo") } before do tap.formula_dir.mkpath end include_examples "finds installed formulae in tap" end end describe "#installed_casks_for", :cask do shared_examples "finds installed casks in tap", :no_api do def load_cask(token:, with_cask_file: false, mock_install: false) cask_loader = Cask::CaskLoader::FromContentLoader.new(<<~RUBY, tap:) cask '#{token}' do version "1.2.3" sha256 :no_check url 'https://brew.sh/' end RUBY cask = cask_loader.load(config: nil) if with_cask_file cask_path = tap.cask_dir/"#{token}.rb" cask_path.parent.mkpath cask_path.write cask.source end InstallHelper.install_with_caskfile(cask) if mock_install cask end let!(:currently_installed_cask) do load_cask(token: "current_install", with_cask_file: true, mock_install: true) end before do # Cask that is available from a tap but not installed. load_cask(token: "no_install", with_cask_file: true) # Cask that was installed from a tap but is no longer available from that tap. load_cask(token: "legacy_install", mock_install: true) end it "returns the expected casks" do expect(class_instance.installed_casks_for(tap:)).to eq([currently_installed_cask]) end end context "with core cask tap" do let(:tap) { CoreCaskTap.instance } include_examples "finds installed casks in tap" end context "with non-core cask tap" do let(:tap) { Tap.fetch("homebrew", "foo") } include_examples "finds installed casks in tap" end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/home_spec.rb
Library/Homebrew/test/cmd/home_spec.rb
# frozen_string_literal: true require "cmd/home" require "cmd/shared_examples/args_parse" RSpec.describe Homebrew::Cmd::Home do let(:testballhome_homepage) do Formula["testballhome"].homepage end let(:local_caffeine_path) do cask_path("local-caffeine") end let(:local_caffeine_homepage) do Cask::CaskLoader.load(local_caffeine_path).homepage end it_behaves_like "parseable arguments" it "opens the project page when no formula or cask is specified", :integration_test do expect { brew "home", "HOMEBREW_BROWSER" => "echo" } .to output("https://brew.sh\n").to_stdout .and not_to_output.to_stderr .and be_a_success end it "opens the homepage for a given Formula", :integration_test do setup_test_formula "testballhome" expect { brew "home", "testballhome", "HOMEBREW_BROWSER" => "echo" } .to output(/#{testballhome_homepage}/).to_stdout .and not_to_output.to_stderr .and be_a_success end it "opens the homepage for a given Cask", :integration_test, :needs_macos do expect { brew "home", local_caffeine_path, "HOMEBREW_BROWSER" => "echo" } .to output(/#{local_caffeine_homepage}/).to_stdout .and output(/Treating #{Regexp.escape(local_caffeine_path)} as a cask/).to_stderr .and be_a_success expect { brew "home", "--cask", local_caffeine_path, "HOMEBREW_BROWSER" => "echo" } .to output(/#{local_caffeine_homepage}/).to_stdout .and not_to_output.to_stderr .and be_a_success end it "opens the homepages for a given formula and Cask", :integration_test, :needs_macos do setup_test_formula "testballhome" expect { brew "home", "testballhome", local_caffeine_path, "HOMEBREW_BROWSER" => "echo" } .to output(/#{testballhome_homepage} #{local_caffeine_homepage}/).to_stdout .and output(/Treating #{Regexp.escape(local_caffeine_path)} as a cask/).to_stderr .and be_a_success end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/missing_spec.rb
Library/Homebrew/test/cmd/missing_spec.rb
# frozen_string_literal: true require "cmd/missing" require "cmd/shared_examples/args_parse" RSpec.describe Homebrew::Cmd::Missing do it_behaves_like "parseable arguments" it "prints missing dependencies", :integration_test, :no_api do setup_test_formula "foo" setup_test_formula "bar" (HOMEBREW_CELLAR/"bar/1.0").mkpath expect { brew "missing" } .to output("foo\n").to_stdout .and not_to_output.to_stderr .and be_a_failure end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/options_spec.rb
Library/Homebrew/test/cmd/options_spec.rb
# frozen_string_literal: true require "cmd/options" require "cmd/shared_examples/args_parse" RSpec.describe Homebrew::Cmd::OptionsCmd do it_behaves_like "parseable arguments" it "prints a given Formula's options", :integration_test do setup_test_formula "testball", <<~RUBY depends_on "bar" => :recommended RUBY expect { brew "options", "testball" } .to output("--with-foo\n\tBuild with foo\n--without-bar\n\tBuild without bar support\n\n").to_stdout .and not_to_output.to_stderr .and be_a_success end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/shared_examples/reinstall_pkgconf_if_needed.rb
Library/Homebrew/test/cmd/shared_examples/reinstall_pkgconf_if_needed.rb
# typed: false # frozen_string_literal: true require "reinstall" require "formula_installer" RSpec.shared_examples "reinstall_pkgconf_if_needed" do context "when running on macOS", :needs_macos do describe ".reinstall_pkgconf_if_needed!" do let(:formula) { instance_double(Formula) } let(:formula_installer) do instance_double(FormulaInstaller, formula:, prelude_fetch: true, prelude: true, fetch: true) end let(:context) { instance_double(Homebrew::Reinstall::InstallationContext, formula_installer:) } before do allow(OS).to receive(:mac?).and_return(true) allow(Formula).to receive(:[]).with("pkgconf").and_return(formula) allow(Homebrew::Install).to receive(:fetch_formulae).with([formula_installer]) allow(Homebrew::Reinstall).to receive(:build_install_context).and_return(context) end context "when there is no macOS SDK mismatch" do it "does nothing" do allow(Homebrew::Pkgconf).to receive(:macos_sdk_mismatch).and_return(nil) expect(Homebrew::Reinstall).not_to receive(:reinstall_formula) Homebrew::Reinstall.reinstall_pkgconf_if_needed! end end context "when dry_run is true" do it "prints a warning and does not reinstall" do allow(Homebrew::Pkgconf).to receive_messages( macos_sdk_mismatch: %w[13 14], mismatch_warning_message: "warning", ) expect(Homebrew::Reinstall).not_to receive(:reinstall_formula) expect(Homebrew::Reinstall).to receive(:opoo).with(/would be reinstalled/) Homebrew::Reinstall.reinstall_pkgconf_if_needed!(dry_run: true) end end context "when there is a mismatch and reinstall succeeds" do it "reinstalls pkgconf and prints success" do allow(Homebrew::Pkgconf).to receive(:macos_sdk_mismatch).and_return(%w[13 14]) expect(Homebrew::Reinstall).to receive(:reinstall_formula).with(context) expect(Homebrew::Reinstall).to receive(:ohai).with(/Reinstalled pkgconf/) allow(Homebrew::Reinstall).to receive(:restore_backup) Homebrew::Reinstall.reinstall_pkgconf_if_needed! end end context "when reinstall_formula raises an error" do it "rescues and prints the mismatch warning" do allow(Homebrew::Pkgconf).to receive_messages( macos_sdk_mismatch: %w[13 14], mismatch_warning_message: "warning", ) allow(Homebrew::Reinstall).to receive(:reinstall_formula).and_raise(RuntimeError) allow(Homebrew::Reinstall).to receive(:restore_backup) allow(Homebrew::Reinstall).to receive(:backup) expect(Homebrew::Reinstall).to receive(:ofail).with("warning") Homebrew::Reinstall.reinstall_pkgconf_if_needed! end end end end context "when on a non-macOS platform" do before do allow(OS).to receive(:mac?).and_return(false) end it "does nothing and does not crash" do expect(Homebrew::Reinstall).not_to receive(:reinstall_formula) expect { Homebrew::Reinstall.reinstall_pkgconf_if_needed! }.not_to raise_error end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/cmd/shared_examples/args_parse.rb
Library/Homebrew/test/cmd/shared_examples/args_parse.rb
# frozen_string_literal: true RSpec.shared_examples "parseable arguments" do |command_name: nil| let(:command) do |example| example.metadata.dig(:example_group, :parent_example_group, :description) end it "can parse arguments" do if described_class klass = described_class else # for tests of remote taps, we need to load the command class require(Commands.external_ruby_v2_cmd_path(command_name)) klass = Object.const_get(command) end argv = klass.parser.instance_variable_get(:@min_named_args)&.times&.map { "argument" } || [] cmd = klass.new(argv) expect(cmd.args).to be_a Homebrew::CLI::Args end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/livecheck_spec.rb
Library/Homebrew/test/livecheck/livecheck_spec.rb
# frozen_string_literal: true require "livecheck/livecheck" RSpec.describe Homebrew::Livecheck do subject(:livecheck) { described_class } let(:cask_url) { "https://brew.sh/test-0.0.1.dmg" } let(:head_url) { "https://github.com/Homebrew/brew.git" } let(:homepage_url) { "https://brew.sh" } let(:livecheck_url) { "https://formulae.brew.sh/api/formula/ruby.json" } let(:stable_url) { "https://brew.sh/test-0.0.1.tgz" } let(:resource_url) { "https://brew.sh/foo-1.0.tar.gz" } let(:f) do formula("test") do desc "Test formula" homepage "https://brew.sh" url "https://brew.sh/test-0.0.1.tgz" head "https://github.com/Homebrew/brew.git", branch: "main" livecheck do url "https://formulae.brew.sh/api/formula/ruby.json" regex(/"stable":"(\d+(?:\.\d+)+)"/i) end resource "foo" do url "https://brew.sh/foo-1.0.tar.gz" sha256 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" livecheck do url "https://brew.sh/test/releases" regex(/foo[._-]v?(\d+(?:\.\d+)+)\.t/i) end end end end let(:f_stable_url_only) do stable_url_s = stable_url formula("test_stable_url_only") do desc "Test formula with only a stable URL" url stable_url_s end end let(:r) { f.resources.first } let(:c) do Cask::CaskLoader.load(+<<-RUBY) cask "test" do version "0.0.1,2" url "https://brew.sh/test-0.0.1.dmg" name "Test" desc "Test cask" homepage "https://brew.sh" livecheck do url "https://formulae.brew.sh/api/formula/ruby.json" regex(/"stable":"(\d+(?:.\d+)+)"/i) end end RUBY end let(:c_no_checkable_urls) do Cask::CaskLoader.load(+<<-RUBY) cask "test_no_checkable_urls" do version "1.2.3" name "Test" desc "Test cask with no checkable URLs" end RUBY end describe "::livecheck_strategy_names" do context "when provided with a strategy class" do it "returns demodulized class name" do # We run this twice with the same argument to exercise the caching logic expect(livecheck.send(:livecheck_strategy_names, Homebrew::Livecheck::Strategy::PageMatch)).to eq("PageMatch") expect(livecheck.send(:livecheck_strategy_names, Homebrew::Livecheck::Strategy::PageMatch)).to eq("PageMatch") end end end describe "::livecheck_find_versions_parameters" do context "when provided with a strategy class" do it "returns demodulized class name" do page_match_parameters = T::Utils.signature_for_method( Homebrew::Livecheck::Strategy::PageMatch.method(:find_versions), ).parameters.map(&:second) # We run this twice with the same argument to exercise the caching logic expect(livecheck.send(:livecheck_find_versions_parameters, Homebrew::Livecheck::Strategy::PageMatch)) .to eq(page_match_parameters) expect(livecheck.send(:livecheck_find_versions_parameters, Homebrew::Livecheck::Strategy::PageMatch)) .to eq(page_match_parameters) end end end describe "::resolve_livecheck_reference" do context "when a formula/cask has a `livecheck` block without formula/cask methods" do it "returns [nil, []]" do expect(livecheck.resolve_livecheck_reference(f)).to eq([nil, []]) expect(livecheck.resolve_livecheck_reference(c)).to eq([nil, []]) end end end describe "::package_or_resource_name" do it "returns the name of a formula" do expect(livecheck.package_or_resource_name(f)).to eq("test") end it "returns the full name of a formula" do expect(livecheck.package_or_resource_name(f, full_name: true)).to eq("test") end it "returns the token of a cask" do expect(livecheck.package_or_resource_name(c)).to eq("test") end it "returns the full name of a cask" do expect(livecheck.package_or_resource_name(c, full_name: true)).to eq("test") end end describe "::status_hash" do it "returns a hash containing the livecheck status for a formula" do expect(livecheck.status_hash(f, "error", ["Unable to get versions"])) .to eq({ formula: "test", status: "error", messages: ["Unable to get versions"], meta: { livecheck_defined: true, }, }) end it "returns a hash containing the livecheck status for a resource" do expect(livecheck.status_hash(r, "error", ["Unable to get versions"])) .to eq({ resource: "foo", status: "error", messages: ["Unable to get versions"], meta: { livecheck_defined: true, }, }) end end describe "::livecheck_url_to_string" do let(:f_livecheck_url) do homepage_url_s = homepage_url stable_url_s = stable_url head_url_s = head_url resource_url_s = resource_url formula("test_livecheck_url") do desc "Test Livecheck URL formula" homepage homepage_url_s url stable_url_s head head_url_s resource "foo" do url resource_url_s sha256 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" livecheck do url "https://brew.sh/test/releases" regex(/foo[._-]v?(\d+(?:\.\d+)+)\.t/i) end end end end let(:r_livecheck_url) { f_livecheck_url.resources.first } let(:c_livecheck_url) do Cask::CaskLoader.load(+<<-RUBY) cask "test_livecheck_url" do version "0.0.1,2" url "https://brew.sh/test-0.0.1.dmg" name "Test" desc "Test Livecheck URL cask" homepage "https://brew.sh" end RUBY end it "returns a URL string when given a livecheck_url string for a formula" do expect(livecheck.livecheck_url_to_string(livecheck_url, f_livecheck_url)).to eq(livecheck_url) end it "returns a URL string when given a livecheck_url string for a resource" do expect(livecheck.livecheck_url_to_string(livecheck_url, r_livecheck_url)).to eq(livecheck_url) end it "returns a URL symbol when given a valid livecheck_url symbol" do expect(livecheck.livecheck_url_to_string(:head, f_livecheck_url)).to eq(head_url) expect(livecheck.livecheck_url_to_string(:homepage, f_livecheck_url)).to eq(homepage_url) expect(livecheck.livecheck_url_to_string(:homepage, c_livecheck_url)).to eq(homepage_url) expect(livecheck.livecheck_url_to_string(:stable, f_livecheck_url)).to eq(stable_url) expect(livecheck.livecheck_url_to_string(:url, c_livecheck_url)).to eq(cask_url) expect(livecheck.livecheck_url_to_string(:url, r_livecheck_url)).to eq(resource_url) end it "returns nil when not given a string or valid symbol" do error_text = "`url :%<symbol>s` does not reference a checkable URL" # Invalid symbol in any context expect { livecheck.livecheck_url_to_string(:invalid_symbol, f_livecheck_url) } .to raise_error(ArgumentError, format(error_text, symbol: :invalid_symbol)) expect { livecheck.livecheck_url_to_string(:invalid_symbol, c_livecheck_url) } .to raise_error(ArgumentError, format(error_text, symbol: :invalid_symbol)) expect { livecheck.livecheck_url_to_string(:invalid_symbol, r_livecheck_url) } .to raise_error(ArgumentError, format(error_text, symbol: :invalid_symbol)) # Valid symbol in provided context but referenced URL is not present expect { livecheck.livecheck_url_to_string(:head, f_stable_url_only) } .to raise_error(ArgumentError, format(error_text, symbol: :head)) expect { livecheck.livecheck_url_to_string(:homepage, f_stable_url_only) } .to raise_error(ArgumentError, format(error_text, symbol: :homepage)) expect { livecheck.livecheck_url_to_string(:homepage, c_no_checkable_urls) } .to raise_error(ArgumentError, format(error_text, symbol: :homepage)) expect { livecheck.livecheck_url_to_string(:url, c_no_checkable_urls) } .to raise_error(ArgumentError, format(error_text, symbol: :url)) # Valid symbol but not in the provided context expect { livecheck.livecheck_url_to_string(:head, c_livecheck_url) } .to raise_error(ArgumentError, format(error_text, symbol: :head)) expect { livecheck.livecheck_url_to_string(:homepage, r_livecheck_url) } .to raise_error(ArgumentError, format(error_text, symbol: :homepage)) expect { livecheck.livecheck_url_to_string(:stable, c_livecheck_url) } .to raise_error(ArgumentError, format(error_text, symbol: :stable)) expect { livecheck.livecheck_url_to_string(:url, f_livecheck_url) } .to raise_error(ArgumentError, format(error_text, symbol: :url)) end end describe "::checkable_urls" do let(:resource_url) { "https://brew.sh/foo-1.0.tar.gz" } let(:f_duplicate_urls) do formula("test_duplicate_urls") do desc "Test formula with a duplicate URL" homepage "https://github.com/Homebrew/brew.git" url "https://brew.sh/test-0.0.1.tgz" head "https://github.com/Homebrew/brew.git", branch: "main" end end it "returns the list of URLs to check" do expect(livecheck.checkable_urls(f)).to eq([stable_url, head_url, homepage_url]) expect(livecheck.checkable_urls(c)).to eq([cask_url, homepage_url]) expect(livecheck.checkable_urls(r)).to eq([resource_url]) expect(livecheck.checkable_urls(f_duplicate_urls)).to eq([stable_url, head_url]) expect(livecheck.checkable_urls(f_stable_url_only)).to eq([stable_url]) expect(livecheck.checkable_urls(c_no_checkable_urls)).to eq([]) end end describe "::use_homebrew_curl?" do let(:example_url) { "https://www.example.com/test-0.0.1.tgz" } let(:f_homebrew_curl) do formula("test") do desc "Test formula" homepage "https://brew.sh" url "https://brew.sh/test-0.0.1.tgz", using: :homebrew_curl # head is deliberably omitted to exercise more of the method livecheck do url "https://formulae.brew.sh/api/formula/ruby.json" regex(/"stable":"(\d+(?:\.\d+)+)"/i) end end end let(:c_homebrew_curl) do Cask::CaskLoader.load(+<<-RUBY) cask "test" do version "0.0.1,2" url "https://brew.sh/test-0.0.1.dmg", using: :homebrew_curl name "Test" desc "Test cask" homepage "https://brew.sh" livecheck do url "https://formulae.brew.sh/api/formula/ruby.json" regex(/"stable":"(\d+(?:.\d+)+)"/i) end end RUBY end it "returns `true` when URL matches a `using: :homebrew_curl` URL" do expect(livecheck.use_homebrew_curl?(f_homebrew_curl, livecheck_url)).to be(true) expect(livecheck.use_homebrew_curl?(f_homebrew_curl, homepage_url)).to be(true) expect(livecheck.use_homebrew_curl?(f_homebrew_curl, stable_url)).to be(true) expect(livecheck.use_homebrew_curl?(c_homebrew_curl, livecheck_url)).to be(true) expect(livecheck.use_homebrew_curl?(c_homebrew_curl, homepage_url)).to be(true) expect(livecheck.use_homebrew_curl?(c_homebrew_curl, cask_url)).to be(true) end it "returns `false` if URL root domain differs from `using: :homebrew_curl` URLs" do expect(livecheck.use_homebrew_curl?(f_homebrew_curl, example_url)).to be(false) expect(livecheck.use_homebrew_curl?(c_homebrew_curl, example_url)).to be(false) end it "returns `false` if a `using: homebrew_curl` URL is not present" do expect(livecheck.use_homebrew_curl?(f, livecheck_url)).to be(false) expect(livecheck.use_homebrew_curl?(f, homepage_url)).to be(false) expect(livecheck.use_homebrew_curl?(f, stable_url)).to be(false) expect(livecheck.use_homebrew_curl?(f, example_url)).to be(false) expect(livecheck.use_homebrew_curl?(c, livecheck_url)).to be(false) expect(livecheck.use_homebrew_curl?(c, homepage_url)).to be(false) expect(livecheck.use_homebrew_curl?(c, cask_url)).to be(false) expect(livecheck.use_homebrew_curl?(c, example_url)).to be(false) end it "returns `false` if URL string does not contain a domain" do expect(livecheck.use_homebrew_curl?(f_homebrew_curl, "test")).to be(false) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/skip_conditions_spec.rb
Library/Homebrew/test/livecheck/skip_conditions_spec.rb
# frozen_string_literal: true require "livecheck/livecheck" require "livecheck/skip_conditions" RSpec.describe Homebrew::Livecheck::SkipConditions do subject(:skip_conditions) { described_class } let(:formulae) do { basic: formula("test") do desc "Test formula" homepage "https://brew.sh" url "https://brew.sh/test-0.0.1.tgz" head "https://github.com/Homebrew/brew.git", branch: "main" livecheck do url "https://formulae.brew.sh/api/formula/ruby.json" regex(/"stable":"(\d+(?:\.\d+)+)"/i) end end, deprecated: formula("test_deprecated") do desc "Deprecated test formula" homepage "https://brew.sh" url "https://brew.sh/test-0.0.1.tgz" deprecate! date: "2020-06-25", because: :unmaintained end, disabled: formula("test_disabled") do desc "Disabled test formula" homepage "https://brew.sh" url "https://brew.sh/test-0.0.1.tgz" disable! date: "2020-06-25", because: :unmaintained end, head_only: formula("test_head_only") do desc "HEAD-only test formula" homepage "https://brew.sh" head "https://github.com/Homebrew/brew.git", branch: "main" end, gist: formula("test_gist") do desc "Gist test formula" homepage "https://brew.sh" url "https://gist.github.com/Homebrew/0000000000" end, google_code_archive: formula("test_google_code_archive") do desc "Google Code Archive test formula" homepage "https://brew.sh" url "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/brew/brew-1.0.0.tar.gz" end, internet_archive: formula("test_internet_archive") do desc "Internet Archive test formula" homepage "https://brew.sh" url "https://web.archive.org/web/20200101000000/https://brew.sh/test-0.0.1.tgz" end, skip: formula("test_skip") do desc "Skipped test formula" homepage "https://brew.sh" url "https://brew.sh/test-0.0.1.tgz" livecheck do skip end end, skip_with_message: formula("test_skip_with_message") do desc "Skipped test formula" homepage "https://brew.sh" url "https://brew.sh/test-0.0.1.tgz" livecheck do skip "Not maintained" end end, versioned: formula("test@0.0.1") do desc "Versioned test formula" homepage "https://brew.sh" url "https://brew.sh/test-0.0.1.tgz" end, } end let(:casks) do { basic: Cask::Cask.new("test") do version "0.0.1,2" url "https://brew.sh/test-#{version.csv.first}.tgz" name "Test" desc "Test cask" homepage "https://brew.sh" livecheck do url "https://formulae.brew.sh/api/formula/ruby.json" regex(/"stable":"(\d+(?:\.\d+)+)"/i) end end, deprecated: Cask::Cask.new("test_deprecated") do version "0.0.1" sha256 :no_check url "https://brew.sh/test-#{version}.tgz" name "Test Deprecate" desc "Deprecated test cask" homepage "https://brew.sh" deprecate! date: "2020-06-25", because: :discontinued end, disabled: Cask::Cask.new("test_disabled") do version "0.0.1" sha256 :no_check url "https://brew.sh/test-#{version}.tgz" name "Test Disable" desc "Disabled test cask" homepage "https://brew.sh" disable! date: "2020-06-25", because: :discontinued end, future_disable_fails_gatekeeper_check: Cask::Cask.new("test_future_disable_fails_gatekeeper_check") do version "0.0.1" url "https://brew.sh/test-#{version}.tgz" name "Test Future Disabled Fails Gatekeeper Check" desc "Future Disable Fails Gatekeeper Check test cask" homepage "https://brew.sh" disable! date: "3000-06-25", because: :fails_gatekeeper_check end, extract_plist: Cask::Cask.new("test_extract_plist_skip") do version "0.0.1" url "https://brew.sh/test-#{version}.tgz" name "Test ExtractPlist Skip" desc "Skipped test cask" homepage "https://brew.sh" livecheck do strategy :extract_plist end end, latest: Cask::Cask.new("test_latest") do version :latest sha256 :no_check url "https://brew.sh/test-0.0.1.tgz" name "Test Latest" desc "Latest test cask" homepage "https://brew.sh" end, unversioned: Cask::Cask.new("test_unversioned") do version "1.2.3" sha256 :no_check url "https://brew.sh/test.tgz" name "Test Unversioned" desc "Unversioned test cask" homepage "https://brew.sh" end, skip: Cask::Cask.new("test_skip") do version "0.0.1" url "https://brew.sh/test-#{version}.tgz" name "Test Skip" desc "Skipped test cask" homepage "https://brew.sh" livecheck do skip end end, skip_with_message: Cask::Cask.new("test_skip_with_message") do version "0.0.1" url "https://brew.sh/test-#{version}.tgz" name "Test Skip" desc "Skipped test cask" homepage "https://brew.sh" livecheck do skip "Not maintained" end end, } end let(:status_hashes) do { formula: { deprecated: { formula: "test_deprecated", status: "deprecated", meta: { livecheck_defined: false, }, }, disabled: { formula: "test_disabled", status: "disabled", meta: { livecheck_defined: false, }, }, versioned: { formula: "test@0.0.1", status: "versioned", meta: { livecheck_defined: false, }, }, head_only: { formula: "test_head_only", status: "error", messages: ["HEAD only formula must be installed to be checkable"], meta: { livecheck_defined: false, head_only: true, }, }, gist: { formula: "test_gist", status: "skipped", messages: ["Stable URL is a GitHub Gist"], meta: { livecheck_defined: false, }, }, google_code_archive: { formula: "test_google_code_archive", status: "skipped", messages: ["Stable URL is from Google Code Archive"], meta: { livecheck_defined: false, }, }, internet_archive: { formula: "test_internet_archive", status: "skipped", messages: ["Stable URL is from Internet Archive"], meta: { livecheck_defined: false, }, }, skip: { formula: "test_skip", status: "skipped", meta: { livecheck_defined: true, }, }, skip_with_message: { formula: "test_skip_with_message", status: "skipped", messages: ["Not maintained"], meta: { livecheck_defined: true, }, }, }, cask: { deprecated: { cask: "test_deprecated", status: "deprecated", meta: { livecheck_defined: false, }, }, disabled: { cask: "test_disabled", status: "disabled", meta: { livecheck_defined: false, }, }, extract_plist: { cask: "test_extract_plist_skip", status: "skipped", messages: ["Use `--extract-plist` to enable checking multiple casks with ExtractPlist strategy"], meta: { livecheck_defined: true, }, }, latest: { cask: "test_latest", status: "latest", meta: { livecheck_defined: false, }, }, unversioned: { cask: "test_unversioned", status: "unversioned", meta: { livecheck_defined: false, }, }, skip: { cask: "test_skip", status: "skipped", meta: { livecheck_defined: true, }, }, skip_with_message: { cask: "test_skip_with_message", status: "skipped", messages: ["Not maintained"], meta: { livecheck_defined: true, }, }, }, } end describe "::skip_information" do context "when a formula without a `livecheck` block is deprecated" do it "skips" do expect(skip_conditions.skip_information(formulae[:deprecated])) .to eq(status_hashes[:formula][:deprecated]) end end context "when a formula without a `livecheck` block is disabled" do it "skips" do expect(skip_conditions.skip_information(formulae[:disabled])) .to eq(status_hashes[:formula][:disabled]) end end context "when a formula without a `livecheck` block is versioned" do it "skips" do expect(skip_conditions.skip_information(formulae[:versioned])) .to eq(status_hashes[:formula][:versioned]) end end context "when a formula is HEAD-only and not installed" do it "skips" do expect(skip_conditions.skip_information(formulae[:head_only])) .to eq(status_hashes[:formula][:head_only]) end end context "when a formula without a `livecheck` block has a GitHub Gist stable URL" do it "skips" do expect(skip_conditions.skip_information(formulae[:gist])) .to eq(status_hashes[:formula][:gist]) end end context "when a formula without a `livecheck` block has a Google Code Archive stable URL" do it "skips" do expect(skip_conditions.skip_information(formulae[:google_code_archive])) .to eq(status_hashes[:formula][:google_code_archive]) end end context "when a formula without a `livecheck` block has an Internet Archive stable URL" do it "skips" do expect(skip_conditions.skip_information(formulae[:internet_archive])) .to eq(status_hashes[:formula][:internet_archive]) end end context "when a formula has a `livecheck` block containing `skip`" do it "skips" do expect(skip_conditions.skip_information(formulae[:skip])) .to eq(status_hashes[:formula][:skip]) expect(skip_conditions.skip_information(formulae[:skip_with_message])) .to eq(status_hashes[:formula][:skip_with_message]) end end context "when a cask without a `livecheck` block is deprecated" do it "skips" do expect(skip_conditions.skip_information(casks[:deprecated])) .to eq(status_hashes[:cask][:deprecated]) end end context "when a cask without a `livecheck` block is disabled" do it "skips" do expect(skip_conditions.skip_information(casks[:disabled])) .to eq(status_hashes[:cask][:disabled]) end end context "when a cask without a `livecheck` block is deprecated" \ "with a future disable date because `:fails_gatekeeper_check`" do it "does not skip" do expect(skip_conditions.skip_information(casks[:future_disable_fails_gatekeeper_check])).to eq({}) end end context "when a cask has a `livecheck` block using `ExtractPlist` and `--extract-plist` is not used" do it "skips" do expect(skip_conditions.skip_information(casks[:extract_plist], extract_plist: false)) .to eq(status_hashes[:cask][:extract_plist]) end end context "when a cask without a `livecheck` block has `version :latest`" do it "skips" do expect(skip_conditions.skip_information(casks[:latest])) .to eq(status_hashes[:cask][:latest]) end end context "when a cask without a `livecheck` block has an unversioned URL" do it "skips" do expect(skip_conditions.skip_information(casks[:unversioned])) .to eq(status_hashes[:cask][:unversioned]) end end context "when a cask has a `livecheck` block containing `skip`" do it "skips" do expect(skip_conditions.skip_information(casks[:skip])) .to eq(status_hashes[:cask][:skip]) expect(skip_conditions.skip_information(casks[:skip_with_message])) .to eq(status_hashes[:cask][:skip_with_message]) end end it "returns an empty hash for a non-skippable formula" do expect(skip_conditions.skip_information(formulae[:basic])).to eq({}) end it "returns an empty hash for a non-skippable cask" do expect(skip_conditions.skip_information(casks[:basic])).to eq({}) end end describe "::referenced_skip_information" do let(:original_name) { "original" } context "when a formula without a `livecheck` block is deprecated" do it "errors" do expect { skip_conditions.referenced_skip_information(formulae[:deprecated], original_name) } .to raise_error(RuntimeError, "Referenced formula (test_deprecated) is skipped as deprecated") end end context "when a formula without a `livecheck` block is disabled" do it "errors" do expect { skip_conditions.referenced_skip_information(formulae[:disabled], original_name) } .to raise_error(RuntimeError, "Referenced formula (test_disabled) is skipped as disabled") end end context "when a formula without a `livecheck` block is versioned" do it "errors" do expect { skip_conditions.referenced_skip_information(formulae[:versioned], original_name) } .to raise_error(RuntimeError, "Referenced formula (test@0.0.1) is skipped as versioned") end end context "when a formula is HEAD-only and not installed" do it "skips" do expect(skip_conditions.referenced_skip_information(formulae[:head_only], original_name)) .to eq(status_hashes[:formula][:head_only].merge({ formula: original_name })) end end context "when a formula without a `livecheck` block has a GitHub Gist stable URL" do it "errors" do expect { skip_conditions.referenced_skip_information(formulae[:gist], original_name) } .to raise_error(RuntimeError, "Referenced formula (test_gist) is automatically skipped") end end context "when a formula without a `livecheck` block has a Google Code Archive stable URL" do it "errors" do expect { skip_conditions.referenced_skip_information(formulae[:google_code_archive], original_name) } .to raise_error(RuntimeError, "Referenced formula (test_google_code_archive) is automatically skipped") end end context "when a formula without a `livecheck` block has an Internet Archive stable URL" do it "errors" do expect { skip_conditions.referenced_skip_information(formulae[:internet_archive], original_name) } .to raise_error(RuntimeError, "Referenced formula (test_internet_archive) is automatically skipped") end end context "when a formula has a `livecheck` block containing `skip`" do it "skips" do expect(skip_conditions.referenced_skip_information(formulae[:skip], original_name)) .to eq(status_hashes[:formula][:skip].merge({ formula: original_name })) expect(skip_conditions.referenced_skip_information(formulae[:skip_with_message], original_name)) .to eq(status_hashes[:formula][:skip_with_message].merge({ formula: original_name })) end end context "when a cask without a `livecheck` block is deprecated" do it "errors" do expect { skip_conditions.referenced_skip_information(casks[:deprecated], original_name) } .to raise_error(RuntimeError, "Referenced cask (test_deprecated) is skipped as deprecated") end end context "when a cask without a `livecheck` block is disabled" do it "errors" do expect { skip_conditions.referenced_skip_information(casks[:disabled], original_name) } .to raise_error(RuntimeError, "Referenced cask (test_disabled) is skipped as disabled") end end context "when a cask has a `livecheck` block using `ExtractPlist` and `--extract-plist` is not used" do it "skips" do expect do skip_conditions.referenced_skip_information(casks[:extract_plist], original_name, extract_plist: false) end .to raise_error(RuntimeError, "Referenced cask (test_extract_plist_skip) is automatically skipped") end end context "when a cask without a `livecheck` block has `version :latest`" do it "errors" do expect { skip_conditions.referenced_skip_information(casks[:latest], original_name) } .to raise_error(RuntimeError, "Referenced cask (test_latest) is skipped as latest") end end context "when a cask without a `livecheck` block has an unversioned URL" do it "errors" do expect { skip_conditions.referenced_skip_information(casks[:unversioned], original_name) } .to raise_error(RuntimeError, "Referenced cask (test_unversioned) is skipped as unversioned") end end context "when a cask has a `livecheck` block containing `skip`" do it "skips" do expect(skip_conditions.referenced_skip_information(casks[:skip], original_name)) .to eq(status_hashes[:cask][:skip].merge({ cask: original_name })) expect(skip_conditions.referenced_skip_information(casks[:skip_with_message], original_name)) .to eq(status_hashes[:cask][:skip_with_message].merge({ cask: original_name })) end end it "returns an empty hash for a non-skippable formula" do expect(skip_conditions.referenced_skip_information(formulae[:basic], original_name)).to be_nil end it "returns an empty hash for a non-skippable cask" do expect(skip_conditions.referenced_skip_information(casks[:basic], original_name)).to be_nil end end describe "::print_skip_information" do context "when a formula without a `livecheck` block is deprecated" do it "prints skip information" do expect { skip_conditions.print_skip_information(status_hashes[:formula][:deprecated]) } .to output("test_deprecated: deprecated\n").to_stdout .and not_to_output.to_stderr end end context "when a formula without a `livecheck` block is disabled" do it "prints skip information" do expect { skip_conditions.print_skip_information(status_hashes[:formula][:disabled]) } .to output("test_disabled: disabled\n").to_stdout .and not_to_output.to_stderr end end context "when a formula without a `livecheck` block is versioned" do it "prints skip information" do expect { skip_conditions.print_skip_information(status_hashes[:formula][:versioned]) } .to output("test@0.0.1: versioned\n").to_stdout .and not_to_output.to_stderr end end context "when a formula is HEAD-only and not installed" do it "prints skip information" do expect { skip_conditions.print_skip_information(status_hashes[:formula][:head_only]) } .to output("test_head_only: HEAD only formula must be installed to be checkable\n").to_stdout .and not_to_output.to_stderr end end context "when a formula has a GitHub Gist stable URL" do it "prints skip information" do expect { skip_conditions.print_skip_information(status_hashes[:formula][:gist]) } .to output("test_gist: skipped - Stable URL is a GitHub Gist\n").to_stdout .and not_to_output.to_stderr end end context "when a formula has a Google Code Archive stable URL" do it "prints skip information" do expect { skip_conditions.print_skip_information(status_hashes[:formula][:google_code_archive]) } .to output("test_google_code_archive: skipped - Stable URL is from Google Code Archive\n").to_stdout .and not_to_output.to_stderr end end context "when a formula has an Internet Archive stable URL" do it "prints skip information" do expect { skip_conditions.print_skip_information(status_hashes[:formula][:internet_archive]) } .to output("test_internet_archive: skipped - Stable URL is from Internet Archive\n").to_stdout .and not_to_output.to_stderr end end context "when a formula has a `livecheck` block containing `skip`" do it "prints skip information" do expect { skip_conditions.print_skip_information(status_hashes[:formula][:skip]) } .to output("test_skip: skipped\n").to_stdout .and not_to_output.to_stderr expect { skip_conditions.print_skip_information(status_hashes[:formula][:skip_with_message]) } .to output("test_skip_with_message: skipped - Not maintained\n").to_stdout .and not_to_output.to_stderr end end context "when the cask is deprecated without a `livecheck` block" do it "prints skip information" do expect { skip_conditions.print_skip_information(status_hashes[:cask][:deprecated]) } .to output("test_deprecated: deprecated\n").to_stdout .and not_to_output.to_stderr end end context "when the cask is disabled without a `livecheck` block" do it "prints skip information" do expect { skip_conditions.print_skip_information(status_hashes[:cask][:disabled]) } .to output("test_disabled: disabled\n").to_stdout .and not_to_output.to_stderr end end context "when the cask has `version :latest` without a `livecheck` block" do it "prints skip information" do expect { skip_conditions.print_skip_information(status_hashes[:cask][:latest]) } .to output("test_latest: latest\n").to_stdout .and not_to_output.to_stderr end end context "when the cask has an unversioned URL without a `livecheck` block" do it "prints skip information" do expect { skip_conditions.print_skip_information(status_hashes[:cask][:unversioned]) } .to output("test_unversioned: unversioned\n").to_stdout .and not_to_output.to_stderr end end context "when the cask has a `livecheck` block containing `skip`" do it "prints skip information" do expect { skip_conditions.print_skip_information(status_hashes[:cask][:skip]) } .to output("test_skip: skipped\n").to_stdout .and not_to_output.to_stderr expect { skip_conditions.print_skip_information(status_hashes[:cask][:skip_with_message]) } .to output("test_skip_with_message: skipped - Not maintained\n").to_stdout .and not_to_output.to_stderr end end context "with a blank parameter" do it "prints nothing" do expect { skip_conditions.print_skip_information({}) } .to not_to_output.to_stdout .and not_to_output.to_stderr end end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/strategy_spec.rb
Library/Homebrew/test/livecheck/strategy_spec.rb
# frozen_string_literal: true require "livecheck/strategy" RSpec.describe Homebrew::Livecheck::Strategy do subject(:strategy) { described_class } let(:url) { "https://brew.sh/" } let(:redirection_url) { "https://brew.sh/redirection" } let(:post_hash) do { empty: "", boolean: "true", number: "1", string: "a + b = c", } end let(:form_string) { "empty=&boolean=true&number=1&string=a+%2B+b+%3D+c" } let(:json_string) { '{"empty":"","boolean":"true","number":"1","string":"a + b = c"}' } let(:response_hash) do response_hash = {} response_hash[:ok] = { status_code: "200", status_text: "OK", headers: { "cache-control" => "max-age=604800", "content-type" => "text/html; charset=UTF-8", "date" => "Wed, 1 Jan 2020 01:23:45 GMT", "expires" => "Wed, 31 Jan 2020 01:23:45 GMT", "last-modified" => "Thu, 1 Jan 2019 01:23:45 GMT", "content-length" => "123", }, } response_hash[:redirection] = { status_code: "301", status_text: "Moved Permanently", headers: { "cache-control" => "max-age=604800", "content-type" => "text/html; charset=UTF-8", "date" => "Wed, 1 Jan 2020 01:23:45 GMT", "expires" => "Wed, 31 Jan 2020 01:23:45 GMT", "last-modified" => "Thu, 1 Jan 2019 01:23:45 GMT", "content-length" => "123", "location" => redirection_url, }, } response_hash end let(:body) do <<~HTML <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Thank you!</title> </head> <body> <h1>Download</h1> <p>This download link could have been made publicly available in a reasonable fashion but we appreciate that you jumped through the hoops that we carefully set up!: <a href="https://brew.sh/example-1.2.3.tar.gz">Example v1.2.3</a></p> <p>The current legacy version is: <a href="https://brew.sh/example-0.1.2.tar.gz">Example v0.1.2</a></p> </body> </html> HTML end let(:response_text) do response_text = {} response_text[:ok] = <<~EOS HTTP/1.1 #{response_hash[:ok][:status_code]} #{response_hash[:ok][:status_text]}\r Cache-Control: #{response_hash[:ok][:headers]["cache-control"]}\r Content-Type: #{response_hash[:ok][:headers]["content-type"]}\r Date: #{response_hash[:ok][:headers]["date"]}\r Expires: #{response_hash[:ok][:headers]["expires"]}\r Last-Modified: #{response_hash[:ok][:headers]["last-modified"]}\r Content-Length: #{response_hash[:ok][:headers]["content-length"]}\r \r #{body.rstrip} EOS response_text[:redirection_to_ok] = response_text[:ok].sub( "HTTP/1.1 #{response_hash[:ok][:status_code]} #{response_hash[:ok][:status_text]}\r", "HTTP/1.1 #{response_hash[:redirection][:status_code]} #{response_hash[:redirection][:status_text]}\r\n" \ "Location: #{response_hash[:redirection][:headers]["location"]}\r", ) response_text end describe "::from_symbol" do it "returns the Strategy module represented by the Symbol argument" do expect(strategy.from_symbol(:page_match)).to eq(Homebrew::Livecheck::Strategy::PageMatch) end it "returns `nil` if the argument is `nil`" do expect(strategy.from_symbol(nil)).to be_nil end end describe "::from_url" do let(:sourceforge_url) { "https://sourceforge.net/projects/test" } context "when a regex or `strategy` block is not provided" do it "returns an array of usable strategies which doesn't include PageMatch" do expect(strategy.from_url(sourceforge_url)).to eq([Homebrew::Livecheck::Strategy::Sourceforge]) end end context "when a regex or `strategy` block is provided" do it "returns an array of usable strategies including PageMatch, sorted in descending order by priority" do expect(strategy.from_url(sourceforge_url, regex_provided: true)) .to eq( [Homebrew::Livecheck::Strategy::Sourceforge, Homebrew::Livecheck::Strategy::PageMatch], ) end end context "when a `strategy` block is required and one is provided" do it "returns an array of usable strategies including the specified strategy" do # The strategies array is naturally in alphabetic order when all # applicable strategies have the same priority expect(strategy.from_url(url, livecheck_strategy: :json, block_provided: true)) .to eq([Homebrew::Livecheck::Strategy::Json, Homebrew::Livecheck::Strategy::PageMatch]) expect(strategy.from_url(url, livecheck_strategy: :xml, block_provided: true)) .to eq([Homebrew::Livecheck::Strategy::PageMatch, Homebrew::Livecheck::Strategy::Xml]) expect(strategy.from_url(url, livecheck_strategy: :yaml, block_provided: true)) .to eq([Homebrew::Livecheck::Strategy::PageMatch, Homebrew::Livecheck::Strategy::Yaml]) end end context "when a `strategy` block is required and one is not provided" do it "returns an array of usable strategies not including the specified strategy" do expect(strategy.from_url(url, livecheck_strategy: :json, block_provided: false)).to eq([]) expect(strategy.from_url(url, livecheck_strategy: :xml, block_provided: false)).to eq([]) expect(strategy.from_url(url, livecheck_strategy: :yaml, block_provided: false)).to eq([]) end end end describe "::post_args" do let(:form_string_content_length) { "Content-Length: #{form_string.length}" } let(:json_string_content_length) { "Content-Length: #{json_string.length}" } it "returns an array including `--data` and an encoded form data string" do expect(strategy.post_args(post_form: post_hash)) .to eq(["--data", form_string, "--header", form_string_content_length]) # If both `post_form` and `post_json` are present, only `post_form` will # be used. expect(strategy.post_args(post_form: post_hash, post_json: post_hash)) .to eq(["--data", form_string, "--header", form_string_content_length]) end it "returns an array including `--json` and a JSON string" do expect(strategy.post_args(post_json: post_hash)) .to eq(["--json", json_string, "--header", json_string_content_length]) end it "returns an empty array if `post_form` value is blank" do expect(strategy.post_args(post_form: {})).to eq([]) end it "returns an empty array if `post_json` value is blank" do expect(strategy.post_args(post_json: {})).to eq([]) end it "returns an empty array if hash argument doesn't have a `post_form` or `post_json` value" do expect(strategy.post_args).to eq([]) end end describe "::page_headers" do let(:responses) { [response_hash[:ok]] } it "returns headers from fetched content" do allow(strategy).to receive(:curl_headers).and_return({ responses:, body: }) expect(strategy.page_headers(url)).to eq([responses.first[:headers]]) end it "handles `cookies` `url` options" do allow(strategy).to receive(:curl_headers).and_return({ responses:, body: }) expect( strategy.page_headers( url, options: Homebrew::Livecheck::Options.new( cookies: { "cookie_key" => "cookie_value" }, ), ), ).to eq([responses.first[:headers]]) end it "handles `header` `url` options" do allow(strategy).to receive(:curl_headers).and_return({ responses:, body: }) expect( strategy.page_headers( url, options: Homebrew::Livecheck::Options.new(header: "Accept: */*"), ), ).to eq([responses.first[:headers]]) expect( strategy.page_headers( url, options: Homebrew::Livecheck::Options.new( header: ["Accept: */*", "X-Requested-With: XMLHttpRequest"], ), ), ).to eq([responses.first[:headers]]) end it "handles `post_form` `url` options" do allow(strategy).to receive(:curl_headers).and_return({ responses:, body: }) expect( strategy.page_headers( url, options: Homebrew::Livecheck::Options.new(post_form: post_hash), ), ).to eq([responses.first[:headers]]) end it "handles `post_json` `url` options" do allow(strategy).to receive(:curl_headers).and_return({ responses:, body: }) expect( strategy.page_headers( url, options: Homebrew::Livecheck::Options.new(post_json: post_hash), ), ).to eq([responses.first[:headers]]) end it "handles `referer` `url` option" do allow(strategy).to receive(:curl_headers).and_return({ responses:, body: }) expect( strategy.page_headers( url, options: Homebrew::Livecheck::Options.new(referer: "https://brew.sh/"), ), ).to eq([responses.first[:headers]]) end it "handles `user_agent` `url` option" do allow(strategy).to receive(:curl_headers).and_return({ responses:, body: }) expect( strategy.page_headers( url, options: Homebrew::Livecheck::Options.new(user_agent: :browser), ), ).to eq([responses.first[:headers]]) end it "returns an empty array if `curl_headers` only raises an `ErrorDuringExecution` error" do allow(strategy).to receive(:curl_headers).and_raise(ErrorDuringExecution.new([], status: 1)) expect(strategy.page_headers(url)).to eq([]) end end describe "::page_content" do let(:curl_version) { Version.new("8.7.1") } let(:success_status) { instance_double(Process::Status, success?: true, exitstatus: 0) } it "returns hash including fetched content" do allow_any_instance_of(Utils::Curl).to receive(:curl_version).and_return(curl_version) allow(strategy).to receive(:curl_output).and_return([response_text[:ok], nil, success_status]) expect(strategy.page_content(url)).to eq({ content: body }) end it "handles `cookies` `url` option" do allow_any_instance_of(Utils::Curl).to receive(:curl_version).and_return(curl_version) allow(strategy).to receive(:curl_output).and_return([response_text[:ok], nil, success_status]) expect( strategy.page_content( url, options: Homebrew::Livecheck::Options.new( cookies: { "cookie_key" => "cookie_value" }, ), ), ).to eq({ content: body }) end it "handles `header` `url` option" do allow_any_instance_of(Utils::Curl).to receive(:curl_version).and_return(curl_version) allow(strategy).to receive(:curl_output).and_return([response_text[:ok], nil, success_status]) expect( strategy.page_content( url, options: Homebrew::Livecheck::Options.new(header: "Accept: */*"), ), ).to eq({ content: body }) expect( strategy.page_content( url, options: Homebrew::Livecheck::Options.new( header: ["Accept: */*", "X-Requested-With: XMLHttpRequest"], ), ), ).to eq({ content: body }) end it "handles `post_form` `url` option" do allow_any_instance_of(Utils::Curl).to receive(:curl_version).and_return(curl_version) allow(strategy).to receive(:curl_output).and_return([response_text[:ok], nil, success_status]) expect( strategy.page_content( url, options: Homebrew::Livecheck::Options.new(post_form: post_hash), ), ).to eq({ content: body }) end it "handles `post_json` `url` option" do allow_any_instance_of(Utils::Curl).to receive(:curl_version).and_return(curl_version) allow(strategy).to receive(:curl_output).and_return([response_text[:ok], nil, success_status]) expect( strategy.page_content( url, options: Homebrew::Livecheck::Options.new(post_json: post_hash), ), ).to eq({ content: body }) end it "handles `referer` `url` option" do allow_any_instance_of(Utils::Curl).to receive(:curl_version).and_return(curl_version) allow(strategy).to receive(:curl_output).and_return([response_text[:ok], nil, success_status]) expect( strategy.page_content( url, options: Homebrew::Livecheck::Options.new(referer: "https://brew.sh/"), ), ).to eq({ content: body }) end it "handles `user_agent` `url` option" do allow_any_instance_of(Utils::Curl).to receive(:curl_version).and_return(curl_version) allow(strategy).to receive(:curl_output).and_return([response_text[:ok], nil, success_status]) expect( strategy.page_content( url, options: Homebrew::Livecheck::Options.new(user_agent: :browser), ), ).to eq({ content: body }) end it "returns error `messages` from `stderr` in the return hash on failure when `stderr` is not `nil`" do error_message = "curl: (6) Could not resolve host: brew.sh" allow_any_instance_of(Utils::Curl).to receive(:curl_version).and_return(curl_version) allow(strategy).to receive(:curl_output).and_return([ nil, error_message, instance_double(Process::Status, success?: false, exitstatus: 6), ]) expect(strategy.page_content(url)).to eq({ messages: [error_message] }) end it "returns default error `messages` in the return hash on failure when `stderr` is `nil`" do allow_any_instance_of(Utils::Curl).to receive(:curl_version).and_return(curl_version) allow(strategy).to receive(:curl_output).and_return([ nil, nil, instance_double(Process::Status, success?: false, exitstatus: 1), ]) expect(strategy.page_content(url)).to eq({ messages: ["cURL failed without a detectable error"] }) end it "returns hash including `final_url` if it differs from initial `url`" do allow_any_instance_of(Utils::Curl).to receive(:curl_version).and_return(curl_version) allow(strategy).to receive(:curl_output).and_return([response_text[:redirection_to_ok], nil, success_status]) expect(strategy.page_content(url)).to eq({ content: body, final_url: redirection_url }) end end describe "::handle_block_return" do it "returns an array of version strings when given a valid value" do expect(strategy.handle_block_return("1.2.3")).to eq(["1.2.3"]) expect(strategy.handle_block_return(["1.2.3", "1.2.4"])).to eq(["1.2.3", "1.2.4"]) end it "returns an empty array when given a nil value" do expect(strategy.handle_block_return(nil)).to eq([]) end it "errors when given an invalid value" do expect { strategy.handle_block_return(123) } .to raise_error(TypeError, strategy::INVALID_BLOCK_RETURN_VALUE_MSG) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/livecheck_version_spec.rb
Library/Homebrew/test/livecheck/livecheck_version_spec.rb
# frozen_string_literal: true require "livecheck/livecheck_version" RSpec.describe Homebrew::Livecheck::LivecheckVersion do let(:formula) { instance_double(Formula) } let(:cask) { instance_double(Cask::Cask) } let(:resource) { instance_double(Resource) } before do # Case statements use #=== for case equality purposes allow(Formula).to receive(:===).and_call_original allow(Formula).to receive(:===).with(formula).and_return(true) allow(Cask::Cask).to receive(:===).and_call_original allow(Cask::Cask).to receive(:===).with(cask).and_return(true) allow(Resource).to receive(:===).and_call_original allow(Resource).to receive(:===).with(resource).and_return(true) end specify "::create" do expect(described_class.create(formula, Version.new("1.1.6")).versions).to eq ["1.1.6"] expect(described_class.create(formula, Version.new("2.19.0,1.8.0")).versions).to eq ["2.19.0,1.8.0"] expect(described_class.create(formula, Version.new("0.17.0,20210111183933,226")).versions) .to eq ["0.17.0,20210111183933,226"] expect(described_class.create(cask, Version.new("1.1.6")).versions).to eq ["1.1.6"] expect(described_class.create(cask, Version.new("2.19.0,1.8.0")).versions).to eq ["2.19.0", "1.8.0"] expect(described_class.create(cask, Version.new("0.17.0,20210111183933,226")).versions) .to eq ["0.17.0", "20210111183933", "226"] expect(described_class.create(resource, Version.new("1.1.6")).versions).to eq ["1.1.6"] expect(described_class.create(resource, Version.new("2.19.0,1.8.0")).versions).to eq ["2.19.0,1.8.0"] expect(described_class.create(resource, Version.new("0.17.0,20210111183933,226")).versions) .to eq ["0.17.0,20210111183933,226"] end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/options_spec.rb
Library/Homebrew/test/livecheck/options_spec.rb
# frozen_string_literal: true require "livecheck/options" RSpec.describe Homebrew::Livecheck::Options do subject(:options) { described_class } let(:cookies) { { "cookie_key" => "cookie_value" } } let(:header_string) { "Accept: */*" } let(:referer_url) { "https://example.com/referer" } let(:post_hash) do { empty: "", boolean: "true", number: "1", string: "a + b = c", } end let(:args) do { cookies: cookies, header: header_string, homebrew_curl: true, post_form: post_hash, post_json: post_hash, referer: referer_url, user_agent: :browser, } end let(:other_args) do { post_form: { something: "else" }, } end let(:merged_hash) { args.merge(other_args) } let(:base_options) { options.new(**args) } let(:other_options) { options.new(**other_args) } let(:merged_options) { options.new(**merged_hash) } describe "#url_options" do it "returns a Hash of the options that are provided as arguments to the `url` DSL method" do expect(options.new.url_options).to eq({ cookies: nil, header: nil, homebrew_curl: nil, post_form: nil, post_json: nil, referer: nil, user_agent: nil, }) end end describe "#to_h" do it "returns a Hash of all instance variables" do # `T::Struct.serialize` omits `nil` values expect(options.new.to_h).to eq({}) expect(options.new(**args).to_h).to eq(args) end end describe "#to_hash" do it "returns a Hash of all instance variables, using String keys" do # `T::Struct.serialize` omits `nil` values expect(options.new.to_hash).to eq({}) expect(options.new(**args).to_hash).to eq(args.transform_keys(&:to_s)) end end describe "#merge" do it "returns an Options object with merged values" do expect(options.new(**args).merge(other_args)) .to eq(options.new(**merged_hash)) expect(options.new(**args).merge(options.new(**other_args))) .to eq(options.new(**merged_hash)) expect(options.new(**args).merge(args)) .to eq(options.new(**args)) expect(options.new(**args).merge({})) .to eq(options.new(**args)) end end describe "#merge!" do it "merges values from `other` into `self` and returns `self`" do o1 = options.new(**args) expect(o1.merge!(other_options)).to eq(merged_options) expect(o1).to eq(merged_options) o2 = options.new(**args) expect(o2.merge!(other_args)).to eq(merged_options) expect(o2).to eq(merged_options) o3 = options.new(**args) expect(o3.merge!(base_options)).to eq(base_options) expect(o3).to eq(base_options) o4 = options.new(**args) expect(o4.merge!(args)).to eq(base_options) expect(o4).to eq(base_options) o5 = options.new(**args) expect(o5.merge!(options.new)).to eq(base_options) expect(o5).to eq(base_options) o6 = options.new(**args) expect(o6.merge!({})).to eq(base_options) expect(o6).to eq(base_options) end it "skips over hash values without a corresponding Options value" do o1 = options.new(**args) expect(o1.merge!({ nonexistent: true })).to eq(base_options) expect(o1).to eq(base_options) end end describe "#==" do it "returns true if all instance variables are the same" do obj_with_args1 = options.new(**args) obj_with_args2 = options.new(**args) expect(obj_with_args1 == obj_with_args2).to be true default_obj1 = options.new default_obj2 = options.new expect(default_obj1 == default_obj2).to be true end it "returns false if any instance variables differ" do expect(options.new == options.new(**args)).to be false end it "returns false if other object is not the same class" do expect(options.new == :other).to be false end end describe "#empty?" do it "returns true if object has only default values" do expect(options.new.empty?).to be true end it "returns false if object has any non-default values" do # rubocop:todo RSpec/AggregateExamples expect(options.new(**args).empty?).to be false end end describe "#present?" do it "returns false if object has only default values" do expect(options.new.present?).to be false end it "returns true if object has any non-default values" do # rubocop:todo RSpec/AggregateExamples expect(options.new(**args).present?).to be true end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/strategy/npm_spec.rb
Library/Homebrew/test/livecheck/strategy/npm_spec.rb
# frozen_string_literal: true require "livecheck/strategy" RSpec.describe Homebrew::Livecheck::Strategy::Npm do subject(:npm) { described_class } let(:npm_urls) do { typical: "https://registry.npmjs.org/abc/-/def-1.2.3.tgz", org_scoped: "https://registry.npmjs.org/@example/abc/-/def-1.2.3.tgz", } end let(:non_npm_url) { "https://brew.sh/test" } let(:generated) do { typical: { url: "https://registry.npmjs.org/abc/latest", }, org_scoped: { url: "https://registry.npmjs.org/%40example%2Fabc/latest", }, } end # This is a limited subset of a `latest` response object, for the sake of # testing. let(:content) do <<~EOS { "name": "example", "version": "1.2.3" } EOS end let(:matches) { ["1.2.3"] } describe "::match?" do it "returns true for an npm URL" do expect(npm.match?(npm_urls[:typical])).to be true expect(npm.match?(npm_urls[:org_scoped])).to be true end it "returns false for a non-npm URL" do expect(npm.match?(non_npm_url)).to be false end end describe "::generate_input_values" do it "returns a hash containing url and regex for an npm URL" do expect(npm.generate_input_values(npm_urls[:typical])).to eq(generated[:typical]) expect(npm.generate_input_values(npm_urls[:org_scoped])).to eq(generated[:org_scoped]) end it "returns an empty hash for a non-npm URL" do expect(npm.generate_input_values(non_npm_url)).to eq({}) end end describe "::find_versions" do let(:match_data) do cached = { matches: matches.to_h { |v| [v, Version.new(v)] }, regex: nil, url: generated[:typical][:url], cached: true, } { cached:, cached_default: cached.merge({ matches: {} }), } end it "finds versions in provided content" do expect(npm.find_versions(url: npm_urls[:typical], provided_content: content)) .to eq(match_data[:cached]) end it "finds versions in provided content using a block" do # This `strategy` block is unnecessary but it's only intended to test # using a provided `strategy` block. expect(npm.find_versions(url: npm_urls[:typical], provided_content: content) do |json| json["version"] end).to eq(match_data[:cached]) end it "returns default match_data when block doesn't return version information" do expect(npm.find_versions(url: npm_urls[:typical], provided_content: content) do |json| json["nonexistentValue"] end).to eq(match_data[:cached_default]) end it "returns default match_data when url is blank" do expect(npm.find_versions(url: "") { "1.2.3" }) .to eq({ matches: {}, regex: nil, url: "" }) end it "returns default match_data when content is blank" do expect(npm.find_versions(url: npm_urls[:typical], provided_content: "")) .to eq(match_data[:cached_default]) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/strategy/electron_builder_spec.rb
Library/Homebrew/test/livecheck/strategy/electron_builder_spec.rb
# frozen_string_literal: true require "livecheck/strategy" RSpec.describe Homebrew::Livecheck::Strategy::ElectronBuilder do subject(:electron_builder) { described_class } let(:http_url) { "https://www.example.com/example/latest-mac.yml" } let(:non_http_url) { "ftp://brew.sh/" } let(:regex) { /Example[._-]v?(\d+(?:\.\d+)+)[._-]mac\.zip/i } let(:content) do <<~EOS version: 1.2.3 files: - url: Example-1.2.3-mac.zip sha512: MDXR0pxozBJjxxbtUQJOnhiaiiQkryLAwtcVjlnNiz30asm/PtSxlxWKFYN3kV/kl+jriInJrGypuzajTF6XIA== size: 92031237 blockMapSize: 96080 - url: Example-1.2.3.dmg sha512: k6WRDlZEfZGZHoOfUShpHxXZb5p44DRp+FAO2FXNx2kStZvyW9VuaoB7phPMfZpcMKrzfRfncpP8VEM8OB2y9g== size: 94972630 path: Example-1.2.3-mac.zip sha512: MDXR0pxozBJjxxbtUQJOnhiaiiQkryLAwtcVjlnNiz30asm/PtSxlxWKFYN3kV/kl+jriInJrGypuzajTF6XIA== releaseDate: '2000-01-01T00:00:00.000Z' EOS end let(:content_timestamp) do # An electron-builder YAML file may use a timestamp instead of an explicit # string value (with quotes) for `releaseDate`, so we need to make sure that # `ElectronBuilder#versions_from_content` won't encounter an error in this # scenario (e.g. `Tried to load unspecified class: Time`). content.sub(/releaseDate:\s*'([^']+)'/, 'releaseDate: \1') end let(:content_matches) { ["1.2.3"] } let(:find_versions_return_hash) do { matches: { "1.2.3" => Version.new("1.2.3"), }, regex: nil, url: http_url, } end let(:find_versions_cached_return_hash) do find_versions_return_hash.merge({ cached: true }) end describe "::match?" do it "returns true for a YAML file URL" do expect(electron_builder.match?(http_url)).to be true end it "returns false for non-YAML URL" do expect(electron_builder.match?(non_http_url)).to be false end end describe "::find_versions?" do it "finds versions in provided_content using a block" do expect(electron_builder.find_versions(url: http_url, provided_content: content)) .to eq(find_versions_cached_return_hash) expect(electron_builder.find_versions(url: http_url, regex:, provided_content: content) do |yaml, regex| yaml["path"][regex, 1] end).to eq(find_versions_cached_return_hash.merge({ regex: })) expect(electron_builder.find_versions( url: http_url, regex:, provided_content: content_timestamp, ) do |yaml, regex| yaml["path"][regex, 1] end).to eq(find_versions_cached_return_hash.merge({ regex: })) # NOTE: A regex should be provided using the `#regex` method in a # `livecheck` block but we're using a regex literal in the `strategy` # block here simply to ensure this method works as expected when a # regex isn't provided. expect(electron_builder.find_versions(url: http_url, provided_content: content) do |yaml| regex = /^v?(\d+(?:\.\d+)+)$/i yaml["version"][regex, 1] end).to eq(find_versions_cached_return_hash) end it "errors if a block is not provided" do expect { electron_builder.find_versions(url: http_url, regex:, provided_content: content) } .to raise_error(ArgumentError, "ElectronBuilder only supports a regex when using a `strategy` block") end it "returns default match_data when url is blank" do expect(electron_builder.find_versions(url: "") { "1.2.3" }) .to eq({ matches: {}, regex: nil, url: "" }) end it "returns default match_data when content is blank" do expect(electron_builder.find_versions(url: http_url, provided_content: "") { "1.2.3" }) .to eq({ matches: {}, regex: nil, url: http_url, cached: true }) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/strategy/extract_plist_spec.rb
Library/Homebrew/test/livecheck/strategy/extract_plist_spec.rb
# frozen_string_literal: true require "livecheck/strategy" require "bundle_version" RSpec.describe Homebrew::Livecheck::Strategy::ExtractPlist do subject(:extract_plist) { described_class } let(:http_url) { "https://brew.sh/blog/" } let(:non_http_url) { "ftp://brew.sh/" } let(:items) do { "first" => extract_plist::Item.new( bundle_version: Homebrew::BundleVersion.new(nil, "1.2"), ), "second" => extract_plist::Item.new( bundle_version: Homebrew::BundleVersion.new(nil, "1.2.3"), ), } end let(:multipart_items) do { "first" => extract_plist::Item.new( bundle_version: Homebrew::BundleVersion.new(nil, "1.2.3-45"), ), "second" => extract_plist::Item.new( bundle_version: Homebrew::BundleVersion.new(nil, "1.2.3-45-abcdef"), ), } end let(:multipart_regex) { /^v?(\d+(?:\.\d+)+)(?:[._-](\d+))?(?:[._-]([0-9a-f]+))?$/i } let(:versions) { ["1.2", "1.2.3"] } let(:multipart_versions) { ["1.2.3,45", "1.2.3,45,abcdef"] } describe "::match?" do it "returns true for an HTTP URL" do expect(extract_plist.match?(http_url)).to be true end it "returns false for a non-HTTP URL" do expect(extract_plist.match?(non_http_url)).to be false end end describe "::versions_from_items" do it "returns an empty array if Items hash is empty" do expect(extract_plist.versions_from_items({})).to eq([]) end it "returns an array of version strings when given Items" do expect(extract_plist.versions_from_items(items)).to eq(versions) end it "returns an array of version strings when given Items and a block" do # Returning a string from block expect( extract_plist.versions_from_items(items) do |items| items["first"].version end, ).to eq(["1.2"]) # Returning an array of strings from block expect( extract_plist.versions_from_items(items) do |items| items.map do |_key, item| item.bundle_version.nice_version end end, ).to eq(versions) end it "returns an array of version strings when given `Item`s, a regex and a block" do # Returning a string from block expect( extract_plist.versions_from_items(multipart_items, multipart_regex) do |items, regex| match = items["first"].version.match(regex) next if match.blank? match[1..].compact.join(",") end, ).to eq(["1.2.3,45"]) # Returning an array of strings from block expect( extract_plist.versions_from_items(multipart_items, multipart_regex) do |items, regex| items.map do |_key, item| match = item.version.match(regex) next if match.blank? match[1..].compact.join(",") end end, ).to eq(multipart_versions) end it "allows a nil return from a block" do expect(extract_plist.versions_from_items(items) { next }).to eq([]) end it "errors on an invalid return type from a block" do expect { extract_plist.versions_from_items(items) { 123 } } .to raise_error(TypeError, Homebrew::Livecheck::Strategy::INVALID_BLOCK_RETURN_VALUE_MSG) end end describe "::find_versions" do it "returns a for an installer artifact" do cask = Cask::CaskLoader.load(cask_path("livecheck/livecheck-installer-manual")) installer_artifact = cask.artifacts.first expect(installer_artifact).to be_a(Cask::Artifact::Installer) expect(installer_artifact.path).to be_a(Pathname) end it "uses the provided livecheck url", :needs_macos do cask = Cask::CaskLoader.load(cask_path("livecheck/livecheck-extract-plist")) livecheck_url = "file://#{TEST_FIXTURE_DIR}/cask/caffeine-with-plist.zip" expect(Homebrew::UnversionedCaskChecker).to receive(:new).with(cask).and_call_original result = described_class.find_versions(cask:, url: livecheck_url) expect(result) .to eq({ matches: { "1.2.3"=> @version="1.2.3" }, regex: nil, url: livecheck_url }) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/strategy/xml_spec.rb
Library/Homebrew/test/livecheck/strategy/xml_spec.rb
# frozen_string_literal: true require "livecheck/strategy" require "rexml/document" RSpec.describe Homebrew::Livecheck::Strategy::Xml do subject(:xml) { described_class } let(:http_url) { "https://brew.sh/blog/" } let(:non_http_url) { "ftp://brew.sh/" } let(:regex) { /^v?(\d+(?:\.\d+)+)$/i } let(:content_version_text) do <<~EOS <?xml version="1.0" encoding="utf-8"?> <versions> <version>1.1.2</version> <version>1.1.2b</version> <version>1.1.2a</version> <version>1.1.1</version> <version>1.1.0</version> <version>1.1.0-rc3</version> <version>1.1.0-rc2</version> <version>1.1.0-rc1</version> <version>1.0.x-last</version> <version>1.0.3</version> <version>1.0.3-rc3</version> <version>1.0.3-rc2</version> <version>1.0.3-rc1</version> <version>1.0.2</version> <version>1.0.2-rc1</version> <version>1.0.1</version> <version>1.0.1-rc1</version> <version>1.0.0</version> <version>1.0.0-rc1</version> </versions> EOS end let(:content_version_attr) do <<~EOS <?xml version="1.0" encoding="utf-8"?> <items> <item version="1.1.2" /> <item version="1.1.2b" /> <item version="1.1.2a" /> <item version="1.1.1" /> <item version="1.1.0" /> <item version="1.1.0-rc3" /> <item version="1.1.0-rc2" /> <item version="1.1.0-rc1" /> <item version="1.0.x-last" /> <item version="1.0.3" /> <item version="1.0.3-rc3" /> <item version="1.0.3-rc2" /> <item version="1.0.3-rc1" /> <item version="1.0.2" /> <item version="1.0.2-rc1" /> <item version="1.0.1" /> <item version="1.0.1-rc1" /> <item version="1.0.0" /> <item version="1.0.0-rc1" /> </items> EOS end let(:content_simple) do <<~EOS <?xml version="1.0" encoding="utf-8"?> <version>1.2.3</version> EOS end let(:content_undefined_namespace) do <<~EOS <?xml version="1.0" encoding="utf-8"?> <something:version>1.2.3</something:version> EOS end let(:parent_child_text) { { parent: "1.2.3", child: "4.5.6" } } let(:content_parent_child) do # This XML deliberately includes unnecessary whitespace, to ensure that # Xml#element_text properly strips the retrieved text. <<~EOS <?xml version="1.0" encoding="utf-8"?> <elements> <parent> #{parent_child_text[:parent]} <child> #{parent_child_text[:child]} </child> </parent> <blank-parent> <blank-child></blank-child> </blank-parent> </elements> EOS end let(:content_matches) { ["1.1.2", "1.1.1", "1.1.0", "1.0.3", "1.0.2", "1.0.1", "1.0.0"] } let(:content_simple_matches) { ["1.2.3"] } let(:find_versions_return_hash) do { matches: { "1.1.2" => Version.new("1.1.2"), "1.1.1" => Version.new("1.1.1"), "1.1.0" => Version.new("1.1.0"), "1.0.3" => Version.new("1.0.3"), "1.0.2" => Version.new("1.0.2"), "1.0.1" => Version.new("1.0.1"), "1.0.0" => Version.new("1.0.0"), }, regex:, url: http_url, } end let(:find_versions_cached_return_hash) do find_versions_return_hash.merge({ cached: true }) end describe "::match?" do it "returns true for an HTTP URL" do expect(xml.match?(http_url)).to be true end it "returns false for a non-HTTP URL" do expect(xml.match?(non_http_url)).to be false end end describe "::parse_xml" do # TODO: Should we be comparing against an actual REXML::Document object? it "returns an REXML::Document when given XML content" do expect(xml.parse_xml(content_version_text)).to be_an_instance_of(REXML::Document) end it "returns an REXML::Document when given XML content with an undefined namespace" do expect(xml.parse_xml(content_undefined_namespace)).to be_an_instance_of(REXML::Document) end end describe "::element_text" do let(:parent_child_doc) { xml.parse_xml(content_parent_child) } let(:parent) { parent_child_doc.get_elements("/elements/parent").first } let(:blank_parent) { parent_child_doc.get_elements("/elements/blank-parent").first } it "returns the element text if child_name is not provided" do expect(xml.element_text(parent)).to eq(parent_child_text[:parent]) end it "returns the child element text if child_name is provided" do expect(xml.element_text(parent, "child")).to eq(parent_child_text[:child]) end it "returns `nil` if the provided child element does not exist" do expect(xml.element_text(parent, "nonexistent")).to be_nil end it "returns `nil` if the retrieved text is blank" do expect(xml.element_text(blank_parent)).to be_nil expect(xml.element_text(blank_parent, "blank-child")).to be_nil end end describe "::versions_from_content" do it "returns an empty array when given a block but content is blank" do expect(xml.versions_from_content("", regex) { "1.2.3" }).to eq([]) end it "returns an array of version strings when given content and a block" do # Returning a string from block expect(xml.versions_from_content(content_simple) do |xml| xml.elements["version"]&.text end).to eq(content_simple_matches) expect(xml.versions_from_content(content_simple, regex) do |xml| version = xml.elements["version"]&.text next if version.blank? version[regex, 1] end).to eq(content_simple_matches) # Returning an array of strings from block expect(xml.versions_from_content(content_version_text, regex) do |xml, regex| xml.get_elements("/versions/version").map { |item| item.text[regex, 1] } end).to eq(content_matches) expect(xml.versions_from_content(content_version_attr, regex) do |xml, regex| xml.get_elements("/items/item").map do |item| version = item["version"] next if version.blank? version[regex, 1] end end).to eq(content_matches) end it "allows a nil return from a block" do expect(xml.versions_from_content(content_simple, regex) { next }).to eq([]) end it "errors if a block uses two arguments but a regex is not given" do expect { xml.versions_from_content(content_simple) { |xml, regex| xml["version"][regex, 1] } } .to raise_error("Two arguments found in `strategy` block but no regex provided.") end it "errors on an invalid return type from a block" do expect { xml.versions_from_content(content_simple, regex) { 123 } } .to raise_error(TypeError, Homebrew::Livecheck::Strategy::INVALID_BLOCK_RETURN_VALUE_MSG) end end describe "::find_versions?" do it "finds versions in provided_content using a block" do expect(xml.find_versions(url: http_url, regex:, provided_content: content_version_text) do |xml, regex| xml.get_elements("/versions/version").map { |item| item.text[regex, 1] } end).to eq(find_versions_cached_return_hash) # NOTE: A regex should be provided using the `#regex` method in a # `livecheck` block but we're using a regex literal in the `strategy` # block here simply to ensure this method works as expected when a # regex isn't provided. expect(xml.find_versions(url: http_url, provided_content: content_version_text) do |xml| regex = /^v?(\d+(?:\.\d+)+)$/i xml.get_elements("/versions/version").map { |item| item.text[regex, 1] } end).to eq(find_versions_cached_return_hash.merge({ regex: nil })) end it "errors if a block is not provided" do expect { xml.find_versions(url: http_url, provided_content: content_simple) } .to raise_error(ArgumentError, "Xml requires a `strategy` block") end it "returns default match_data when url is blank" do expect(xml.find_versions(url: "") { "1.2.3" }) .to eq({ matches: {}, regex: nil, url: "" }) end it "returns default match_data when content is blank" do expect(xml.find_versions(url: http_url, provided_content: "") { "1.2.3" }) .to eq({ matches: {}, regex: nil, url: http_url, cached: true }) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/strategy/apache_spec.rb
Library/Homebrew/test/livecheck/strategy/apache_spec.rb
# frozen_string_literal: true require "livecheck/strategy" RSpec.describe Homebrew::Livecheck::Strategy::Apache do subject(:apache) { described_class } let(:apache_urls) do { version_dir: "https://www.apache.org/dyn/closer.lua?path=abc/1.2.3/def-1.2.3.tar.gz", version_dir_root: "https://www.apache.org/dyn/closer.lua?path=/abc/1.2.3/def-1.2.3.tar.gz", name_and_version_dir: "https://www.apache.org/dyn/closer.lua?path=abc/def-1.2.3/ghi-1.2.3.tar.gz", name_dir_bin: "https://www.apache.org/dyn/closer.lua?path=abc/def/ghi-1.2.3-bin.tar.gz", archive_version_dir: "https://archive.apache.org/dist/abc/1.2.3/def-1.2.3.tar.gz", archive_name_and_version_dir: "https://archive.apache.org/dist/abc/def-1.2.3/ghi-1.2.3.tar.gz", archive_name_dir_bin: "https://archive.apache.org/dist/abc/def/ghi-1.2.3-bin.tar.gz", dlcdn_version_dir: "https://dlcdn.apache.org/abc/1.2.3/def-1.2.3.tar.gz", dlcdn_name_and_version_dir: "https://dlcdn.apache.org/abc/def-1.2.3/ghi-1.2.3.tar.gz", dlcdn_name_dir_bin: "https://dlcdn.apache.org/abc/def/ghi-1.2.3-bin.tar.gz", downloads_version_dir: "https://downloads.apache.org/abc/1.2.3/def-1.2.3.tar.gz", downloads_name_and_version_dir: "https://downloads.apache.org/abc/def-1.2.3/ghi-1.2.3.tar.gz", downloads_name_dir_bin: "https://downloads.apache.org/abc/def/ghi-1.2.3-bin.tar.gz", mirrors_version_dir: "https://www.apache.org/dyn/mirrors/mirrors.cgi?action=download&filename=abc/1.2.3/def-1.2.3.tar.gz", mirrors_version_dir_root: "https://www.apache.org/dyn/mirrors/mirrors.cgi?action=download&filename=/abc/1.2.3/def-1.2.3.tar.gz", mirrors_name_and_version_dir: "https://www.apache.org/dyn/mirrors/mirrors.cgi?action=download&filename=abc/def-1.2.3/ghi-1.2.3.tar.gz", mirrors_name_dir_bin: "https://www.apache.org/dyn/mirrors/mirrors.cgi?action=download&filename=abc/def/ghi-1.2.3-bin.tar.gz", } end let(:non_apache_url) { "https://brew.sh/test" } let(:generated) do values = { version_dir: { url: "https://archive.apache.org/dist/abc/", regex: %r{href=["']?v?(\d+(?:\.\d+)+)/}i, }, name_and_version_dir: { url: "https://archive.apache.org/dist/abc/", regex: %r{href=["']?def-v?(\d+(?:\.\d+)+)/}i, }, name_dir_bin: { url: "https://archive.apache.org/dist/abc/def/", regex: /href=["']?ghi-v?(\d+(?:\.\d+)+)-bin\.t/i, }, } values[:version_dir_root] = values[:version_dir] values[:archive_version_dir] = values[:version_dir] values[:archive_name_and_version_dir] = values[:name_and_version_dir] values[:archive_name_dir_bin] = values[:name_dir_bin] values[:dlcdn_version_dir] = values[:version_dir] values[:dlcdn_name_and_version_dir] = values[:name_and_version_dir] values[:dlcdn_name_dir_bin] = values[:name_dir_bin] values[:downloads_version_dir] = values[:version_dir] values[:downloads_name_and_version_dir] = values[:name_and_version_dir] values[:downloads_name_dir_bin] = values[:name_dir_bin] values[:mirrors_version_dir] = values[:version_dir] values[:mirrors_version_dir_root] = values[:version_dir_root] values[:mirrors_name_and_version_dir] = values[:name_and_version_dir] values[:mirrors_name_dir_bin] = values[:name_dir_bin] values end describe "::match?" do it "returns true for an Apache URL" do apache_urls.each_value { |url| expect(apache.match?(url)).to be true } end it "returns false for a non-Apache URL" do expect(apache.match?(non_apache_url)).to be false end end describe "::generate_input_values" do it "returns a hash containing url and regex for an Apache URL" do apache_urls.each do |key, url| expect(apache.generate_input_values(url)).to eq(generated[key]) end end it "returns an empty hash for a non-Apache URL" do expect(apache.generate_input_values(non_apache_url)).to eq({}) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/strategy/pypi_spec.rb
Library/Homebrew/test/livecheck/strategy/pypi_spec.rb
# frozen_string_literal: true require "livecheck/strategy" RSpec.describe Homebrew::Livecheck::Strategy::Pypi do subject(:pypi) { described_class } let(:pypi_url) { "https://files.pythonhosted.org/packages/ab/cd/efg/example-package-1.2.3.tar.gz" } let(:non_pypi_url) { "https://brew.sh/test" } let(:regex) { /^v?(\d+(?:\.\d+)+)/i } let(:generated) do { url: "https://pypi.org/pypi/example-package/json", } end # This is a limited subset of a PyPI JSON API response object, for the sake # of testing. Typical versions use a `1.2.3` format but this adds a suffix, # so we can test regex matching. let(:content) do <<~JSON { "info": { "version": "1.2.3-456" } } JSON end let(:matches) { ["1.2.3-456"] } let(:find_versions_return_hash) do { matches: { "1.2.3-456" => Version.new("1.2.3-456"), }, regex:, url: generated[:url], } end let(:find_versions_cached_return_hash) do find_versions_return_hash.merge({ cached: true }) end describe "::match?" do it "returns true for a PyPI URL" do expect(pypi.match?(pypi_url)).to be true end it "returns false for a non-PyPI URL" do expect(pypi.match?(non_pypi_url)).to be false end end describe "::generate_input_values" do it "returns a hash containing url and regex for an PyPI URL" do expect(pypi.generate_input_values(pypi_url)).to eq(generated) end it "returns an empty hash for a non-PyPI URL" do expect(pypi.generate_input_values(non_pypi_url)).to eq({}) end end describe "::find_versions" do let(:match_data) do cached = { matches: matches.to_h { |v| [v, Version.new(v)] }, regex: nil, url: generated[:url], cached: true, } { cached:, cached_default: cached.merge({ matches: {} }), cached_regex: cached.merge({ matches: { "1.2.3" => Version.new("1.2.3") }, regex:, }), } end it "finds versions in provided content" do expect(pypi.find_versions(url: pypi_url, regex:, provided_content: content)) .to eq(match_data[:cached_regex]) expect(pypi.find_versions(url: pypi_url, provided_content: content)) .to eq(match_data[:cached]) end it "finds versions in provided content using a block" do # NOTE: We only use a regex here to make sure it can be passed into the # block, if necessary. expect(pypi.find_versions(url: pypi_url, regex:, provided_content: content) do |json, regex| match = json.dig("info", "version")&.match(regex) next if match.blank? match[1] end).to eq(match_data[:cached_regex]) expect(pypi.find_versions(url: pypi_url, provided_content: content) do |json| json.dig("info", "version").presence end).to eq(match_data[:cached]) end it "returns default match_data when block doesn't return version information" do no_match_regex = /will_not_match/i expect(pypi.find_versions(url: pypi_url, provided_content: '{"info":{"version":""}}')) .to eq(match_data[:cached_default]) expect(pypi.find_versions(url: pypi_url, provided_content: '{"other":true}')) .to eq(match_data[:cached_default]) expect(pypi.find_versions(url: pypi_url, regex: no_match_regex, provided_content: content)) .to eq(match_data[:cached_default].merge({ regex: no_match_regex })) end it "returns default match_data when url is blank" do expect(pypi.find_versions(url: "") { "1.2.3" }) .to eq({ matches: {}, regex: nil, url: "" }) end it "returns default match_data when content is blank" do expect(pypi.find_versions(url: pypi_url, provided_content: "{}") { "1.2.3" }) .to eq(match_data[:cached_default]) expect(pypi.find_versions(url: pypi_url, provided_content: "") { "1.2.3" }) .to eq(match_data[:cached_default]) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/strategy/crate_spec.rb
Library/Homebrew/test/livecheck/strategy/crate_spec.rb
# frozen_string_literal: true require "livecheck/strategy" RSpec.describe Homebrew::Livecheck::Strategy::Crate do subject(:crate) { described_class } let(:crate_url) { "https://static.crates.io/crates/example/example-0.1.0.crate" } let(:non_crate_url) { "https://brew.sh/test" } let(:regex) { /^v?(\d+(?:\.\d+)+)$/i } let(:generated) do { url: "https://crates.io/api/v1/crates/example/versions" } end # This is a limited subset of a `versions` response object, for the sake of # testing. let(:content) do <<~EOS { "versions": [ { "crate": "example", "created_at": "2023-01-03T00:00:00.000000+00:00", "num": "1.0.2", "updated_at": "2023-01-03T00:00:00.000000+00:00", "yanked": true }, { "crate": "example", "created_at": "2023-01-02T00:00:00.000000+00:00", "num": "1.0.1", "updated_at": "2023-01-02T00:00:00.000000+00:00", "yanked": false }, { "crate": "example", "created_at": "2023-01-01T00:00:00.000000+00:00", "num": "1.0.0", "updated_at": "2023-01-01T00:00:00.000000+00:00", "yanked": false } ] } EOS end let(:matches) { ["1.0.0", "1.0.1"] } let(:find_versions_return_hash) do { matches: { "1.0.1" => Version.new("1.0.1"), "1.0.0" => Version.new("1.0.0"), }, regex:, url: generated[:url], } end let(:find_versions_cached_return_hash) do find_versions_return_hash.merge({ cached: true }) end describe "::match?" do it "returns true for a crate URL" do expect(crate.match?(crate_url)).to be true end it "returns false for a non-crate URL" do expect(crate.match?(non_crate_url)).to be false end end describe "::generate_input_values" do it "returns a hash containing url for a crate URL" do expect(crate.generate_input_values(crate_url)).to eq(generated) end it "returns an empty hash for a non-crate URL" do expect(crate.generate_input_values(non_crate_url)).to eq({}) end end describe "::find_versions" do let(:match_data) do cached = { matches: matches.to_h { |v| [v, Version.new(v)] }, regex: nil, url: generated[:url], cached: true, } { cached:, cached_default: cached.merge({ matches: {} }), } end it "finds versions in provided content" do expect(crate.find_versions(url: crate_url, regex:, provided_content: content)) .to eq(match_data[:cached].merge({ regex: })) expect(crate.find_versions(url: crate_url, provided_content: content)) .to eq(match_data[:cached]) end it "finds versions in provided content using a block" do expect(crate.find_versions(url: crate_url, regex:, provided_content: content) do |json, regex| json["versions"]&.map do |version| next if version["yanked"] == true next if (match = version["num"]&.match(regex)).blank? match[1] end end).to eq(match_data[:cached].merge({ regex: })) expect(crate.find_versions(url: crate_url, provided_content: content) do |json| json["versions"]&.map do |version| next if version["yanked"] == true next if (match = version["num"]&.match(regex)).blank? match[1] end end).to eq(match_data[:cached]) end it "returns default match_data when block doesn't return version information" do no_match_regex = /will_not_match/i expect(crate.find_versions(url: crate_url, provided_content: '{"other":true}')) .to eq(match_data[:cached_default]) expect(crate.find_versions(url: crate_url, provided_content: '{"versions":[{}]}')) .to eq(match_data[:cached_default]) expect(crate.find_versions(url: crate_url, regex: no_match_regex, provided_content: content)) .to eq(match_data[:cached_default].merge({ regex: no_match_regex })) end it "returns default match_data when url is blank" do expect(crate.find_versions(url: "") { "1.2.3" }) .to eq({ matches: {}, regex: nil, url: "" }) end it "returns default match_data when content is blank" do expect(crate.find_versions(url: crate_url, provided_content: "{}") { "1.2.3" }) .to eq(match_data[:cached_default]) expect(crate.find_versions(url: crate_url, provided_content: "") { "1.2.3" }) .to eq(match_data[:cached_default]) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/strategy/git_spec.rb
Library/Homebrew/test/livecheck/strategy/git_spec.rb
# frozen_string_literal: true require "livecheck/strategy" RSpec.describe Homebrew::Livecheck::Strategy::Git do subject(:git) { described_class } let(:git_url) { "https://github.com/Homebrew/brew.git" } let(:non_git_url) { "https://brew.sh/test" } let(:tags) do { normal: ["brew/1.2", "brew/1.2.1", "brew/1.2.2", "brew/1.2.3", "brew/1.2.4", "1.2.5"], hyphens: ["brew/1-2", "brew/1-2-1", "brew/1-2-2", "brew/1-2-3", "brew/1-2-4", "1-2-5"], } end let(:regexes) do { standard: /^v?(\d+(?:\.\d+)+)$/i, hyphens: /^v?(\d+(?:[.-]\d+)+)$/i, brew: %r{^brew/v?(\d+(?:\.\d+)+)$}i, } end let(:versions) do { default: ["1.2", "1.2.1", "1.2.2", "1.2.3", "1.2.4", "1.2.5"], standard_regex: ["1.2.5"], brew_regex: ["1.2", "1.2.1", "1.2.2", "1.2.3", "1.2.4"], } end describe "::tag_info", :needs_network do it "returns the Git tags for the provided remote URL that match the regex provided" do expect(git.tag_info(git_url, regexes[:standard])).not_to be_empty end end describe "::preprocess_url" do let(:github_git_url_with_extension) { "https://github.com/Homebrew/brew.git" } it "returns the unmodified URL for an unparsable URL" do # Modeled after the `head` URL in the `ncp` formula expect(git.preprocess_url(":something:cvs:@cvs.brew.sh:/cvs")) .to eq(":something:cvs:@cvs.brew.sh:/cvs") end it "returns the unmodified URL for a GitHub URL ending in .git" do expect(git.preprocess_url(github_git_url_with_extension)) .to eq(github_git_url_with_extension) end it "returns the Git repository URL for a GitHub URL not ending in .git" do expect(git.preprocess_url("https://github.com/Homebrew/brew")) .to eq(github_git_url_with_extension) end it "returns the unmodified URL for a GitHub /releases/latest URL" do expect(git.preprocess_url("https://github.com/Homebrew/brew/releases/latest")) .to eq("https://github.com/Homebrew/brew/releases/latest") end it "returns the Git repository URL for a GitHub AWS URL" do expect(git.preprocess_url("https://github.s3.amazonaws.com/downloads/Homebrew/brew/1.0.0.tar.gz")) .to eq(github_git_url_with_extension) end it "returns the Git repository URL for a github.com/downloads/... URL" do expect(git.preprocess_url("https://github.com/downloads/Homebrew/brew/1.0.0.tar.gz")) .to eq(github_git_url_with_extension) end it "returns the Git repository URL for a GitHub tag archive URL" do expect(git.preprocess_url("https://github.com/Homebrew/brew/archive/1.0.0.tar.gz")) .to eq(github_git_url_with_extension) end it "returns the Git repository URL for a GitHub release archive URL" do expect(git.preprocess_url("https://github.com/Homebrew/brew/releases/download/1.0.0/brew-1.0.0.tar.gz")) .to eq(github_git_url_with_extension) end it "returns the Git repository URL for a gitlab.com archive URL" do expect(git.preprocess_url("https://gitlab.com/Homebrew/brew/-/archive/1.0.0/brew-1.0.0.tar.gz")) .to eq("https://gitlab.com/Homebrew/brew.git") end it "returns the Git repository URL for a self-hosted GitLab archive URL" do expect(git.preprocess_url("https://brew.sh/Homebrew/brew/-/archive/1.0.0/brew-1.0.0.tar.gz")) .to eq("https://brew.sh/Homebrew/brew.git") end it "returns the Git repository URL for a Codeberg archive URL" do expect(git.preprocess_url("https://codeberg.org/Homebrew/brew/archive/brew-1.0.0.tar.gz")) .to eq("https://codeberg.org/Homebrew/brew.git") end it "returns the Git repository URL for a Gitea archive URL" do expect(git.preprocess_url("https://gitea.com/Homebrew/brew/archive/brew-1.0.0.tar.gz")) .to eq("https://gitea.com/Homebrew/brew.git") end it "returns the Git repository URL for an Opendev archive URL" do expect(git.preprocess_url("https://opendev.org/Homebrew/brew/archive/brew-1.0.0.tar.gz")) .to eq("https://opendev.org/Homebrew/brew.git") end it "returns the Git repository URL for a tildegit archive URL" do expect(git.preprocess_url("https://tildegit.org/Homebrew/brew/archive/brew-1.0.0.tar.gz")) .to eq("https://tildegit.org/Homebrew/brew.git") end it "returns the Git repository URL for a LOL Git archive URL" do expect(git.preprocess_url("https://lolg.it/Homebrew/brew/archive/brew-1.0.0.tar.gz")) .to eq("https://lolg.it/Homebrew/brew.git") end it "returns the Git repository URL for a sourcehut archive URL" do expect(git.preprocess_url("https://git.sr.ht/~Homebrew/brew/archive/1.0.0.tar.gz")) .to eq("https://git.sr.ht/~Homebrew/brew") end end describe "::match?" do it "returns true for a Git repository URL" do expect(git.match?(git_url)).to be true end it "returns false for a non-Git URL" do expect(git.match?(non_git_url)).to be false end end describe "::versions_from_tags" do it "returns an empty array if tags array is empty" do expect(git.versions_from_tags([])).to eq([]) end it "returns an array of version strings when given tags" do expect(git.versions_from_tags(tags[:normal])).to eq(versions[:default]) expect(git.versions_from_tags(tags[:normal], regexes[:standard])).to eq(versions[:standard_regex]) expect(git.versions_from_tags(tags[:normal], regexes[:brew])).to eq(versions[:brew_regex]) end it "returns an array of version strings when given tags and a block" do # Returning a string from block, default strategy regex expect(git.versions_from_tags(tags[:normal]) { versions[:default].first }).to eq([versions[:default].first]) # Returning an array of strings from block, default strategy regex expect( git.versions_from_tags(tags[:hyphens]) do |tags, regex| tags.map { |tag| tag[regex, 1]&.tr("-", ".") } end, ).to eq(versions[:default]) # Returning an array of strings from block, explicit regex expect( git.versions_from_tags(tags[:hyphens], regexes[:hyphens]) do |tags, regex| tags.map { |tag| tag[regex, 1]&.tr("-", ".") } end, ).to eq(versions[:standard_regex]) expect(git.versions_from_tags(tags[:hyphens]) { "1.2.3" }).to eq(["1.2.3"]) end it "allows a nil return from a block" do expect(git.versions_from_tags(tags[:normal]) { next }).to eq([]) end it "errors on an invalid return type from a block" do expect { git.versions_from_tags(tags[:normal]) { 123 } } .to raise_error(TypeError, Homebrew::Livecheck::Strategy::INVALID_BLOCK_RETURN_VALUE_MSG) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/strategy/bitbucket_spec.rb
Library/Homebrew/test/livecheck/strategy/bitbucket_spec.rb
# frozen_string_literal: true require "livecheck/strategy" RSpec.describe Homebrew::Livecheck::Strategy::Bitbucket do subject(:bitbucket) { described_class } let(:bitbucket_urls) do { get: "https://bitbucket.org/abc/def/get/1.2.3.tar.gz", downloads: "https://bitbucket.org/abc/def/downloads/ghi-1.2.3.tar.gz", } end let(:non_bitbucket_url) { "https://brew.sh/test" } let(:generated) do { get: { url: "https://bitbucket.org/abc/def/downloads/?tab=tags&iframe=true&spa=0", regex: /<td[^>]*?class="name"[^>]*?>\s*v?(\d+(?:\.\d+)+)\s*?</im, }, downloads: { url: "https://bitbucket.org/abc/def/downloads/?iframe=true&spa=0", regex: /href=.*?ghi-v?(\d+(?:\.\d+)+)\.t/i, }, } end describe "::match?" do it "returns true for a Bitbucket URL" do expect(bitbucket.match?(bitbucket_urls[:get])).to be true expect(bitbucket.match?(bitbucket_urls[:downloads])).to be true end it "returns false for a non-Bitbucket URL" do expect(bitbucket.match?(non_bitbucket_url)).to be false end end describe "::generate_input_values" do it "returns a hash containing url and regex for a Bitbucket URL" do expect(bitbucket.generate_input_values(bitbucket_urls[:get])).to eq(generated[:get]) expect(bitbucket.generate_input_values(bitbucket_urls[:downloads])).to eq(generated[:downloads]) end it "returns an empty hash for a non-Bitbucket URL" do expect(bitbucket.generate_input_values(non_bitbucket_url)).to eq({}) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/strategy/hackage_spec.rb
Library/Homebrew/test/livecheck/strategy/hackage_spec.rb
# frozen_string_literal: true require "livecheck/strategy/hackage" RSpec.describe Homebrew::Livecheck::Strategy::Hackage do subject(:hackage) { described_class } let(:hackage_urls) do { package: "https://hackage.haskell.org/package/abc-1.2.3/abc-1.2.3.tar.gz", downloads: "https://downloads.haskell.org/~abc/1.2.3/abc-1.2.3-src.tar.xz", } end let(:non_hackage_url) { "https://brew.sh/test" } let(:generated) do { url: "https://hackage.haskell.org/package/abc/src/", regex: %r{<h3>abc-(.*?)/?</h3>}i, } end describe "::match?" do it "returns true for a Hackage URL" do expect(hackage.match?(hackage_urls[:package])).to be true expect(hackage.match?(hackage_urls[:downloads])).to be true end it "returns false for a non-Hackage URL" do expect(hackage.match?(non_hackage_url)).to be false end end describe "::generate_input_values" do it "returns a hash containing url and regex for a Hackage URL" do expect(hackage.generate_input_values(hackage_urls[:package])).to eq(generated) expect(hackage.generate_input_values(hackage_urls[:downloads])).to eq(generated) end it "returns an empty hash for a non-Hackage URL" do expect(hackage.generate_input_values(non_hackage_url)).to eq({}) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/strategy/gnome_spec.rb
Library/Homebrew/test/livecheck/strategy/gnome_spec.rb
# frozen_string_literal: true require "livecheck/strategy/gnome" RSpec.describe Homebrew::Livecheck::Strategy::Gnome do subject(:gnome) { described_class } let(:gnome_url) { "https://download.gnome.org/sources/abc/1.2/abc-1.2.3.tar.xz" } let(:non_gnome_url) { "https://brew.sh/test" } let(:generated) do { url: "https://download.gnome.org/sources/abc/cache.json", regex: /abc-(\d+(?:\.\d+)*)\.t/i, } end describe "::match?" do it "returns true for a GNOME URL" do expect(gnome.match?(gnome_url)).to be true end it "returns false for a non-GNOME URL" do expect(gnome.match?(non_gnome_url)).to be false end end describe "::generate_input_values" do it "returns a hash containing url and regex for a GNOME URL" do expect(gnome.generate_input_values(gnome_url)).to eq(generated) end it "returns an empty hash for a non-GNOME URL" do expect(gnome.generate_input_values(non_gnome_url)).to eq({}) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/strategy/header_match_spec.rb
Library/Homebrew/test/livecheck/strategy/header_match_spec.rb
# frozen_string_literal: true require "livecheck/strategy" RSpec.describe Homebrew::Livecheck::Strategy::HeaderMatch do subject(:header_match) { described_class } let(:http_url) { "https://brew.sh/blog/" } let(:non_http_url) { "ftp://brew.sh/" } let(:versions) do versions = { content_disposition: ["1.2.3"], location: ["1.2.4"], } versions[:content_disposition_and_location] = versions[:content_disposition] + versions[:location] versions end let(:headers) do headers = { content_disposition: { "date" => "Fri, 01 Jan 2021 01:23:45 GMT", "content-type" => "application/x-gzip", "content-length" => "120", "content-disposition" => "attachment; filename=brew-#{versions[:content_disposition].first}.tar.gz", }, location: { "date" => "Fri, 01 Jan 2021 01:23:45 GMT", "content-type" => "text/html; charset=utf-8", "location" => "https://github.com/Homebrew/brew/releases/tag/#{versions[:location].first}", "content-length" => "117", }, } headers[:content_disposition_and_location] = headers[:content_disposition].merge(headers[:location]) headers end let(:regexes) do { archive: /filename=brew[._-]v?(\d+(?:\.\d+)+)\.t/i, latest: %r{.*?/tag/v?(\d+(?:\.\d+)+)$}i, loose: /v?(\d+(?:\.\d+)+)/i, } end describe "::match?" do it "returns true for an HTTP URL" do expect(header_match.match?(http_url)).to be true end it "returns false for a non-HTTP URL" do expect(header_match.match?(non_http_url)).to be false end end describe "::versions_from_headers" do it "returns an empty array if headers hash is empty" do expect(header_match.versions_from_headers({})).to eq([]) end it "returns an array of version strings when given headers" do expect(header_match.versions_from_headers(headers[:content_disposition])).to eq(versions[:content_disposition]) expect(header_match.versions_from_headers(headers[:location])).to eq(versions[:location]) expect(header_match.versions_from_headers(headers[:content_disposition_and_location])) .to eq(versions[:content_disposition_and_location]) expect(header_match.versions_from_headers(headers[:content_disposition], regexes[:archive])) .to eq(versions[:content_disposition]) expect(header_match.versions_from_headers(headers[:location], regexes[:latest])).to eq(versions[:location]) expect(header_match.versions_from_headers(headers[:content_disposition_and_location], regexes[:latest])) .to eq(versions[:location]) end it "returns an array of version strings when given headers and a block" do # Returning a string from block, no regex. expect( header_match.versions_from_headers(headers[:location]) do |headers| v = Version.parse(headers["location"], detected_from_url: true) v.null? ? nil : v.to_s end, ).to eq(versions[:location]) # Returning a string from block, explicit regex. expect( header_match.versions_from_headers(headers[:location], regexes[:latest]) do |headers, regex| headers["location"] ? headers["location"][regex, 1] : nil end, ).to eq(versions[:location]) # Returning an array of strings from block. # # NOTE: Strategies runs `#compact` on an array from a block, so nil values # are filtered out without needing to use `#compact` in the block. expect( header_match.versions_from_headers( headers[:content_disposition_and_location], regexes[:loose], ) do |headers, regex| headers.transform_values { |header| header[regex, 1] }.values end, ).to eq(versions[:content_disposition_and_location]) end it "allows a nil return from a block" do expect(header_match.versions_from_headers(headers[:location]) { next }).to eq([]) end it "errors on an invalid return type from a block" do expect { header_match.versions_from_headers(headers) { 123 } } .to raise_error(TypeError, /Parameter 'headers': Expected type T::Hash\[String, String\]/o) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/strategy/page_match_spec.rb
Library/Homebrew/test/livecheck/strategy/page_match_spec.rb
# frozen_string_literal: true require "livecheck/strategy" RSpec.describe Homebrew::Livecheck::Strategy::PageMatch do subject(:page_match) { described_class } let(:http_url) { "https://brew.sh/blog/" } let(:non_http_url) { "ftp://brew.sh/" } let(:regex) { %r{href=.*?/homebrew[._-]v?(\d+(?:\.\d+)+)/?["' >]}i } let(:content) do <<~EOS <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Homebrew — Homebrew</title> </head> <body> <ul class="posts"> <li><a href="/2020/12/01/homebrew-2.6.0/" title="2.6.0"><h2>2.6.0</h2><h3>01 Dec 2020</h3></a></li> <li><a href="/2020/11/18/homebrew-tap-with-bottles-uploaded-to-github-releases/" title="Homebrew tap with bottles uploaded to GitHub Releases"><h2>Homebrew tap with bottles uploaded to GitHub Releases</h2><h3>18 Nov 2020</h3></a></li> <li><a href="/2020/09/08/homebrew-2.5.0/" title="2.5.0"><h2>2.5.0</h2><h3>08 Sep 2020</h3></a></li> <li><a href="/2020/06/11/homebrew-2.4.0/" title="2.4.0"><h2>2.4.0</h2><h3>11 Jun 2020</h3></a></li> <li><a href="/2020/05/29/homebrew-2.3.0/" title="2.3.0"><h2>2.3.0</h2><h3>29 May 2020</h3></a></li> <li><a href="/2019/11/27/homebrew-2.2.0/" title="2.2.0"><h2>2.2.0</h2><h3>27 Nov 2019</h3></a></li> <li><a href="/2019/06/14/homebrew-maintainer-meeting/" title="Homebrew Maintainer Meeting"><h2>Homebrew Maintainer Meeting</h2><h3>14 Jun 2019</h3></a></li> <li><a href="/2019/04/04/homebrew-2.1.0/" title="2.1.0"><h2>2.1.0</h2><h3>04 Apr 2019</h3></a></li> <li><a href="/2019/02/02/homebrew-2.0.0/" title="2.0.0"><h2>2.0.0</h2><h3>02 Feb 2019</h3></a></li> <li><a href="/2019/01/09/homebrew-1.9.0/" title="1.9.0"><h2>1.9.0</h2><h3>09 Jan 2019</h3></a></li> </ul> </body> </html> EOS end let(:content_matches) { ["2.6.0", "2.5.0", "2.4.0", "2.3.0", "2.2.0", "2.1.0", "2.0.0", "1.9.0"] } let(:find_versions_return_hash) do { matches: { "2.6.0" => Version.new("2.6.0"), "2.5.0" => Version.new("2.5.0"), "2.4.0" => Version.new("2.4.0"), "2.3.0" => Version.new("2.3.0"), "2.2.0" => Version.new("2.2.0"), "2.1.0" => Version.new("2.1.0"), "2.0.0" => Version.new("2.0.0"), "1.9.0" => Version.new("1.9.0"), }, regex:, url: http_url, } end let(:find_versions_cached_return_hash) do return_hash = find_versions_return_hash return_hash[:cached] = true return_hash end describe "::match?" do it "returns true for an HTTP URL" do expect(page_match.match?(http_url)).to be true end it "returns false for a non-HTTP URL" do expect(page_match.match?(non_http_url)).to be false end end describe "::versions_from_content" do it "returns an empty array if content is blank" do expect(page_match.versions_from_content("", regex)).to eq([]) end it "returns an array of version strings when given content" do expect(page_match.versions_from_content(content, regex)).to eq(content_matches) # Regexes should use a capture group around the version but a regex # without one should still be handled expect(page_match.versions_from_content(content, /\d+(?:\.\d+)+/i)).to eq(content_matches) end it "returns an array of version strings when given content and a block" do # Returning a string from block expect(page_match.versions_from_content(content, regex) { "1.2.3" }).to eq(["1.2.3"]) # Returning an array of strings from block expect(page_match.versions_from_content(content, regex) { |page, regex| page.scan(regex).map(&:first) }) .to eq(content_matches) end it "allows a nil return from a block" do expect(page_match.versions_from_content(content, regex) { next }).to eq([]) end it "errors on an invalid return type from a block" do expect { page_match.versions_from_content(content, regex) { 123 } } .to raise_error(TypeError, Homebrew::Livecheck::Strategy::INVALID_BLOCK_RETURN_VALUE_MSG) end end describe "::find_versions?" do it "finds versions in provided_content" do expect(page_match.find_versions(url: http_url, regex:, provided_content: content)) .to eq(find_versions_cached_return_hash) # NOTE: Ideally, a regex should always be provided to `#find_versions` # for `PageMatch` but there are currently some `livecheck` blocks in # casks where `#regex` isn't used and the regex only exists within a # `strategy` block. This isn't ideal but, for the moment, we allow a # `strategy` block to act as a substitution for a regex and we need to # test this scenario to ensure it works. # # Under normal circumstances, a regex should be established in a # `livecheck` block using `#regex` and passed into the `strategy` block # using `do |page, regex|`. Hopefully over time we can address related # issues and get to a point where regexes are always established using # `#regex`. expect(page_match.find_versions(url: http_url, provided_content: content) do |page| page.scan(%r{href=.*?/homebrew[._-]v?(\d+(?:\.\d+)+)/?["' >]}i).map(&:first) end) .to eq(find_versions_cached_return_hash.merge({ regex: nil })) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/strategy/github_releases_spec.rb
Library/Homebrew/test/livecheck/strategy/github_releases_spec.rb
# frozen_string_literal: true require "livecheck/strategy" RSpec.describe Homebrew::Livecheck::Strategy::GithubReleases do subject(:github_releases) { described_class } let(:github_urls) do { release_artifact: "https://github.com/abc/def/releases/download/1.2.3/ghi-1.2.3.tar.gz", tag_archive: "https://github.com/abc/def/archive/v1.2.3.tar.gz", repository_upload: "https://github.com/downloads/abc/def/ghi-1.2.3.tar.gz", } end let(:non_github_url) { "https://brew.sh/test" } let(:regex) { github_releases::DEFAULT_REGEX } let(:generated) do { url: "https://api.github.com/repos/abc/def/releases", username: "abc", repository: "def", } end # For the sake of brevity, this is a limited subset of the information found # in release objects in a response from the GitHub API. Some of these objects # are somewhat representative of real world scenarios but others are # contrived examples for the sake of exercising code paths. let(:content) do <<~EOS [ { "tag_name": "v1.2.3", "name": "v1.2.3", "draft": false, "prerelease": false }, { "tag_name": "no-version-tag-also", "name": "1.2.2", "draft": false, "prerelease": false }, { "tag_name": "1.2.1", "name": "No version title", "draft": false, "prerelease": false }, { "tag_name": "no-version-tag", "name": "No version title", "draft": false, "prerelease": false }, { "tag_name": "v1.1.2", "name": "v1.1.2", "draft": false, "prerelease": true }, { "tag_name": "v1.1.1", "name": "v1.1.1", "draft": true, "prerelease": false }, { "tag_name": "v1.1.0", "name": "v1.1.0", "draft": true, "prerelease": true }, { "other": "something-else" } ] EOS end let(:json) { JSON.parse(content) } let(:matches) { ["1.2.3", "1.2.2", "1.2.1"] } describe "::match?" do it "returns true for a GitHub release artifact URL" do expect(github_releases.match?(github_urls[:release_artifact])).to be true end it "returns true for a GitHub tag archive URL" do expect(github_releases.match?(github_urls[:tag_archive])).to be true end it "returns true for a GitHub repository upload URL" do expect(github_releases.match?(github_urls[:repository_upload])).to be true end it "returns false for a non-GitHub URL" do expect(github_releases.match?(non_github_url)).to be false end end describe "::generate_input_values" do it "returns a hash containing a url and regex for a GitHub release artifact URL" do expect(github_releases.generate_input_values(github_urls[:release_artifact])).to eq(generated) end it "returns a hash containing a url and regex for a GitHub tag archive URL" do expect(github_releases.generate_input_values(github_urls[:tag_archive])).to eq(generated) end it "returns a hash containing a url and regex for a GitHub repository upload URL" do expect(github_releases.generate_input_values(github_urls[:repository_upload])).to eq(generated) end it "returns an empty hash for a non-GitHub URL" do expect(github_releases.generate_input_values(non_github_url)).to eq({}) end end describe "::versions_from_content" do it "returns an empty array if content is blank" do expect(github_releases.versions_from_content({}, regex)).to eq([]) end it "returns an array of version strings when given content" do expect(github_releases.versions_from_content(json, regex)).to eq(matches) end it "returns an array of version strings when given content and a block" do # Returning a string from block expect(github_releases.versions_from_content(json, regex) { "1.2.3" }).to eq(["1.2.3"]) # Returning an array of strings from block expect(github_releases.versions_from_content(json, regex) do |json, regex| json.map do |release| next if release["draft"] || release["prerelease"] match = release["tag_name"]&.match(regex) next if match.blank? match[1] end end).to eq(["1.2.3", "1.2.1"]) end it "allows a nil return from a block" do expect(github_releases.versions_from_content(json, regex) { next }).to eq([]) end it "errors on an invalid return type from a block" do expect { github_releases.versions_from_content(json, regex) { 123 } } .to raise_error(TypeError, Homebrew::Livecheck::Strategy::INVALID_BLOCK_RETURN_VALUE_MSG) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/strategy/xorg_spec.rb
Library/Homebrew/test/livecheck/strategy/xorg_spec.rb
# frozen_string_literal: true require "livecheck/strategy/xorg" RSpec.describe Homebrew::Livecheck::Strategy::Xorg do subject(:xorg) { described_class } let(:xorg_urls) do { app: "https://www.x.org/archive/individual/app/abc-1.2.3.tar.bz2", font: "https://www.x.org/archive/individual/font/abc-1.2.3.tar.bz2", lib: "https://www.x.org/archive/individual/lib/libabc-1.2.3.tar.bz2", ftp_lib: "https://ftp.x.org/archive/individual/lib/libabc-1.2.3.tar.bz2", pub_doc: "https://www.x.org/pub/individual/doc/abc-1.2.3.tar.bz2", freedesktop: "https://xorg.freedesktop.org/archive/individual/util/abc-1.2.3.tar.xz", mesa: "https://archive.mesa3d.org/mesa-1.2.3.tar.xz", } end let(:non_xorg_url) { "https://brew.sh/test" } let(:generated) do { app: { url: "https://www.x.org/archive/individual/app/", regex: /href=.*?abc[._-]v?(\d+(?:\.\d+)+)\.t/i, }, font: { url: "https://www.x.org/archive/individual/font/", regex: /href=.*?abc[._-]v?(\d+(?:\.\d+)+)\.t/i, }, lib: { url: "https://www.x.org/archive/individual/lib/", regex: /href=.*?libabc[._-]v?(\d+(?:\.\d+)+)\.t/i, }, ftp_lib: { url: "https://ftp.x.org/archive/individual/lib/", regex: /href=.*?libabc[._-]v?(\d+(?:\.\d+)+)\.t/i, }, pub_doc: { url: "https://www.x.org/archive/individual/doc/", regex: /href=.*?abc[._-]v?(\d+(?:\.\d+)+)\.t/i, }, freedesktop: { url: "https://xorg.freedesktop.org/archive/individual/util/", regex: /href=.*?abc[._-]v?(\d+(?:\.\d+)+)\.t/i, }, mesa: { url: "https://archive.mesa3d.org/", regex: /href=.*?mesa[._-]v?(\d+(?:\.\d+)+)\.t/i, }, } end describe "::match?" do it "returns true for an X.Org URL" do expect(xorg.match?(xorg_urls[:app])).to be true expect(xorg.match?(xorg_urls[:font])).to be true expect(xorg.match?(xorg_urls[:lib])).to be true expect(xorg.match?(xorg_urls[:ftp_lib])).to be true expect(xorg.match?(xorg_urls[:pub_doc])).to be true expect(xorg.match?(xorg_urls[:freedesktop])).to be true expect(xorg.match?(xorg_urls[:mesa])).to be true end it "returns false for a non-X.Org URL" do expect(xorg.match?(non_xorg_url)).to be false end end describe "::generate_input_values" do it "returns a hash containing url and regex for an X.org URL" do expect(xorg.generate_input_values(xorg_urls[:app])).to eq(generated[:app]) expect(xorg.generate_input_values(xorg_urls[:font])).to eq(generated[:font]) expect(xorg.generate_input_values(xorg_urls[:lib])).to eq(generated[:lib]) expect(xorg.generate_input_values(xorg_urls[:ftp_lib])).to eq(generated[:ftp_lib]) expect(xorg.generate_input_values(xorg_urls[:pub_doc])).to eq(generated[:pub_doc]) expect(xorg.generate_input_values(xorg_urls[:freedesktop])).to eq(generated[:freedesktop]) expect(xorg.generate_input_values(xorg_urls[:mesa])).to eq(generated[:mesa]) end it "returns an empty hash for a non-X.org URL" do expect(xorg.generate_input_values(non_xorg_url)).to eq({}) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/strategy/sparkle_spec.rb
Library/Homebrew/test/livecheck/strategy/sparkle_spec.rb
# frozen_string_literal: true require "livecheck/strategy" require "bundle_version" RSpec.describe Homebrew::Livecheck::Strategy::Sparkle do subject(:sparkle) { described_class } def create_appcast_xml(items_str = "") <<~EOS <?xml version="1.0" encoding="utf-8"?> <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle"> <channel> <title>Example Changelog</title> <link>#{appcast_url}</link> <description>Most recent changes with links to updates.</description> <language>en</language> #{items_str} </channel> </rss> EOS end let(:appcast_url) { "https://www.example.com/example/appcast.xml" } let(:non_http_url) { "ftp://brew.sh/" } # The `item_hashes` data is used to create test appcast XML and expected # `Sparkle::Item` objects. let(:item_hashes) do { # The 1.2.4 version is only used in tests as the basis for an item that # should be excluded (after modifications). v124: { title: "Version 1.2.4", release_notes_link: "https://www.example.com/example/1.2.4.html", pub_date: "Fri, 02 Jan 2021 01:23:45 +0000", url: "https://www.example.com/example/example-1.2.4.tar.gz", short_version: "1.2.4", version: "124", minimum_system_version: "10.10", }, v123: { title: "Version 1.2.3", release_notes_link: "https://www.example.com/example/1.2.3.html", pub_date: "Fri, 01 Jan 2021 01:23:45 +0000", url: "https://www.example.com/example/example-1.2.3.tar.gz", short_version: "1.2.3", version: "123", minimum_system_version: "10.10", }, v122: { title: "Version 1.2.2", release_notes_link: "https://www.example.com/example/1.2.2.html", pub_date: "Not a parseable date string", link: "https://www.example.com/example/example-1.2.2.tar.gz", short_version: "1.2.2", version: "122", minimum_system_version: "10.10", }, v121: { title: "Version 1.2.1", release_notes_link: "https://www.example.com/example/1.2.1.html", pub_date: "Thu, 31 Dec 2020 01:23:45 +0000", os: "osx", url: "https://www.example.com/example/example-1.2.1.tar.gz", short_version: "1.2.1", version: "121", minimum_system_version: "10.10", }, v120: { title: "Version 1.2.0", release_notes_link: "https://www.example.com/example/1.2.0.html", pub_date: "Wed, 30 Dec 2020 01:23:45 +0000", os: "macos", url: "https://www.example.com/example/example-1.2.0.tar.gz", short_version: "1.2.0", version: "120", minimum_system_version: "10.10", }, } end let(:xml) do v123_item = <<~EOS <item> <title>#{item_hashes[:v123][:title]}</title> <sparkle:minimumSystemVersion>#{item_hashes[:v123][:minimum_system_version]}</sparkle:minimumSystemVersion> <sparkle:releaseNotesLink>#{item_hashes[:v123][:release_notes_link]}</sparkle:releaseNotesLink> <pubDate>#{item_hashes[:v123][:pub_date]}</pubDate> <enclosure url="#{item_hashes[:v123][:url]}" sparkle:shortVersionString="#{item_hashes[:v123][:short_version]}" sparkle:version="#{item_hashes[:v123][:version]}" length="12345678" type="application/octet-stream" sparkle:dsaSignature="ABCDEF+GHIJKLMNOPQRSTUVWXYZab/cdefghijklmnopqrst/uvwxyz1234567==" /> </item> EOS v122_item = <<~EOS <item> <title>#{item_hashes[:v122][:title]}</title> <link>#{item_hashes[:v122][:link]}</link> <sparkle:minimumSystemVersion>#{item_hashes[:v122][:minimum_system_version]}</sparkle:minimumSystemVersion> <sparkle:releaseNotesLink>#{item_hashes[:v122][:release_notes_link]}</sparkle:releaseNotesLink> <pubDate>#{item_hashes[:v122][:pub_date]}</pubDate> <sparkle:version>#{item_hashes[:v122][:version]}</sparkle:version> <sparkle:shortVersionString>#{item_hashes[:v122][:short_version]}</sparkle:shortVersionString> </item> EOS v121_item_with_osx_os = <<~EOS <item> <title>#{item_hashes[:v121][:title]}</title> <sparkle:minimumSystemVersion>#{item_hashes[:v121][:minimum_system_version]}</sparkle:minimumSystemVersion> <sparkle:releaseNotesLink>#{item_hashes[:v121][:release_notes_link]}</sparkle:releaseNotesLink> <pubDate>#{item_hashes[:v121][:pub_date]}</pubDate> <enclosure os="#{item_hashes[:v121][:os]}" url="#{item_hashes[:v121][:url]}" sparkle:shortVersionString="#{item_hashes[:v121][:short_version]}" sparkle:version="#{item_hashes[:v121][:version]}" length="12345678" type="application/octet-stream" sparkle:dsaSignature="ABCDEF+GHIJKLMNOPQRSTUVWXYZab/cdefghijklmnopqrst/uvwxyz1234567==" /> </item> EOS v120_item_with_macos_os = <<~EOS <item> <title>#{item_hashes[:v120][:title]}</title> <sparkle:minimumSystemVersion>#{item_hashes[:v120][:minimum_system_version]}</sparkle:minimumSystemVersion> <sparkle:releaseNotesLink>#{item_hashes[:v120][:release_notes_link]}</sparkle:releaseNotesLink> <pubDate>#{item_hashes[:v120][:pub_date]}</pubDate> <enclosure os="#{item_hashes[:v120][:os]}" url="#{item_hashes[:v120][:url]}" sparkle:shortVersionString="#{item_hashes[:v120][:short_version]}" sparkle:version="#{item_hashes[:v120][:version]}" length="12345678" type="application/octet-stream" sparkle:dsaSignature="ABCDEF+GHIJKLMNOPQRSTUVWXYZab/cdefghijklmnopqrst/uvwxyz1234567==" /> </item> EOS # This main `appcast` data is intended as a relatively normal example. # As such, it also serves as a base for some other test data. appcast = create_appcast_xml <<~EOS #{v123_item} #{v122_item} #{v121_item_with_osx_os} #{v120_item_with_macos_os} EOS omitted_items = create_appcast_xml <<~EOS #{v123_item.sub(%r{<(enclosure[^>]+?)\s*?/>}, '<\1 os="not-osx-or-macos" />')} #{v123_item.sub(/(<sparkle:minimumSystemVersion>)[^<]+?</m, '\1100<')} <item> </item> EOS # Set the first item in a copy of `appcast` to a bad `minimumSystemVersion` # value, to test `MacOSVersion::Error` handling. bad_macos_version = appcast.sub( v123_item, v123_item.sub( /(<sparkle:minimumSystemVersion>)[^<]+?</m, '\1Not a macOS version<', ), ) # Set the first item in a copy of `appcast` to the "beta" channel, to test # filtering items by channel using a `strategy` block. beta_channel_item = appcast.sub( v123_item, v123_item.sub( "</title>", "</title>\n<sparkle:channel>beta</sparkle:channel>", ), ) no_versions_item = create_appcast_xml <<~EOS <item> <title>Version</title> <sparkle:minimumSystemVersion>#{item_hashes[:v123][:minimum_system_version]}</sparkle:minimumSystemVersion> <sparkle:releaseNotesLink>#{item_hashes[:v123][:release_notes_link]}</sparkle:releaseNotesLink> <pubDate>#{item_hashes[:v123][:pub_date]}</pubDate> <enclosure url="#{item_hashes[:v123][:url]}" length="12345678" type="application/octet-stream" sparkle:dsaSignature="ABCDEF+GHIJKLMNOPQRSTUVWXYZab/cdefghijklmnopqrst/uvwxyz1234567==" /> </item> EOS no_items = create_appcast_xml undefined_namespace = appcast.sub(/\s*xmlns:sparkle="[^"]+"/, "") { appcast:, omitted_items:, bad_macos_version:, beta_channel_item:, no_versions_item:, no_items:, undefined_namespace:, } end let(:title_regex) { /Version\s+v?(\d+(?:\.\d+)+)\s*$/i } let(:items) do { v124: Homebrew::Livecheck::Strategy::Sparkle::Item.new( title: item_hashes[:v124][:title], release_notes_link: item_hashes[:v124][:release_notes_link], pub_date: Time.parse(item_hashes[:v124][:pub_date]), url: item_hashes[:v124][:url], bundle_version: Homebrew::BundleVersion.new( item_hashes[:v124][:short_version], item_hashes[:v124][:version], ), minimum_system_version: MacOSVersion.new(item_hashes[:v124][:minimum_system_version]), ), v123: Homebrew::Livecheck::Strategy::Sparkle::Item.new( title: item_hashes[:v123][:title], release_notes_link: item_hashes[:v123][:release_notes_link], pub_date: Time.parse(item_hashes[:v123][:pub_date]), url: item_hashes[:v123][:url], bundle_version: Homebrew::BundleVersion.new( item_hashes[:v123][:short_version], item_hashes[:v123][:version], ), minimum_system_version: MacOSVersion.new(item_hashes[:v123][:minimum_system_version]), ), v122: Homebrew::Livecheck::Strategy::Sparkle::Item.new( title: item_hashes[:v122][:title], link: item_hashes[:v122][:link], release_notes_link: item_hashes[:v122][:release_notes_link], # `#items_from_content` falls back to a default `pub_date` when # one isn't provided or can't be successfully parsed. pub_date: Time.new(0), url: item_hashes[:v122][:link], bundle_version: Homebrew::BundleVersion.new( item_hashes[:v122][:short_version], item_hashes[:v122][:version], ), minimum_system_version: MacOSVersion.new(item_hashes[:v122][:minimum_system_version]), ), v121: Homebrew::Livecheck::Strategy::Sparkle::Item.new( title: item_hashes[:v121][:title], release_notes_link: item_hashes[:v121][:release_notes_link], pub_date: Time.parse(item_hashes[:v121][:pub_date]), os: item_hashes[:v121][:os], url: item_hashes[:v121][:url], bundle_version: Homebrew::BundleVersion.new( item_hashes[:v121][:short_version], item_hashes[:v121][:version], ), minimum_system_version: MacOSVersion.new(item_hashes[:v121][:minimum_system_version]), ), v120: Homebrew::Livecheck::Strategy::Sparkle::Item.new( title: item_hashes[:v120][:title], release_notes_link: item_hashes[:v120][:release_notes_link], pub_date: Time.parse(item_hashes[:v120][:pub_date]), os: item_hashes[:v120][:os], url: item_hashes[:v120][:url], bundle_version: Homebrew::BundleVersion.new( item_hashes[:v120][:short_version], item_hashes[:v120][:version], ), minimum_system_version: MacOSVersion.new(item_hashes[:v120][:minimum_system_version]), ), } end let(:item_arrays) do item_arrays = { appcast: [ items[:v123], items[:v122], items[:v121], items[:v120], ], appcast_sorted: [ items[:v123], items[:v121], items[:v120], items[:v122], ], } bad_macos_version_item = items[:v123].clone bad_macos_version_item.minimum_system_version = nil item_arrays[:bad_macos_version] = [ bad_macos_version_item, items[:v122], items[:v121], items[:v120], ] beta_channel_item = items[:v123].clone beta_channel_item.channel = "beta" item_arrays[:beta_channel_item] = [ beta_channel_item, items[:v122], items[:v121], items[:v120], ] no_versions_item = items[:v123].clone no_versions_item.title = "Version" no_versions_item.bundle_version = nil item_arrays[:no_versions_item] = [no_versions_item] item_arrays end let(:versions) { [items[:v123].nice_version] } describe "::match?" do it "returns true for an HTTP URL" do expect(sparkle.match?(appcast_url)).to be true end it "returns false for a non-HTTP URL" do expect(sparkle.match?(non_http_url)).to be false end end describe "::items_from_content" do let(:items_from_appcast) { sparkle.items_from_content(xml[:appcast]) } it "returns nil if content is blank" do expect(sparkle.items_from_content("")).to eq([]) end it "returns an array of Items when given XML data" do expect(items_from_appcast).to eq(item_arrays[:appcast]) expect(items_from_appcast[0].title).to eq(item_hashes[:v123][:title]) expect(items_from_appcast[0].pub_date).to eq(Time.parse(item_hashes[:v123][:pub_date])) expect(items_from_appcast[0].url).to eq(item_hashes[:v123][:url]) expect(items_from_appcast[0].short_version).to eq(item_hashes[:v123][:short_version]) expect(items_from_appcast[0].version).to eq(item_hashes[:v123][:version]) expect(sparkle.items_from_content(xml[:bad_macos_version])).to eq(item_arrays[:bad_macos_version]) expect(sparkle.items_from_content(xml[:beta_channel_item])).to eq(item_arrays[:beta_channel_item]) expect(sparkle.items_from_content(xml[:no_versions_item])).to eq(item_arrays[:no_versions_item]) end end describe "::filter_items" do let(:items_non_mac_os) do item = items[:v124].clone item.os = "not-osx-or-macos" item_arrays[:appcast] + [item] end let(:items_prerelease_minimum_system_version) do item = items[:v124].clone item.minimum_system_version = MacOSVersion.new("100") item_arrays[:appcast] + [item] end it "removes items with a non-mac OS" do expect(sparkle.filter_items(items_non_mac_os)).to eq(item_arrays[:appcast]) end it "removes items with a prerelease minimumSystemVersion" do expect(sparkle.filter_items(items_prerelease_minimum_system_version)).to eq(item_arrays[:appcast]) end end describe "::sort_items" do it "returns a sorted array of items" do expect(sparkle.sort_items(item_arrays[:appcast])).to eq(item_arrays[:appcast_sorted]) end end # `#versions_from_content` sorts items by `pub_date` and `bundle_version`, so # these tests have to account for this behavior in the expected output. # For example, the version 122 item doesn't have a parseable `pub_date` and # the substituted default will cause it to be sorted last. describe "::versions_from_content" do let(:subbed_items) { item_arrays[:appcast_sorted].map { |item| item.nice_version.sub("1", "0") } } it "returns an array of version strings when given content" do expect(sparkle.versions_from_content(xml[:appcast])).to eq(versions) expect(sparkle.versions_from_content(xml[:omitted_items])).to eq([]) expect(sparkle.versions_from_content(xml[:beta_channel_item])).to eq(versions) expect(sparkle.versions_from_content(xml[:no_versions_item])).to eq([]) expect(sparkle.versions_from_content(xml[:undefined_namespace])).to eq(versions) end it "returns an empty array if no items are found" do expect(sparkle.versions_from_content(xml[:no_items])).to eq([]) end it "returns an array of version strings when given content and a block" do # Returning a string from block expect( sparkle.versions_from_content(xml[:appcast]) do |item| item.nice_version&.sub("1", "0") end, ).to eq([subbed_items[0]]) # Returning an array of strings from block expect( sparkle.versions_from_content(xml[:appcast]) do |items| items.map { |item| item.nice_version&.sub("1", "0") } end, ).to eq(subbed_items) expect( sparkle.versions_from_content(xml[:beta_channel_item]) do |items| items.find { |item| item.channel.nil? }&.nice_version end, ).to eq([items[:v121].nice_version]) end it "returns an array of version strings when given content, a regex and a block" do # Returning a string from the block expect( sparkle.versions_from_content(xml[:appcast], title_regex) do |item, regex| item.title[regex, 1] end, ).to eq([item_hashes[:v123][:short_version]]) expect( sparkle.versions_from_content(xml[:appcast], title_regex) do |items, regex| next if (item = items[0]).blank? match = item&.title&.match(regex) next if match.blank? "#{match[1]},#{item.version}" end, ).to eq(["#{item_hashes[:v123][:short_version]},#{item_hashes[:v123][:version]}"]) # Returning an array of strings from the block expect( sparkle.versions_from_content(xml[:appcast], title_regex) do |item, regex| [item.title[regex, 1]] end, ).to eq([item_hashes[:v123][:short_version]]) expect( sparkle.versions_from_content(xml[:appcast], &:short_version), ).to eq([item_hashes[:v123][:short_version]]) expect( sparkle.versions_from_content(xml[:appcast], title_regex) do |items, regex| items.map { |item| item.title[regex, 1] } end, ).to eq(item_arrays[:appcast_sorted].map(&:short_version)) end it "allows a nil return from a block" do expect( sparkle.versions_from_content(xml[:appcast]) do |item| _ = item # To appease `brew style` without modifying arg name next end, ).to eq([]) end it "errors on an invalid return type from a block" do expect do sparkle.versions_from_content(xml[:appcast]) do |item| _ = item # To appease `brew style` without modifying arg name 123 end end.to raise_error(TypeError, Homebrew::Livecheck::Strategy::INVALID_BLOCK_RETURN_VALUE_MSG) end it "errors if the first block argument uses an unhandled name" do expect { sparkle.versions_from_content(xml[:appcast]) { |something| something } } .to raise_error("First argument of Sparkle `strategy` block must be `item` or `items`") end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/strategy/launchpad_spec.rb
Library/Homebrew/test/livecheck/strategy/launchpad_spec.rb
# frozen_string_literal: true require "livecheck/strategy/launchpad" RSpec.describe Homebrew::Livecheck::Strategy::Launchpad do subject(:launchpad) { described_class } let(:launchpad_urls) do { version_dir: "https://launchpad.net/abc/1.2/1.2.3/+download/abc-1.2.3.tar.gz", trunk: "https://launchpad.net/abc/trunk/1.2.3/+download/abc-1.2.3.tar.gz", code_subdomain: "https://code.launchpad.net/abc/1.2/1.2.3/+download/abc-1.2.3.tar.gz", } end let(:non_launchpad_url) { "https://brew.sh/test" } let(:generated) do { url: "https://launchpad.net/abc/", } end describe "::match?" do it "returns true for a Launchpad URL" do expect(launchpad.match?(launchpad_urls[:version_dir])).to be true expect(launchpad.match?(launchpad_urls[:trunk])).to be true expect(launchpad.match?(launchpad_urls[:code_subdomain])).to be true end it "returns false for a non-Launchpad URL" do expect(launchpad.match?(non_launchpad_url)).to be false end end describe "::generate_input_values" do it "returns a hash containing url and regex for an Launchpad URL" do expect(launchpad.generate_input_values(launchpad_urls[:version_dir])).to eq(generated) expect(launchpad.generate_input_values(launchpad_urls[:trunk])).to eq(generated) expect(launchpad.generate_input_values(launchpad_urls[:code_subdomain])).to eq(generated) end it "returns an empty hash for a non-Launchpad URL" do expect(launchpad.generate_input_values(non_launchpad_url)).to eq({}) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/strategy/cpan_spec.rb
Library/Homebrew/test/livecheck/strategy/cpan_spec.rb
# frozen_string_literal: true require "livecheck/strategy" RSpec.describe Homebrew::Livecheck::Strategy::Cpan do subject(:cpan) { described_class } let(:cpan_urls) do { no_subdirectory: "https://cpan.metacpan.org/authors/id/H/HO/HOMEBREW/Brew-v1.2.3.tar.gz", with_subdirectory: "https://cpan.metacpan.org/authors/id/H/HO/HOMEBREW/brew/brew-v1.2.3.tar.gz", no_subdirectory_www: "https://www.cpan.org/authors/id/H/HO/HOMEBREW/Brew-v1.2.3.tar.gz", with_subdirectory_www: "https://www.cpan.org/authors/id/H/HO/HOMEBREW/brew/brew-v1.2.3.tar.gz", } end let(:non_cpan_url) { "https://brew.sh/test" } let(:generated) do { no_subdirectory: { url: "https://www.cpan.org/authors/id/H/HO/HOMEBREW/", regex: /href=.*?Brew[._-]v?(\d+(?:\.\d+)*)\.t/i, }, with_subdirectory: { url: "https://www.cpan.org/authors/id/H/HO/HOMEBREW/brew/", regex: /href=.*?brew[._-]v?(\d+(?:\.\d+)*)\.t/i, }, } end describe "::match?" do it "returns true for a CPAN URL" do expect(cpan.match?(cpan_urls[:no_subdirectory])).to be true expect(cpan.match?(cpan_urls[:with_subdirectory])).to be true expect(cpan.match?(cpan_urls[:no_subdirectory_www])).to be true expect(cpan.match?(cpan_urls[:with_subdirectory_www])).to be true end it "returns false for a non-CPAN URL" do expect(cpan.match?(non_cpan_url)).to be false end end describe "::generate_input_values" do it "returns a hash containing url and regex for a CPAN URL" do expect(cpan.generate_input_values(cpan_urls[:no_subdirectory])).to eq(generated[:no_subdirectory]) expect(cpan.generate_input_values(cpan_urls[:with_subdirectory])).to eq(generated[:with_subdirectory]) expect(cpan.generate_input_values(cpan_urls[:no_subdirectory_www])).to eq(generated[:no_subdirectory]) expect(cpan.generate_input_values(cpan_urls[:with_subdirectory_www])).to eq(generated[:with_subdirectory]) end it "returns an empty hash for a non-CPAN URL" do expect(cpan.generate_input_values(non_cpan_url)).to eq({}) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/strategy/github_latest_spec.rb
Library/Homebrew/test/livecheck/strategy/github_latest_spec.rb
# frozen_string_literal: true require "livecheck/strategy/github_releases" require "livecheck/strategy/github_latest" RSpec.describe Homebrew::Livecheck::Strategy::GithubLatest do subject(:github_latest) { described_class } let(:github_urls) do { release_artifact: "https://github.com/abc/def/releases/download/1.2.3/ghi-1.2.3.tar.gz", tag_archive: "https://github.com/abc/def/archive/v1.2.3.tar.gz", repository_upload: "https://github.com/downloads/abc/def/ghi-1.2.3.tar.gz", } end let(:non_github_url) { "https://brew.sh/test" } let(:generated) do { url: "https://api.github.com/repos/abc/def/releases/latest", username: "abc", repository: "def", } end describe "::match?" do it "returns true for a GitHub release artifact URL" do expect(github_latest.match?(github_urls[:release_artifact])).to be true end it "returns true for a GitHub tag archive URL" do expect(github_latest.match?(github_urls[:tag_archive])).to be true end it "returns true for a GitHub repository upload URL" do expect(github_latest.match?(github_urls[:repository_upload])).to be true end it "returns false for a non-GitHub URL" do expect(github_latest.match?(non_github_url)).to be false end end describe "::generate_input_values" do it "returns a hash containing a url and regex for a GitHub release artifact URL" do expect(github_latest.generate_input_values(github_urls[:release_artifact])).to eq(generated) end it "returns a hash containing a url and regex for a GitHub tag archive URL" do expect(github_latest.generate_input_values(github_urls[:tag_archive])).to eq(generated) end it "returns a hash containing a url and regex for a GitHub repository upload URL" do expect(github_latest.generate_input_values(github_urls[:repository_upload])).to eq(generated) end it "returns an empty hash for a non-GitHub URL" do expect(github_latest.generate_input_values(non_github_url)).to eq({}) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/strategy/sourceforge_spec.rb
Library/Homebrew/test/livecheck/strategy/sourceforge_spec.rb
# frozen_string_literal: true require "livecheck/strategy/sourceforge" RSpec.describe Homebrew::Livecheck::Strategy::Sourceforge do subject(:sourceforge) { described_class } let(:sourceforge_urls) do { typical: "https://downloads.sourceforge.net/project/abc/def-1.2.3.tar.gz", rss: "https://sourceforge.net/projects/abc/rss", rss_with_path: "https://sourceforge.net/projects/abc/rss?path=/def", } end let(:non_sourceforge_url) { "https://brew.sh/test" } let(:generated) do { typical: { url: "https://sourceforge.net/projects/abc/rss", regex: %r{url=.*?/abc/files/.*?[-_/](\d+(?:[-.]\d+)+)[-_/%.]}i, }, rss: { regex: %r{url=.*?/abc/files/.*?[-_/](\d+(?:[-.]\d+)+)[-_/%.]}i, }, } end describe "::match?" do it "returns true for a SourceForge URL" do expect(sourceforge.match?(sourceforge_urls[:typical])).to be true expect(sourceforge.match?(sourceforge_urls[:rss])).to be true expect(sourceforge.match?(sourceforge_urls[:rss_with_path])).to be true end it "returns false for a non-SourceForge URL" do expect(sourceforge.match?(non_sourceforge_url)).to be false end end describe "::generate_input_values" do it "returns a hash containing url and regex for an Apache URL" do expect(sourceforge.generate_input_values(sourceforge_urls[:typical])).to eq(generated[:typical]) expect(sourceforge.generate_input_values(sourceforge_urls[:rss])).to eq(generated[:rss]) expect(sourceforge.generate_input_values(sourceforge_urls[:rss_with_path])).to eq(generated[:rss]) end it "returns an empty hash for a non-Apache URL" do expect(sourceforge.generate_input_values(non_sourceforge_url)).to eq({}) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/strategy/gnu_spec.rb
Library/Homebrew/test/livecheck/strategy/gnu_spec.rb
# frozen_string_literal: true require "livecheck/strategy/gnu" RSpec.describe Homebrew::Livecheck::Strategy::Gnu do subject(:gnu) { described_class } let(:gnu_urls) do { no_version_dir: "https://ftpmirror.gnu.org/gnu/abc/abc-1.2.3.tar.gz", software_page: "https://www.gnu.org/software/abc/", subdomain: "https://abc.gnu.org", savannah: "https://download.savannah.gnu.org/releases/abc/abc-1.2.3.tar.gz", } end let(:non_gnu_url) { "https://brew.sh/test" } let(:generated) do { no_version_dir: { url: "https://ftpmirror.gnu.org/gnu/abc/", regex: %r{href=.*?abc[._-]v?(\d+(?:\.\d+)*)(?:\.[a-z]+|/)}i, }, software_page: { url: "https://ftpmirror.gnu.org/gnu/abc/", regex: %r{href=.*?abc[._-]v?(\d+(?:\.\d+)*)(?:\.[a-z]+|/)}i, }, subdomain: { url: "https://ftpmirror.gnu.org/gnu/abc/", regex: %r{href=.*?abc[._-]v?(\d+(?:\.\d+)*)(?:\.[a-z]+|/)}i, }, savannah: {}, } end describe "::match?" do it "returns true for a [non-Savannah] GNU URL" do expect(gnu.match?(gnu_urls[:no_version_dir])).to be true expect(gnu.match?(gnu_urls[:software_page])).to be true expect(gnu.match?(gnu_urls[:subdomain])).to be true end it "returns false for a Savannah GNU URL" do expect(gnu.match?(gnu_urls[:savannah])).to be false end it "returns false for a non-GNU URL (not nongnu.org)" do expect(gnu.match?(non_gnu_url)).to be false end end describe "::generate_input_values" do it "returns a hash containing url and regex for a [non-Savannah] GNU URL" do expect(gnu.generate_input_values(gnu_urls[:no_version_dir])).to eq(generated[:no_version_dir]) expect(gnu.generate_input_values(gnu_urls[:software_page])).to eq(generated[:software_page]) expect(gnu.generate_input_values(gnu_urls[:subdomain])).to eq(generated[:subdomain]) end it "returns an empty hash for a Savannah GNU URL" do expect(gnu.generate_input_values(gnu_urls[:savannah])).to eq(generated[:savannah]) end it "returns an empty hash for a non-GNU URL (not nongnu.org)" do expect(gnu.generate_input_values(non_gnu_url)).to eq({}) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/strategy/json_spec.rb
Library/Homebrew/test/livecheck/strategy/json_spec.rb
# frozen_string_literal: true require "livecheck/strategy" RSpec.describe Homebrew::Livecheck::Strategy::Json do subject(:json) { described_class } let(:http_url) { "https://brew.sh/blog/" } let(:non_http_url) { "ftp://brew.sh/" } let(:regex) { /^v?(\d+(?:\.\d+)+)$/i } let(:content) do <<~EOS { "versions": [ { "version": "1.1.2" }, { "version": "1.1.2b" }, { "version": "1.1.2a" }, { "version": "1.1.1" }, { "version": "1.1.0" }, { "version": "1.1.0-rc3" }, { "version": "1.1.0-rc2" }, { "version": "1.1.0-rc1" }, { "version": "1.0.x-last" }, { "version": "1.0.3" }, { "version": "1.0.3-rc3" }, { "version": "1.0.3-rc2" }, { "version": "1.0.3-rc1" }, { "version": "1.0.2" }, { "version": "1.0.2-rc1" }, { "version": "1.0.1" }, { "version": "1.0.1-rc1" }, { "version": "1.0.0" }, { "version": "1.0.0-rc1" }, { "other": "version is omitted from this object for testing" } ] } EOS end let(:content_simple) { '{"version":"1.2.3"}' } let(:content_matches) { ["1.1.2", "1.1.1", "1.1.0", "1.0.3", "1.0.2", "1.0.1", "1.0.0"] } let(:content_simple_matches) { ["1.2.3"] } let(:find_versions_return_hash) do { matches: { "1.1.2" => Version.new("1.1.2"), "1.1.1" => Version.new("1.1.1"), "1.1.0" => Version.new("1.1.0"), "1.0.3" => Version.new("1.0.3"), "1.0.2" => Version.new("1.0.2"), "1.0.1" => Version.new("1.0.1"), "1.0.0" => Version.new("1.0.0"), }, regex:, url: http_url, } end let(:find_versions_cached_return_hash) do find_versions_return_hash.merge({ cached: true }) end describe "::match?" do it "returns true for an HTTP URL" do expect(json.match?(http_url)).to be true end it "returns false for a non-HTTP URL" do expect(json.match?(non_http_url)).to be false end end describe "::parse_json" do it "returns an object when given valid content" do expect(json.parse_json(content_simple)).to be_an_instance_of(Hash) end end describe "::versions_from_content" do it "returns an empty array when given a block but content is blank" do expect(json.versions_from_content("", regex) { "1.2.3" }).to eq([]) end it "errors if provided content is not valid JSON" do expect { json.versions_from_content("not valid JSON") { [] } } .to raise_error(RuntimeError, "Content could not be parsed as JSON.") end it "returns an array of version strings when given content and a block" do # Returning a string from block expect(json.versions_from_content(content_simple) { |json| json["version"] }).to eq(content_simple_matches) expect(json.versions_from_content(content_simple, regex) do |json| json["version"][regex, 1] end).to eq(content_simple_matches) # Returning an array of strings from block expect(json.versions_from_content(content, regex) do |json, regex| json["versions"].select { |item| item["version"]&.match?(regex) } .map { |item| item["version"][regex, 1] } end).to eq(content_matches) end it "allows a nil return from a block" do expect(json.versions_from_content(content_simple, regex) { next }).to eq([]) end it "errors on an invalid return type from a block" do expect { json.versions_from_content(content_simple, regex) { 123 } } .to raise_error(TypeError, Homebrew::Livecheck::Strategy::INVALID_BLOCK_RETURN_VALUE_MSG) end end describe "::find_versions?" do it "finds versions in provided_content using a block" do expect(json.find_versions(url: http_url, regex:, provided_content: content) do |json, regex| json["versions"].select { |item| item["version"]&.match?(regex) } .map { |item| item["version"][regex, 1] } end).to eq(find_versions_cached_return_hash) # NOTE: A regex should be provided using the `#regex` method in a # `livecheck` block but we're using a regex literal in the `strategy` # block here simply to ensure this method works as expected when a # regex isn't provided. expect(json.find_versions(url: http_url, provided_content: content) do |json| regex = /^v?(\d+(?:\.\d+)+)$/i json["versions"].select { |item| item["version"]&.match?(regex) } .map { |item| item["version"][regex, 1] } end).to eq(find_versions_cached_return_hash.merge({ regex: nil })) end it "errors if a block is not provided" do expect { json.find_versions(url: http_url, provided_content: content) } .to raise_error(ArgumentError, "Json requires a `strategy` block") end it "returns default match_data when url is blank" do expect(json.find_versions(url: "") { "1.2.3" }) .to eq({ matches: {}, regex: nil, url: "" }) end it "returns default match_data when content is blank" do expect(json.find_versions(url: http_url, provided_content: "") { "1.2.3" }) .to eq({ matches: {}, regex: nil, url: http_url, cached: true }) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/livecheck/strategy/yaml_spec.rb
Library/Homebrew/test/livecheck/strategy/yaml_spec.rb
# frozen_string_literal: true require "livecheck/strategy" RSpec.describe Homebrew::Livecheck::Strategy::Yaml do subject(:yaml) { described_class } let(:http_url) { "https://brew.sh/blog/" } let(:non_http_url) { "ftp://brew.sh/" } let(:regex) { /^v?(\d+(?:\.\d+)+)$/i } let(:content) do <<~EOS versions: - version: 1.1.2 - version: 1.1.2b - version: 1.1.2a - version: 1.1.1 - version: 1.1.0 - version: 1.1.0-rc3 - version: 1.1.0-rc2 - version: 1.1.0-rc1 - version: 1.0.x-last - version: 1.0.3 - version: 1.0.3-rc3 - version: 1.0.3-rc2 - version: 1.0.3-rc1 - version: 1.0.2 - version: 1.0.2-rc1 - version: 1.0.1 - version: 1.0.1-rc1 - version: 1.0.0 - version: 1.0.0-rc1 - other: version is omitted from this object for testing EOS end let(:content_simple) { "version: 1.2.3" } # This should produce a `Psych::SyntaxError` (`did not find expected comment # or line break while scanning a block scalar`) let(:content_invalid) { ">~" } let(:content_matches) { ["1.1.2", "1.1.1", "1.1.0", "1.0.3", "1.0.2", "1.0.1", "1.0.0"] } let(:content_simple_matches) { ["1.2.3"] } let(:find_versions_return_hash) do { matches: { "1.1.2" => Version.new("1.1.2"), "1.1.1" => Version.new("1.1.1"), "1.1.0" => Version.new("1.1.0"), "1.0.3" => Version.new("1.0.3"), "1.0.2" => Version.new("1.0.2"), "1.0.1" => Version.new("1.0.1"), "1.0.0" => Version.new("1.0.0"), }, regex:, url: http_url, } end let(:find_versions_cached_return_hash) do find_versions_return_hash.merge({ cached: true }) end describe "::match?" do it "returns true for an HTTP URL" do expect(yaml.match?(http_url)).to be true end it "returns false for a non-HTTP URL" do expect(yaml.match?(non_http_url)).to be false end end describe "::parse_yaml" do it "returns an object when given valid content" do expect(yaml.parse_yaml(content_simple)).to be_an_instance_of(Hash) end end describe "::versions_from_content" do it "returns an empty array when given a block but content is blank" do expect(yaml.versions_from_content("", regex) { "1.2.3" }).to eq([]) end it "errors if provided content is not valid YAML" do expect { yaml.versions_from_content(content_invalid) { [] } } .to raise_error(RuntimeError, "Content could not be parsed as YAML.") end it "returns an array of version strings when given content and a block" do # Returning a string from block expect(yaml.versions_from_content(content_simple) { |yaml| yaml["version"] }).to eq(content_simple_matches) expect(yaml.versions_from_content(content_simple, regex) do |yaml| yaml["version"][regex, 1] end).to eq(content_simple_matches) # Returning an array of strings from block expect(yaml.versions_from_content(content, regex) do |yaml, regex| yaml["versions"].select { |item| item["version"]&.match?(regex) } .map { |item| item["version"][regex, 1] } end).to eq(content_matches) end it "allows a nil return from a block" do expect(yaml.versions_from_content(content_simple, regex) { next }).to eq([]) end it "errors if a block uses two arguments but a regex is not given" do expect { yaml.versions_from_content(content_simple) { |yaml, regex| yaml["version"][regex, 1] } } .to raise_error("Two arguments found in `strategy` block but no regex provided.") end it "errors on an invalid return type from a block" do expect { yaml.versions_from_content(content_simple, regex) { 123 } } .to raise_error(TypeError, Homebrew::Livecheck::Strategy::INVALID_BLOCK_RETURN_VALUE_MSG) end end describe "::find_versions?" do it "finds versions in provided_content using a block" do expect(yaml.find_versions(url: http_url, regex:, provided_content: content) do |yaml, regex| yaml["versions"].select { |item| item["version"]&.match?(regex) } .map { |item| item["version"][regex, 1] } end).to eq(find_versions_cached_return_hash) # NOTE: A regex should be provided using the `#regex` method in a # `livecheck` block but we're using a regex literal in the `strategy` # block here simply to ensure this method works as expected when a # regex isn't provided. expect(yaml.find_versions(url: http_url, provided_content: content) do |yaml| regex = /^v?(\d+(?:\.\d+)+)$/i yaml["versions"].select { |item| item["version"]&.match?(regex) } .map { |item| item["version"][regex, 1] } end).to eq(find_versions_cached_return_hash.merge({ regex: nil })) end it "errors if a block is not provided" do expect { yaml.find_versions(url: http_url, provided_content: content) } .to raise_error(ArgumentError, "Yaml requires a `strategy` block") end it "returns default match_data when url is blank" do expect(yaml.find_versions(url: "") { "1.2.3" }) .to eq({ matches: {}, regex: nil, url: "" }) end it "returns default match_data when content is blank" do expect(yaml.find_versions(url: http_url, provided_content: "") { "1.2.3" }) .to eq({ matches: {}, regex: nil, url: http_url, cached: true }) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/options/deprecated_option_spec.rb
Library/Homebrew/test/options/deprecated_option_spec.rb
# frozen_string_literal: true require "options" RSpec.describe DeprecatedOption do subject(:option) { described_class.new("foo", "bar") } specify "#old" do expect(option.old).to eq("foo") end specify "#old_flag" do # rubocop:todo RSpec/AggregateExamples expect(option.old_flag).to eq("--foo") end specify "#current" do # rubocop:todo RSpec/AggregateExamples expect(option.current).to eq("bar") end specify "#current_flag" do # rubocop:todo RSpec/AggregateExamples expect(option.current_flag).to eq("--bar") end specify "equality" do foobar = described_class.new("foo", "bar") boofar = described_class.new("boo", "far") expect(foobar).to eq(option) expect(option).to eq(foobar) expect(boofar).not_to eq(option) expect(option).not_to eq(boofar) end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/options/option_spec.rb
Library/Homebrew/test/options/option_spec.rb
# frozen_string_literal: true require "options" RSpec.describe Option do subject(:option) { described_class.new("foo") } specify "#to_s" do expect(option.to_s).to eq("--foo") end specify "equality" do foo = described_class.new("foo") bar = described_class.new("bar") expect(option).to eq(foo) expect(option).not_to eq(bar) expect(option).to eql(foo) expect(option).not_to eql(bar) end specify "#description" do # rubocop:todo RSpec/AggregateExamples expect(option.description).to be_empty expect(described_class.new("foo", "foo").description).to eq("foo") end specify "#inspect" do # rubocop:todo RSpec/AggregateExamples expect(option.inspect).to eq("#<Option: \"--foo\">") end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/version/parser_spec.rb
Library/Homebrew/test/version/parser_spec.rb
# frozen_string_literal: true require "version/parser" RSpec.describe Version::Parser do specify "::new" do expect { described_class.new } .to raise_error("Version::Parser is declared as abstract; it cannot be instantiated") end describe Version::RegexParser do specify "::new" do expect { described_class.new(/[._-](\d+(?:\.\d+)+)/) } .to raise_error("Version::RegexParser is declared as abstract; it cannot be instantiated") end specify "::process_spec" do expect { described_class.process_spec(Pathname(TEST_TMPDIR)) } .to raise_error("The method `process_spec` on #<Class:Version::RegexParser> is declared as `abstract`. " \ "It does not have an implementation.") end end describe Version::UrlParser do specify "::new" do expect { described_class.new(/[._-](\d+(?:\.\d+)+)/) }.not_to raise_error end specify "::process_spec" do expect(described_class.process_spec(Pathname("#{TEST_TMPDIR}/testdir-0.1.test"))) .to eq("#{TEST_TMPDIR}/testdir-0.1.test") expect(described_class.process_spec(Pathname("https://sourceforge.net/foo_bar-1.21.tar.gz/download"))) .to eq("https://sourceforge.net/foo_bar-1.21.tar.gz/download") expect(described_class.process_spec(Pathname("https://sf.net/foo_bar-1.21.tar.gz/download"))) .to eq("https://sf.net/foo_bar-1.21.tar.gz/download") expect(described_class.process_spec(Pathname("https://brew.sh/testball-0.1"))) .to eq("https://brew.sh/testball-0.1") expect(described_class.process_spec(Pathname("https://brew.sh/testball-0.1.tgz"))) .to eq("https://brew.sh/testball-0.1.tgz") end end describe Version::StemParser do before { Pathname("#{TEST_TMPDIR}/testdir-0.1.test").mkpath } after { Pathname("#{TEST_TMPDIR}/testdir-0.1.test").unlink } specify "::new" do expect { described_class.new(/[._-](\d+(?:\.\d+)+)/) }.not_to raise_error end describe "::process_spec" do it "works with directories" do expect(described_class.process_spec(Pathname("#{TEST_TMPDIR}/testdir-0.1.test"))).to eq("testdir-0.1.test") end it "works with SourceForge URLs with /download suffix" do expect(described_class.process_spec(Pathname("https://sourceforge.net/foo_bar-1.21.tar.gz/download"))) .to eq("foo_bar-1.21") expect(described_class.process_spec(Pathname("https://sf.net/foo_bar-1.21.tar.gz/download"))) .to eq("foo_bar-1.21") end it "works with URLs without file extension" do expect(described_class.process_spec(Pathname("https://brew.sh/testball-0.1"))).to eq("testball-0.1") end it "works with URLs with file extension" do expect(described_class.process_spec(Pathname("https://brew.sh/testball-0.1.tgz"))).to eq("testball-0.1") end end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/sorbet/tapioca/config_spec.rb
Library/Homebrew/test/sorbet/tapioca/config_spec.rb
# frozen_string_literal: true require "bundler" require "yaml" RSpec.describe "Tapioca Config", type: :system do let(:config) { YAML.load_file(File.join(__dir__, "../../../sorbet/tapioca/config.yml")) } it "only excludes dependencies" do exclusions = config.dig("gem", "exclude") dependencies = Bundler::Definition.build( HOMEBREW_LIBRARY_PATH/"Gemfile", HOMEBREW_LIBRARY_PATH/"Gemfile.lock", false, ).resolve.names expect(exclusions - dependencies).to be_empty end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/update-sponsors_spec.rb
Library/Homebrew/test/dev-cmd/update-sponsors_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/update-sponsors" RSpec.describe Homebrew::DevCmd::UpdateSponsors do it_behaves_like "parseable arguments" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/pr-pull_spec.rb
Library/Homebrew/test/dev-cmd/pr-pull_spec.rb
# frozen_string_literal: true require "dev-cmd/pr-pull" require "utils/git" require "tap" require "cmd/shared_examples/args_parse" RSpec.describe Homebrew::DevCmd::PrPull do include FileUtils let(:pr_pull) { described_class.new(["foo"]) } let(:formula_rebuild) do <<~EOS class Foo < Formula desc "Helpful description" url "https://brew.sh/foo-1.0.tgz" end EOS end let(:formula_revision) do <<~EOS class Foo < Formula url "https://brew.sh/foo-1.0.tgz" revision 1 end EOS end let(:formula_version) do <<~EOS class Foo < Formula url "https://brew.sh/foo-2.0.tgz" end EOS end let(:formula) do <<~EOS class Foo < Formula url "https://brew.sh/foo-1.0.tgz" end EOS end let(:cask_rebuild) do <<~EOS cask "food" do desc "Helpful description" version "1.0" sha256 "a" url "https://brew.sh/food-\#{version}.tgz" end EOS end let(:cask_checksum) do <<~EOS cask "food" do desc "Helpful description" version "1.0" sha256 "b" url "https://brew.sh/food-\#{version}.tgz" end EOS end let(:cask_version) do <<~EOS cask "food" do version "2.0" sha256 "a" url "https://brew.sh/food-\#{version}.tgz" end EOS end let(:cask) do <<~EOS cask "food" do version "1.0" sha256 "a" url "https://brew.sh/food-\#{version}.tgz" end EOS end let(:tap) { Tap.fetch("Homebrew", "foo") } let(:formula_file) { tap.path/"Formula/foo.rb" } let(:cask_file) { tap.cask_dir/"food.rb" } let(:path) { Pathname(HOMEBREW_TAP_DIRECTORY/"homebrew/homebrew-foo") } it_behaves_like "parseable arguments" describe "#autosquash!" do it "squashes a formula or cask correctly" do secondary_author = "Someone Else <me@example.com>" (tap.path/"Formula").mkpath formula_file.write(formula) cd tap.path do safe_system Utils::Git.git, "init" safe_system Utils::Git.git, "add", formula_file safe_system Utils::Git.git, "commit", "-m", "foo 1.0 (new formula)" original_hash = `git rev-parse HEAD`.chomp File.write(formula_file, formula_revision) safe_system Utils::Git.git, "commit", formula_file, "-m", "revision" File.write(formula_file, formula_version) safe_system Utils::Git.git, "commit", formula_file, "-m", "version", "--author=#{secondary_author}" pr_pull.autosquash!(original_hash, tap:) expect(tap.git_repository.commit_message).to include("foo 2.0") expect(tap.git_repository.commit_message).to include("Co-authored-by: #{secondary_author}") end (path/"Casks").mkpath cask_file.write(cask) cd path do safe_system Utils::Git.git, "add", cask_file safe_system Utils::Git.git, "commit", "-m", "food 1.0 (new cask)" original_hash = `git rev-parse HEAD`.chomp File.write(cask_file, cask_rebuild) safe_system Utils::Git.git, "commit", cask_file, "-m", "rebuild" File.write(cask_file, cask_version) safe_system Utils::Git.git, "commit", cask_file, "-m", "version", "--author=#{secondary_author}" pr_pull.autosquash!(original_hash, tap:) git_repo = GitRepository.new(path) expect(git_repo.commit_message).to include("food 2.0") expect(git_repo.commit_message).to include("Co-authored-by: #{secondary_author}") end end end describe "#signoff!" do it "signs off a formula or cask" do (tap.path/"Formula").mkpath formula_file.write(formula) cd tap.path do safe_system Utils::Git.git, "init" safe_system Utils::Git.git, "add", formula_file safe_system Utils::Git.git, "commit", "-m", "foo 1.0 (new formula)" end pr_pull.signoff!(tap.git_repository) expect(tap.git_repository.commit_message).to include("Signed-off-by:") (path/"Casks").mkpath cask_file.write(cask) cd path do safe_system Utils::Git.git, "add", cask_file safe_system Utils::Git.git, "commit", "-m", "food 1.0 (new cask)" end pr_pull.signoff!(tap.git_repository) expect(tap.git_repository.commit_message).to include("Signed-off-by:") end end describe "#get_package" do it "returns a formula" do expect(pr_pull.get_package(tap, "foo", formula_file, formula)).to be_a(Formula) end it "returns nil for an unknown formula" do expect(pr_pull.get_package(tap, "foo", formula_file, "")).to be_nil end it "returns a cask" do expect(pr_pull.get_package(tap, "foo", cask_file, cask)).to be_a(Cask::Cask) end it "returns nil for an unknown cask" do expect(pr_pull.get_package(tap, "foo", cask_file, "")).to be_nil end end describe "#determine_bump_subject" do it "correctly bumps a new formula" do expect(pr_pull.determine_bump_subject("", formula, formula_file)).to eq("foo 1.0 (new formula)") end it "correctly bumps a new cask" do expect(pr_pull.determine_bump_subject("", cask, cask_file)).to eq("food 1.0 (new cask)") end it "correctly bumps a formula version" do expect(pr_pull.determine_bump_subject(formula, formula_version, formula_file)).to eq("foo 2.0") end it "correctly bumps a cask version" do expect(pr_pull.determine_bump_subject(cask, cask_version, cask_file)).to eq("food 2.0") end it "correctly bumps a cask checksum" do expect(pr_pull.determine_bump_subject(cask, cask_checksum, cask_file)).to eq("food: checksum update") end it "correctly bumps a formula revision with reason" do expect(pr_pull.determine_bump_subject( formula, formula_revision, formula_file, reason: "for fun" )).to eq("foo: revision for fun") end it "correctly bumps a formula rebuild" do expect(pr_pull.determine_bump_subject(formula, formula_rebuild, formula_file)).to eq("foo: rebuild") end it "correctly bumps a formula deletion" do expect(pr_pull.determine_bump_subject(formula, "", formula_file)).to eq("foo: delete") end it "correctly bumps a cask deletion" do expect(pr_pull.determine_bump_subject(cask, "", cask_file)).to eq("food: delete") end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/update-test_spec.rb
Library/Homebrew/test/dev-cmd/update-test_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/update-test" RSpec.describe Homebrew::DevCmd::UpdateTest do it_behaves_like "parseable arguments" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/generate-cask-api_spec.rb
Library/Homebrew/test/dev-cmd/generate-cask-api_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/generate-cask-api" RSpec.describe Homebrew::DevCmd::GenerateCaskApi do it_behaves_like "parseable arguments" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/style_spec.rb
Library/Homebrew/test/dev-cmd/style_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/style" RSpec.describe Homebrew::DevCmd::StyleCmd do it_behaves_like "parseable arguments" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/update-python-resources_spec.rb
Library/Homebrew/test/dev-cmd/update-python-resources_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/update-python-resources" RSpec.describe Homebrew::DevCmd::UpdatePythonResources do it_behaves_like "parseable arguments" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/pr-automerge_spec.rb
Library/Homebrew/test/dev-cmd/pr-automerge_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/pr-automerge" RSpec.describe Homebrew::DevCmd::PrAutomerge do it_behaves_like "parseable arguments" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/ruby_spec.rb
Library/Homebrew/test/dev-cmd/ruby_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/ruby" RSpec.describe Homebrew::DevCmd::Ruby do it_behaves_like "parseable arguments" it "executes ruby code with Homebrew's libraries loaded", :integration_test do expect { brew "ruby", "-e", "exit 0" } .to be_a_success .and not_to_output.to_stdout .and not_to_output.to_stderr end # Doesn't actually need Linux but only running there as integration tests are slow. describe "-e 'puts \"testball\".f.path'", :integration_test, :needs_linux do let!(:target) do target_path = setup_test_formula "testball" { path: target_path } end it "prints the path of a test formula" do expect { brew "ruby", "-e", "puts 'testball'.f.path" } .to be_a_success .and output(/^#{target[:path]}$/).to_stdout .and not_to_output.to_stderr end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/generate-analytics-api_spec.rb
Library/Homebrew/test/dev-cmd/generate-analytics-api_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/generate-analytics-api" RSpec.describe Homebrew::DevCmd::GenerateAnalyticsApi do it_behaves_like "parseable arguments" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/generate-cask-ci-matrix_spec.rb
Library/Homebrew/test/dev-cmd/generate-cask-ci-matrix_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/generate-cask-ci-matrix" RSpec.describe Homebrew::DevCmd::GenerateCaskCiMatrix do it_behaves_like "parseable arguments" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/sh_spec.rb
Library/Homebrew/test/dev-cmd/sh_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/sh" RSpec.describe Homebrew::DevCmd::Sh do it_behaves_like "parseable arguments" it "runs a shell with the Homebrew environment", :integration_test do expect { brew "sh", "SHELL" => which("true") } .to output(/Your shell has been configured/).to_stdout .and not_to_output.to_stderr .and be_a_success end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/livecheck_spec.rb
Library/Homebrew/test/dev-cmd/livecheck_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/livecheck" RSpec.describe Homebrew::DevCmd::LivecheckCmd do it_behaves_like "parseable arguments" it "reports the latest version of a Formula", :integration_test, :needs_network do content = <<~RUBY desc "Some test" homepage "https://github.com/Homebrew/brew" url "https://brew.sh/test-1.0.0.tgz" RUBY setup_test_formula("test", content) expect { brew "livecheck", "test" } .to output(/test: /).to_stdout .and not_to_output.to_stderr .and be_a_success end it "gives an error when no arguments are given and there's no watchlist", :integration_test do expect { brew "livecheck", "HOMEBREW_LIVECHECK_WATCHLIST" => ".this_should_not_exist" } .to output(/Invalid usage: `brew livecheck` with no arguments needs a watchlist file to be present/).to_stderr .and not_to_output.to_stdout .and be_a_failure end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/irb_spec.rb
Library/Homebrew/test/dev-cmd/irb_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/irb" RSpec.describe Homebrew::DevCmd::Irb do it_behaves_like "parseable arguments" describe "integration test" do let(:history_file) { Pathname("#{Dir.home}/.brew_irb_history") } after do history_file.delete if history_file.exist? end it "starts an interactive Homebrew shell session", :integration_test do setup_test_formula "testball" irb_test = HOMEBREW_TEMP/"irb-test.rb" irb_test.write <<~RUBY "testball".f :testball.f exit RUBY expect { brew "irb", irb_test } .to output(/Interactive Homebrew Shell/).to_stdout .and not_to_output.to_stderr .and be_a_success # TODO: newer Ruby only supports history saving in interactive sessions # and not if you feed in data from a file or stdin like we are doing here. # The test will need to be adjusted for this to work. # expect(history_file).to exist end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/linkage_spec.rb
Library/Homebrew/test/dev-cmd/linkage_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/linkage" RSpec.describe Homebrew::DevCmd::Linkage do it_behaves_like "parseable arguments" it "works when no arguments are provided", :integration_test do setup_test_formula "testball" (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath expect { brew "linkage" } .to be_a_success .and not_to_output.to_stdout .and not_to_output.to_stderr end it "accepts no_linkage dependency tag", :integration_test do setup_test_formula "testball" do url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" sha256 TESTBALL_SHA256 depends_on "foo" => :no_linkage end expect { brew "info", "testball" } .to be_a_success end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/prof_spec.rb
Library/Homebrew/test/dev-cmd/prof_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/prof" RSpec.describe Homebrew::DevCmd::Prof do it_behaves_like "parseable arguments" describe "integration tests", :integration_test, :needs_network do after do FileUtils.rm_rf HOMEBREW_LIBRARY_PATH/"prof" end it "works using ruby-prof (the default)" do expect { brew "prof", "help", "HOMEBREW_BROWSER" => "echo" } .to output(/^Example usage:/).to_stdout .and not_to_output.to_stderr .and be_a_success end it "works using stackprof" do expect { brew "prof", "--stackprof", "help", "HOMEBREW_BROWSER" => "echo" } .to output(/^Example usage:/).to_stdout .and not_to_output.to_stderr .and be_a_success end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/update-maintainers_spec.rb
Library/Homebrew/test/dev-cmd/update-maintainers_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/update-maintainers" RSpec.describe Homebrew::DevCmd::UpdateMaintainers do it_behaves_like "parseable arguments" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/dispatch-build-bottle_spec.rb
Library/Homebrew/test/dev-cmd/dispatch-build-bottle_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/dispatch-build-bottle" RSpec.describe Homebrew::DevCmd::DispatchBuildBottle do it_behaves_like "parseable arguments" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/unpack_spec.rb
Library/Homebrew/test/dev-cmd/unpack_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/unpack" RSpec.describe Homebrew::DevCmd::Unpack do it_behaves_like "parseable arguments" it "unpacks a given Formula's archive", :integration_test do setup_test_formula "testball" mktmpdir do |path| expect { brew "unpack", "testball", "--destdir=#{path}" } .to be_a_success expect(path/"testball-0.1").to be_a_directory end end it "unpacks a given Cask's archive", :integration_test do caffeine_cask = Cask::CaskLoader.load(cask_path("local-caffeine")) mktmpdir do |path| expect { brew "unpack", cask_path("local-caffeine"), "--destdir=#{path}" } .to be_a_success expect(path/"local-caffeine-#{caffeine_cask.version}").to be_a_directory end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/tap-new_spec.rb
Library/Homebrew/test/dev-cmd/tap-new_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/tap-new" RSpec.describe Homebrew::DevCmd::TapNew do it_behaves_like "parseable arguments" it "initializes a new tap with a README file and GitHub Actions CI", :integration_test do # To ensure that Utils::Git.setup_gpg! doesn't raise an error setup_test_formula "gnupg" expect { brew "tap-new", "--no-git", "--verbose", "homebrew/foo" } .to be_a_success .and output(%r{homebrew/foo}).to_stdout .and not_to_output.to_stderr expect(HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-foo/README.md").to exist expect(HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-foo/.github/workflows/tests.yml").to exist end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/bump-unversioned-casks_spec.rb
Library/Homebrew/test/dev-cmd/bump-unversioned-casks_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/bump-unversioned-casks" RSpec.describe Homebrew::DevCmd::BumpUnversionedCasks do it_behaves_like "parseable arguments" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/update-license-data_spec.rb
Library/Homebrew/test/dev-cmd/update-license-data_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/update-license-data" RSpec.describe Homebrew::DevCmd::UpdateLicenseData do it_behaves_like "parseable arguments" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/which-update_spec.rb
Library/Homebrew/test/dev-cmd/which-update_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/which-update" RSpec.describe Homebrew::DevCmd::WhichUpdate do it_behaves_like "parseable arguments" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/verify_spec.rb
Library/Homebrew/test/dev-cmd/verify_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/verify" RSpec.describe Homebrew::DevCmd::Verify do it_behaves_like "parseable arguments" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/tests_spec.rb
Library/Homebrew/test/dev-cmd/tests_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/tests" RSpec.describe Homebrew::DevCmd::Tests do it_behaves_like "parseable arguments" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/create_spec.rb
Library/Homebrew/test/dev-cmd/create_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/create" RSpec.describe Homebrew::DevCmd::Create do let(:url) { "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" } let(:formula_file) { CoreTap.instance.new_formula_path("testball") } it_behaves_like "parseable arguments" it "creates a new Formula file for a given URL", :integration_test do brew "create", "--set-name=Testball", url, "HOMEBREW_EDITOR" => "/bin/cat" expect(formula_file).to exist expect(formula_file.read).to match(%Q(sha256 "#{TESTBALL_SHA256}")) end it "generates valid cask tokens" do t = Cask::Utils.token_from("A FooBar_Baz++!") expect(t).to eq("a-foobar-baz-plus-plus") end it "retains @ in cask tokens" do t = Cask::Utils.token_from("test@preview") expect(t).to eq("test@preview") end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/bump-cask-pr_spec.rb
Library/Homebrew/test/dev-cmd/bump-cask-pr_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/bump-cask-pr" RSpec.describe Homebrew::DevCmd::BumpCaskPr do subject(:bump_cask_pr) { described_class.new(["test"]) } let(:newest_macos) { MacOSVersion.new(HOMEBREW_MACOS_NEWEST_SUPPORTED).to_sym } let(:c) do Cask::Cask.new("test") do version "0.0.1,2" url "https://brew.sh/test-0.0.1.dmg" name "Test" desc "Test cask" homepage "https://brew.sh" end end let(:c_depends_on_intel) do Cask::Cask.new("test-depends-on-intel") do version "0.0.1,2" url "https://brew.sh/test-0.0.1.dmg" name "Test" desc "Test cask" homepage "https://brew.sh" depends_on arch: :x86_64 end end let(:c_on_system) do Cask::Cask.new("test-on-system") do os macos: "darwin", linux: "linux" version "0.0.1,2" url "https://brew.sh/test-0.0.1.dmg" name "Test" desc "Test cask" homepage "https://brew.sh" end end let(:c_on_system_depends_on_intel) do Cask::Cask.new("test-on-system-depends-on-intel") do os macos: "darwin", linux: "linux" version "0.0.1,2" url "https://brew.sh/test-0.0.1.dmg" name "Test" desc "Test cask" homepage "https://brew.sh" depends_on arch: :x86_64 end end it_behaves_like "parseable arguments" describe "::generate_system_options" do # We simulate a macOS version older than the newest, as the method will use # the host macOS version instead of the default (the newest macOS version). let(:older_macos) { :big_sur } context "when cask does not have on_system blocks/calls or `depends_on arch`" do it "returns an array only including macOS/ARM" do Homebrew::SimulateSystem.with(os: :linux) do expect(bump_cask_pr.send(:generate_system_options, c)) .to eq([[newest_macos, :arm]]) end Homebrew::SimulateSystem.with(os: older_macos) do expect(bump_cask_pr.send(:generate_system_options, c)) .to eq([[older_macos, :arm]]) end end end context "when cask does not have on_system blocks/calls but has `depends_on arch`" do it "returns an array only including macOS/`depends_on arch` value" do Homebrew::SimulateSystem.with(os: :linux, arch: :arm) do expect(bump_cask_pr.send(:generate_system_options, c_depends_on_intel)) .to eq([[newest_macos, :intel]]) end Homebrew::SimulateSystem.with(os: older_macos, arch: :arm) do expect(bump_cask_pr.send(:generate_system_options, c_depends_on_intel)) .to eq([[older_macos, :intel]]) end end end context "when cask has on_system blocks/calls but does not have `depends_on arch`" do it "returns an array with combinations of `OnSystem::BASE_OS_OPTIONS` and `OnSystem::ARCH_OPTIONS`" do Homebrew::SimulateSystem.with(os: :linux) do expect(bump_cask_pr.send(:generate_system_options, c_on_system)) .to eq([ [newest_macos, :intel], [newest_macos, :arm], [:linux, :intel], [:linux, :arm], ]) end Homebrew::SimulateSystem.with(os: older_macos) do expect(bump_cask_pr.send(:generate_system_options, c_on_system)) .to eq([ [older_macos, :intel], [older_macos, :arm], [:linux, :intel], [:linux, :arm], ]) end end end context "when cask has on_system blocks/calls and `depends_on arch`" do it "returns an array with combinations of `OnSystem::BASE_OS_OPTIONS` and `depends_on arch` value" do Homebrew::SimulateSystem.with(os: :linux, arch: :arm) do expect(bump_cask_pr.send(:generate_system_options, c_on_system_depends_on_intel)) .to eq([ [newest_macos, :intel], [:linux, :intel], ]) end Homebrew::SimulateSystem.with(os: older_macos, arch: :arm) do expect(bump_cask_pr.send(:generate_system_options, c_on_system_depends_on_intel)) .to eq([ [older_macos, :intel], [:linux, :intel], ]) end end end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/formula_spec.rb
Library/Homebrew/test/dev-cmd/formula_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/formula" RSpec.describe Homebrew::DevCmd::FormulaCmd do it_behaves_like "parseable arguments" it "prints a given Formula's path", :integration_test do formula_file = setup_test_formula "testball" expect { brew "formula", "testball" } .to output("#{formula_file}\n").to_stdout .and not_to_output.to_stderr .and be_a_success end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/typecheck_spec.rb
Library/Homebrew/test/dev-cmd/typecheck_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/typecheck" RSpec.describe Homebrew::DevCmd::Typecheck do it_behaves_like "parseable arguments" describe "#trim_rubocop_rbi" do let(:rbi_file) { Pathname.new("#{TEST_FIXTURE_DIR}/rubocop@x.x.x.rbi") } let(:typecheck) { described_class.new([]) } before do allow(Dir).to receive(:glob).and_return([rbi_file.to_s]) end it "trims RuboCop RBI file to only include allowlisted classes" do old_content = rbi_file.read typecheck.trim_rubocop_rbi(path: rbi_file.to_s) new_content = rbi_file.read expect(new_content).to include("RuboCop::Config") expect(new_content).to include("RuboCop::Cop::Base") expect(new_content).to include("Parser::Source") expect(new_content).to include("VERSION") expect(new_content).to include("SOME_CONSTANT") expect(new_content).not_to include("SomeUnusedCop") expect(new_content).not_to include("UnusedModule") expect(new_content).not_to include("CompletelyUnrelated") rbi_file.write(old_content) end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/generate-formula-api_spec.rb
Library/Homebrew/test/dev-cmd/generate-formula-api_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/generate-formula-api" RSpec.describe Homebrew::DevCmd::GenerateFormulaApi do it_behaves_like "parseable arguments" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/bottle_spec.rb
Library/Homebrew/test/dev-cmd/bottle_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/bottle" RSpec.describe Homebrew::DevCmd::Bottle do def stub_hash(parameters) <<~EOS { "#{parameters[:name]}":{ "formula":{ "pkg_version":"#{parameters[:version]}", "path":"#{parameters[:path]}" }, "bottle":{ "root_url":"#{parameters[:root_url] || HOMEBREW_BOTTLE_DEFAULT_DOMAIN}", "prefix":"/usr/local", "cellar":"#{parameters[:cellar]}", "rebuild":0, "tags":{ "#{parameters[:os]}":{ "filename":"#{parameters[:filename]}", "local_filename":"#{parameters[:local_filename]}", "sha256":"#{parameters[:sha256]}" } } } } } EOS end it_behaves_like "parseable arguments" it "builds a bottle for the given Formula", :integration_test, :needs_network do install_test_formula "testball", build_bottle: true # `brew bottle` should not fail with dead symlink # https://github.com/Homebrew/legacy-homebrew/issues/49007 (HOMEBREW_CELLAR/"testball/0.1").cd do FileUtils.ln_s "not-exist", "symlink" end begin expect { brew "bottle", "--no-rebuild", "testball" } .to output(/testball--0\.1.*\.bottle\.tar\.gz/).to_stdout .and not_to_output.to_stderr .and be_a_success expect(HOMEBREW_CELLAR/"testball-bottle.tar").not_to exist ensure FileUtils.rm_f Dir.glob("testball--0.1*.bottle.tar.gz") end end describe "--merge", :integration_test do let(:core_tap) { CoreTap.instance } let(:tarball) do if OS.linux? TEST_FIXTURE_DIR/"tarballs/testball-0.1-linux.tbz" else TEST_FIXTURE_DIR/"tarballs/testball-0.1.tbz" end end before do Pathname("#{TEST_TMPDIR}/testball-1.0.arm64_big_sur.bottle.json").write stub_hash( name: "testball", version: "1.0", path: "#{core_tap.path}/Formula/testball.rb", cellar: "any_skip_relocation", os: "arm64_big_sur", filename: "testball-1.0.arm64_big_sur.bottle.tar.gz", local_filename: "testball--1.0.arm64_big_sur.bottle.tar.gz", sha256: "8f9aecd233463da6a4ea55f5f88fc5841718c013f3e2a7941350d6130f1dc149", ) Pathname("#{TEST_TMPDIR}/testball-1.0.big_sur.bottle.json").write stub_hash( name: "testball", version: "1.0", path: "#{core_tap.path}/Formula/testball.rb", cellar: "any_skip_relocation", os: "big_sur", filename: "hello-1.0.big_sur.bottle.tar.gz", local_filename: "hello--1.0.big_sur.bottle.tar.gz", sha256: "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f", ) Pathname("#{TEST_TMPDIR}/testball-1.0.catalina.bottle.json").write stub_hash( name: "testball", version: "1.0", path: "#{core_tap.path}/Formula/testball.rb", cellar: "any_skip_relocation", os: "catalina", filename: "testball-1.0.catalina.bottle.tar.gz", local_filename: "testball--1.0.catalina.bottle.tar.gz", sha256: "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac", ) end after do FileUtils.rm_f "#{TEST_TMPDIR}/testball-1.0.arm64_big_sur.bottle.json" FileUtils.rm_f "#{TEST_TMPDIR}/testball-1.0.catalina.bottle.json" FileUtils.rm_f "#{TEST_TMPDIR}/testball-1.0.big_sur.bottle.json" end it "adds the bottle block to a formula that has none" do core_tap.path.cd do system "git", "-c", "init.defaultBranch=master", "init" setup_test_formula "testball" system "git", "add", "--all" system "git", "commit", "-m", "testball 0.1" end # RuboCop would align the `.and` with `.to_stdout` which is too floaty. # rubocop:disable Layout/MultilineMethodCallIndentation expect do brew "bottle", "--merge", "--write", "#{TEST_TMPDIR}/testball-1.0.arm64_big_sur.bottle.json", "#{TEST_TMPDIR}/testball-1.0.big_sur.bottle.json", "#{TEST_TMPDIR}/testball-1.0.catalina.bottle.json" end.to output(Regexp.new(<<~'EOS')).to_stdout ==> testball bottle do sha256 cellar: :any_skip_relocation, arm64_big_sur: "8f9aecd233463da6a4ea55f5f88fc5841718c013f3e2a7941350d6130f1dc149" sha256 cellar: :any_skip_relocation, big_sur: "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" sha256 cellar: :any_skip_relocation, catalina: "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" end \[master [0-9a-f]{4,40}\] testball: add 1\.0 bottle\. 1 file changed, 6 insertions\(\+\) EOS .and not_to_output.to_stderr .and be_a_success # rubocop:enable Layout/MultilineMethodCallIndentation expect((core_tap.path/"Formula/testball.rb").read).to eq <<~EOS class Testball < Formula desc "Some test" homepage "https://brew.sh/testball" url "file://#{tarball}" sha256 "#{tarball.sha256}" bottle do sha256 cellar: :any_skip_relocation, arm64_big_sur: "8f9aecd233463da6a4ea55f5f88fc5841718c013f3e2a7941350d6130f1dc149" sha256 cellar: :any_skip_relocation, big_sur: "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" sha256 cellar: :any_skip_relocation, catalina: "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" end option "with-foo", "Build with foo" def install (prefix/"foo"/"test").write("test") if build.with? "foo" prefix.install Dir["*"] (buildpath/"test.c").write \ "#include <stdio.h>\\nint main(){printf(\\"test\\");return 0;}" bin.mkpath system ENV.cc, "test.c", "-o", bin/"test" end # something here end EOS end it "replaces the bottle block in a formula that already has a bottle block" do core_tap.path.cd do system "git", "-c", "init.defaultBranch=master", "init" setup_test_formula "testball", bottle_block: <<~EOS bottle do sha256 cellar: :any_skip_relocation, arm64_big_sur: "c3c650d75f5188f5d6edd351dd3215e141b73b8ec1cf9144f30e39cbc45de72e" sha256 cellar: :any_skip_relocation, big_sur: "6b276491297d4052538bd2fd22d5129389f27d90a98f831987236a5b90511b98" sha256 cellar: :any_skip_relocation, catalina: "16cf230afdfcb6306c208d169549cf8773c831c8653d2c852315a048960d7e72" end EOS system "git", "add", "--all" system "git", "commit", "-m", "testball 0.1" end # RuboCop would align the `.and` with `.to_stdout` which is too floaty. # rubocop:disable Layout/MultilineMethodCallIndentation expect do brew "bottle", "--merge", "--write", "#{TEST_TMPDIR}/testball-1.0.arm64_big_sur.bottle.json", "#{TEST_TMPDIR}/testball-1.0.big_sur.bottle.json", "#{TEST_TMPDIR}/testball-1.0.catalina.bottle.json" end.to output(Regexp.new(<<~'EOS')).to_stdout ==> testball bottle do sha256 cellar: :any_skip_relocation, arm64_big_sur: "8f9aecd233463da6a4ea55f5f88fc5841718c013f3e2a7941350d6130f1dc149" sha256 cellar: :any_skip_relocation, big_sur: "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" sha256 cellar: :any_skip_relocation, catalina: "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" end \[master [0-9a-f]{4,40}\] testball: update 1\.0 bottle\. 1 file changed, 3 insertions\(\+\), 3 deletions\(\-\) EOS .and not_to_output.to_stderr .and be_a_success # rubocop:enable Layout/MultilineMethodCallIndentation expect((core_tap.path/"Formula/testball.rb").read).to eq <<~EOS class Testball < Formula desc "Some test" homepage "https://brew.sh/testball" url "file://#{tarball}" sha256 "#{tarball.sha256}" option "with-foo", "Build with foo" bottle do sha256 cellar: :any_skip_relocation, arm64_big_sur: "8f9aecd233463da6a4ea55f5f88fc5841718c013f3e2a7941350d6130f1dc149" sha256 cellar: :any_skip_relocation, big_sur: "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" sha256 cellar: :any_skip_relocation, catalina: "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" end def install (prefix/"foo"/"test").write("test") if build.with? "foo" prefix.install Dir["*"] (buildpath/"test.c").write \ "#include <stdio.h>\\nint main(){printf(\\"test\\");return 0;}" bin.mkpath system ENV.cc, "test.c", "-o", bin/"test" end # something here end EOS end it "updates the bottle block in a formula that already has a bottle block when using --keep-old" do core_tap.path.cd do system "git", "-c", "init.defaultBranch=master", "init" setup_test_formula "testball", bottle_block: <<~EOS bottle do sha256 cellar: :any, sonoma: "6971b6eebf4c00eaaed72a1104a49be63861eabc95d679a0c84040398e320059" end EOS system "git", "add", "--all" system "git", "commit", "-m", "testball 0.1" end # RuboCop would align the `.and` with `.to_stdout` which is too floaty. # rubocop:disable Layout/MultilineMethodCallIndentation expect do brew "bottle", "--merge", "--write", "--keep-old", "#{TEST_TMPDIR}/testball-1.0.arm64_big_sur.bottle.json", "#{TEST_TMPDIR}/testball-1.0.big_sur.bottle.json", "#{TEST_TMPDIR}/testball-1.0.catalina.bottle.json" end.to output(Regexp.new(<<~'EOS')).to_stdout ==> testball bottle do sha256 cellar: :any_skip_relocation, arm64_big_sur: "8f9aecd233463da6a4ea55f5f88fc5841718c013f3e2a7941350d6130f1dc149" sha256 cellar: :any, sonoma: "6971b6eebf4c00eaaed72a1104a49be63861eabc95d679a0c84040398e320059" sha256 cellar: :any_skip_relocation, big_sur: "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" sha256 cellar: :any_skip_relocation, catalina: "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" end \[master [0-9a-f]{4,40}\] testball: update 1\.0 bottle\. 1 file changed, 4 insertions\(\+\), 1 deletion\(\-\) EOS .and not_to_output.to_stderr .and be_a_success # rubocop:enable Layout/MultilineMethodCallIndentation expect((core_tap.path/"Formula/testball.rb").read).to eq <<~EOS class Testball < Formula desc "Some test" homepage "https://brew.sh/testball" url "file://#{tarball}" sha256 "#{tarball.sha256}" option "with-foo", "Build with foo" bottle do sha256 cellar: :any_skip_relocation, arm64_big_sur: "8f9aecd233463da6a4ea55f5f88fc5841718c013f3e2a7941350d6130f1dc149" sha256 cellar: :any, sonoma: "6971b6eebf4c00eaaed72a1104a49be63861eabc95d679a0c84040398e320059" sha256 cellar: :any_skip_relocation, big_sur: "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" sha256 cellar: :any_skip_relocation, catalina: "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" end def install (prefix/"foo"/"test").write("test") if build.with? "foo" prefix.install Dir["*"] (buildpath/"test.c").write \ "#include <stdio.h>\\nint main(){printf(\\"test\\");return 0;}" bin.mkpath system ENV.cc, "test.c", "-o", bin/"test" end # something here end EOS end end describe "bottle_cmd" do subject(:homebrew) { described_class.new(["foo"]) } let(:hello_hash_big_sur) do JSON.parse stub_hash( name: "hello", version: "1.0", path: "/home/hello.rb", cellar: "any_skip_relocation", os: "big_sur", filename: "hello-1.0.big_sur.bottle.tar.gz", local_filename: "hello--1.0.big_sur.bottle.tar.gz", sha256: "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f", ) end let(:hello_hash_catalina) do JSON.parse stub_hash( name: "hello", version: "1.0", path: "/home/hello.rb", cellar: "any_skip_relocation", os: "catalina", filename: "hello-1.0.catalina.bottle.tar.gz", local_filename: "hello--1.0.catalina.bottle.tar.gz", sha256: "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac", ) end let(:unzip_hash_big_sur) do JSON.parse stub_hash( name: "unzip", version: "2.0", path: "/home/unzip.rb", cellar: "any_skip_relocation", os: "big_sur", filename: "unzip-2.0.big_sur.bottle.tar.gz", local_filename: "unzip--2.0.big_sur.bottle.tar.gz", sha256: "16cf230afdfcb6306c208d169549cf8773c831c8653d2c852315a048960d7e72", ) end let(:unzip_hash_catalina) do JSON.parse stub_hash( name: "unzip", version: "2.0", path: "/home/unzip.rb", cellar: "any", os: "catalina", filename: "unzip-2.0.catalina.bottle.tar.gz", local_filename: "unzip--2.0.catalina.bottle.tar.gz", sha256: "d9cc50eec8ac243148a121049c236cba06af4a0b1156ab397d0a2850aa79c137", ) end specify "::parse_json_files" do Tempfile.open("hello--1.0.big_sur.bottle.json") do |f| f.write stub_hash( name: "hello", version: "1.0", path: "/home/hello.rb", cellar: "any_skip_relocation", os: "big_sur", filename: "hello-1.0.big_sur.bottle.tar.gz", local_filename: "hello--1.0.big_sur.bottle.tar.gz", sha256: "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f", ) f.close expect( homebrew.parse_json_files([f.path]).first["hello"]["bottle"]["tags"]["big_sur"]["filename"], ).to eq("hello-1.0.big_sur.bottle.tar.gz") end end describe "::merge_json_files" do it "merges JSON files" do bottles_hash = homebrew.merge_json_files( [hello_hash_big_sur, hello_hash_catalina, unzip_hash_big_sur, unzip_hash_catalina], ) hello_hash = bottles_hash["hello"] expect(hello_hash["bottle"]["tags"]["big_sur"]["cellar"]).to eq("any_skip_relocation") expect(hello_hash["bottle"]["tags"]["big_sur"]["filename"]).to eq("hello-1.0.big_sur.bottle.tar.gz") expect(hello_hash["bottle"]["tags"]["big_sur"]["local_filename"]).to eq("hello--1.0.big_sur.bottle.tar.gz") expect(hello_hash["bottle"]["tags"]["big_sur"]["sha256"]).to eq( "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f", ) expect(hello_hash["bottle"]["tags"]["catalina"]["cellar"]).to eq("any_skip_relocation") expect(hello_hash["bottle"]["tags"]["catalina"]["filename"]).to eq("hello-1.0.catalina.bottle.tar.gz") expect(hello_hash["bottle"]["tags"]["catalina"]["local_filename"]).to eq("hello--1.0.catalina.bottle.tar.gz") expect(hello_hash["bottle"]["tags"]["catalina"]["sha256"]).to eq( "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac", ) unzip_hash = bottles_hash["unzip"] expect(unzip_hash["bottle"]["tags"]["big_sur"]["cellar"]).to eq("any_skip_relocation") expect(unzip_hash["bottle"]["tags"]["big_sur"]["filename"]).to eq("unzip-2.0.big_sur.bottle.tar.gz") expect(unzip_hash["bottle"]["tags"]["big_sur"]["local_filename"]).to eq("unzip--2.0.big_sur.bottle.tar.gz") expect(unzip_hash["bottle"]["tags"]["big_sur"]["sha256"]).to eq( "16cf230afdfcb6306c208d169549cf8773c831c8653d2c852315a048960d7e72", ) expect(unzip_hash["bottle"]["tags"]["catalina"]["cellar"]).to eq("any") expect(unzip_hash["bottle"]["tags"]["catalina"]["filename"]).to eq("unzip-2.0.catalina.bottle.tar.gz") expect(unzip_hash["bottle"]["tags"]["catalina"]["local_filename"]).to eq("unzip--2.0.catalina.bottle.tar.gz") expect(unzip_hash["bottle"]["tags"]["catalina"]["sha256"]).to eq( "d9cc50eec8ac243148a121049c236cba06af4a0b1156ab397d0a2850aa79c137", ) end # TODO: add deduplication tests e.g. # it "deduplicates JSON files with matching macOS checksums" # it "deduplicates JSON files with matching OS checksums" do end describe "#merge_bottle_spec" do it "allows new bottle hash to be empty" do valid_keys = [:root_url, :cellar, :rebuild, :sha256] old_spec = BottleSpecification.new old_spec.sha256(big_sur: "f59bc65c91e4e698f6f050e1efea0040f57372d4dcf0996cbb8f97ced320403b") expect { homebrew.merge_bottle_spec(valid_keys, old_spec, {}) }.not_to raise_error end it "checks for conflicting root URL" do old_spec = BottleSpecification.new old_spec.root_url("https://failbrew.bintray.com/bottles") new_hash = { "root_url" => "https://testbrew.bintray.com/bottles" } expect(homebrew.merge_bottle_spec([:root_url], old_spec, new_hash)).to eq [ ['root_url: old: "https://failbrew.bintray.com/bottles", new: "https://testbrew.bintray.com/bottles"'], [], ] end it "checks for conflicting rebuild number" do old_spec = BottleSpecification.new old_spec.rebuild(1) new_hash = { "rebuild" => 2 } expect(homebrew.merge_bottle_spec([:rebuild], old_spec, new_hash)).to eq [ ['rebuild: old: "1", new: "2"'], [], ] end it "checks for conflicting checksums" do old_spec = BottleSpecification.new old_sequoia_sha256 = "109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e" old_spec.sha256(sequoia: old_sequoia_sha256) old_spec.sha256(sonoma: "7571772bf7a0c9fe193e70e521318b53993bee6f351976c9b6e01e00d13d6c3f") new_sequoia_sha256 = "ec6d7f08412468f28dee2be17ad8cd8b883b16b34329efcecce019b8c9736428" new_hash = { "tags" => { "sequoia" => { "sha256" => new_sequoia_sha256 } } } expected_checksum_hash = { sonoma: "7571772bf7a0c9fe193e70e521318b53993bee6f351976c9b6e01e00d13d6c3f" } expected_checksum_hash[:cellar] = Homebrew::DEFAULT_MACOS_CELLAR expect(homebrew.merge_bottle_spec([:sha256], old_spec, new_hash)).to eq [ ["sha256 sequoia: old: #{old_sequoia_sha256.inspect}, new: #{new_sequoia_sha256.inspect}"], [expected_checksum_hash], ] end end describe "::generate_sha256_line" do it "generates a string without cellar" do expect(homebrew.generate_sha256_line(:sequoia, "deadbeef", nil, 0, 10)).to eq( <<~RUBY.chomp, sha256 sequoia: "deadbeef" RUBY ) end it "generates a string with cellar symbol" do expect(homebrew.generate_sha256_line(:sequoia, "deadbeef", :any, 14, 24)).to eq( <<~RUBY.chomp, sha256 cellar: :any, sequoia: "deadbeef" RUBY ) end it "generates a string with default cellar path" do expect(homebrew.generate_sha256_line(:sequoia, "deadbeef", Homebrew::DEFAULT_LINUX_CELLAR, 0, 10)).to eq( <<~RUBY.chomp, sha256 sequoia: "deadbeef" RUBY ) end it "generates a string with non-default cellar path" do expect(homebrew.generate_sha256_line(:sequoia, "deadbeef", "/home/test", 22, 32)).to eq( <<~RUBY.chomp, sha256 cellar: "/home/test", sequoia: "deadbeef" RUBY ) end context "with offsets" do it "generates a string without cellar" do expect(homebrew.generate_sha256_line(:sequoia, "deadbeef", nil, 0, 15)).to eq( <<~RUBY.chomp, sha256 sequoia: "deadbeef" RUBY ) end it "generates a string with cellar symbol" do expect(homebrew.generate_sha256_line(:sequoia, "deadbeef", :any, 20, 35)).to eq( <<~RUBY.chomp, sha256 cellar: :any, sequoia: "deadbeef" RUBY ) end it "generates a string with default cellar path" do expect(homebrew.generate_sha256_line(:sequoia, "deadbeef", Homebrew::DEFAULT_LINUX_CELLAR, 14, 30)).to eq( <<~RUBY.chomp, sha256 sequoia: "deadbeef" RUBY ) end it "generates a string with non-default cellar path" do expect(homebrew.generate_sha256_line(:sequoia, "deadbeef", "/home/test", 25, 36)).to eq( <<~RUBY.chomp, sha256 cellar: "/home/test", sequoia: "deadbeef" RUBY ) end end end describe "::bottle_output" do it "includes a custom root_url" do bottle = BottleSpecification.new bottle.root_url("https://example.com") bottle.sha256(catalina: "109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e") expect(homebrew.bottle_output(bottle, nil)).to eq( <<-RUBY, bottle do root_url "https://example.com" sha256 catalina: "109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e" end RUBY ) end it "includes download strategy for custom root_url" do bottle = BottleSpecification.new bottle.root_url("https://example.com") bottle.sha256(catalina: "109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e") expect(homebrew.bottle_output(bottle, "ExampleStrategy")).to eq( <<-RUBY, bottle do root_url "https://example.com", using: ExampleStrategy sha256 catalina: "109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e" end RUBY ) end end end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/bump-formula-pr_spec.rb
Library/Homebrew/test/dev-cmd/bump-formula-pr_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/bump-formula-pr" RSpec.describe Homebrew::DevCmd::BumpFormulaPr do it_behaves_like "parseable arguments" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/generate-man-completions_spec.rb
Library/Homebrew/test/dev-cmd/generate-man-completions_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/generate-man-completions" RSpec.describe Homebrew::DevCmd::GenerateManCompletions do it_behaves_like "parseable arguments" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/dev-cmd/contributions_spec.rb
Library/Homebrew/test/dev-cmd/contributions_spec.rb
# frozen_string_literal: true require "cmd/shared_examples/args_parse" require "dev-cmd/contributions" RSpec.describe Homebrew::DevCmd::Contributions do it_behaves_like "parseable arguments" end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false