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/utils/spdx_spec.rb
Library/Homebrew/test/utils/spdx_spec.rb
# frozen_string_literal: true require "utils/spdx" RSpec.describe SPDX do describe ".license_data" do it "has the license list version" do expect(described_class.license_data["licenseListVersion"]).not_to be_nil end it "has the release date" do expect(described_class.license_data["releaseDate"]).not_to be_nil end it "has licenses" do expect(described_class.license_data["licenses"].length).not_to eq(0) end end describe ".exception_data" do it "has the license list version" do expect(described_class.exception_data["licenseListVersion"]).not_to be_nil end it "has the release date" do expect(described_class.exception_data["releaseDate"]).not_to be_nil end it "has exceptions" do expect(described_class.exception_data["exceptions"].length).not_to eq(0) end end describe ".download_latest_license_data!", :needs_network do let(:download_dir) { mktmpdir } it "downloads latest license data" do described_class.download_latest_license_data! to: download_dir expect(download_dir/"spdx_licenses.json").to exist expect(download_dir/"spdx_exceptions.json").to exist end end describe ".parse_license_expression" do it "returns a single license" do expect(described_class.parse_license_expression("MIT").first).to eq ["MIT"] end it "returns a single license with plus" do # rubocop:todo RSpec/AggregateExamples expect(described_class.parse_license_expression("Apache-2.0+").first).to eq ["Apache-2.0+"] end it "returns multiple licenses with :any" do # rubocop:todo RSpec/AggregateExamples expect(described_class.parse_license_expression(any_of: ["MIT", "0BSD"]).first).to eq ["MIT", "0BSD"] end it "returns multiple licenses with :all" do # rubocop:todo RSpec/AggregateExamples expect(described_class.parse_license_expression(all_of: ["MIT", "0BSD"]).first).to eq ["MIT", "0BSD"] end it "returns multiple licenses with plus" do # rubocop:todo RSpec/AggregateExamples expect(described_class.parse_license_expression(any_of: ["MIT", "EPL-1.0+"]).first).to eq ["MIT", "EPL-1.0+"] end it "returns multiple licenses with array" do # rubocop:todo RSpec/AggregateExamples expect(described_class.parse_license_expression(["MIT", "EPL-1.0+"]).first).to eq ["MIT", "EPL-1.0+"] end it "returns license and exception" do license_expression = { "MIT" => { with: "LLVM-exception" } } expect(described_class.parse_license_expression(license_expression)).to eq [["MIT"], ["LLVM-exception"]] end it "returns licenses and exceptions for complex license expressions" do license_expression = { any_of: [ "MIT", :public_domain, # The final array item is legitimately a hash in the case of license expressions. all_of: ["0BSD", "Zlib"], # rubocop:disable Style/HashAsLastArrayItem "curl" => { with: "LLVM-exception" }, ] } result = [["MIT", :public_domain, "curl", "0BSD", "Zlib"], ["LLVM-exception"]] expect(described_class.parse_license_expression(license_expression)).to eq result end it "returns :public_domain" do # rubocop:todo RSpec/AggregateExamples expect(described_class.parse_license_expression(:public_domain).first).to eq [:public_domain] end it "returns :cannot_represent" do # rubocop:todo RSpec/AggregateExamples expect(described_class.parse_license_expression(:cannot_represent).first).to eq [:cannot_represent] end end describe ".valid_license?" do it "returns true for valid license identifier" do expect(described_class.valid_license?("MIT")).to be true end it "returns false for invalid license identifier" do expect(described_class.valid_license?("foo")).to be false end it "returns true for deprecated license identifier" do expect(described_class.valid_license?("GPL-1.0")).to be true end it "returns true for license identifier with plus" do expect(described_class.valid_license?("Apache-2.0+")).to be true end it "returns true for :public_domain" do expect(described_class.valid_license?(:public_domain)).to be true end it "returns true for :cannot_represent" do expect(described_class.valid_license?(:cannot_represent)).to be true end it "returns false for invalid symbol" do expect(described_class.valid_license?(:invalid_symbol)).to be false end end describe ".deprecated_license?" do it "returns true for deprecated license identifier" do expect(described_class.deprecated_license?("GPL-1.0")).to be true end it "returns true for deprecated license identifier with plus" do expect(described_class.deprecated_license?("GPL-1.0+")).to be true end it "returns false for non-deprecated license identifier" do expect(described_class.deprecated_license?("MIT")).to be false end it "returns false for non-deprecated license identifier with plus" do expect(described_class.deprecated_license?("EPL-1.0+")).to be false end it "returns false for invalid license identifier" do expect(described_class.deprecated_license?("foo")).to be false end it "returns false for :public_domain" do expect(described_class.deprecated_license?(:public_domain)).to be false end it "returns false for :cannot_represent" do expect(described_class.deprecated_license?(:cannot_represent)).to be false end end describe ".valid_license_exception?" do it "returns true for valid license exception identifier" do expect(described_class.valid_license_exception?("LLVM-exception")).to be true end it "returns false for invalid license exception identifier" do expect(described_class.valid_license_exception?("foo")).to be false end it "returns false for deprecated license exception identifier" do expect(described_class.valid_license_exception?("Nokia-Qt-exception-1.1")).to be false end end describe ".license_expression_to_string" do it "returns a single license" do expect(described_class.license_expression_to_string("MIT")).to eq "MIT" end it "returns a single license with plus" do expect(described_class.license_expression_to_string("Apache-2.0+")).to eq "Apache-2.0+" end it "returns multiple licenses with :any" do expect(described_class.license_expression_to_string({ any_of: ["MIT", "0BSD"] })).to eq "MIT OR 0BSD" end it "returns multiple licenses with :all" do expect(described_class.license_expression_to_string({ all_of: ["MIT", "0BSD"] })).to eq "MIT AND 0BSD" end it "returns multiple licenses with plus" do expect(described_class.license_expression_to_string({ any_of: ["MIT", "EPL-1.0+"] })).to eq "MIT OR EPL-1.0+" end it "returns license and exception" do license_expression = { "MIT" => { with: "LLVM-exception" } } expect(described_class.license_expression_to_string(license_expression)).to eq "MIT WITH LLVM-exception" end it "returns licenses and exceptions for complex license expressions" do license_expression = { any_of: [ "MIT", :public_domain, # The final array item is legitimately a hash in the case of license expressions. all_of: ["0BSD", "Zlib"], # rubocop:disable Style/HashAsLastArrayItem "curl" => { with: "LLVM-exception" }, ] } result = "MIT OR LicenseRef-Homebrew-public-domain OR (0BSD AND Zlib) OR (curl WITH LLVM-exception)" expect(described_class.license_expression_to_string(license_expression)).to eq result end it "returns :public_domain" do expect(described_class.license_expression_to_string(:public_domain)).to eq "LicenseRef-Homebrew-public-domain" end it "returns :cannot_represent" do result = "LicenseRef-Homebrew-cannot-represent" expect(described_class.license_expression_to_string(:cannot_represent)).to eq result end end describe ".string_to_license_expression" do it "returns the correct result for 'and', 'or' and 'with'" do expr_string = "Apache-2.0 and (Apache-2.0 with LLVM-exception) and (MIT or NCSA)" expect(described_class.string_to_license_expression(expr_string)).to eq({ all_of: [ "Apache-2.0", { "Apache-2.0" => { with: "LLVM-exception" } }, { any_of: ["MIT", "NCSA"] }, ], }) end it "returns the correct result for 'AND', 'OR' and 'WITH'" do expr_string = "Apache-2.0 AND (Apache-2.0 WITH LLVM-exception) AND (MIT OR NCSA)" expect(described_class.string_to_license_expression(expr_string)).to eq({ all_of: [ "Apache-2.0", { "Apache-2.0" => { with: "LLVM-exception" } }, { any_of: ["MIT", "NCSA"] }, ], }) end # The final array item is legitimately a hash in the case of license expressions. # rubocop:disable Style/HashAsLastArrayItem it "handles nested brackets" do expect(described_class.string_to_license_expression("A AND (B OR (C AND D))")).to eq({ all_of: [ "A", any_of: [ "B", all_of: ["C", "D"], ], ], }) end # rubocop:enable Style/HashAsLastArrayItem it "returns :public_domain" do expect(described_class.string_to_license_expression("LicenseRef-Homebrew-public-domain")).to eq :public_domain end it "returns :cannot_represent" do expr_string = "LicenseRef-Homebrew-cannot-represent" expect(described_class.string_to_license_expression(expr_string)).to eq :cannot_represent end end describe ".license_version_info" do it "returns license without version" do expect(described_class.license_version_info("MIT")).to eq ["MIT"] end it "returns :public_domain without version" do expect(described_class.license_version_info(:public_domain)).to eq [:public_domain] end it "returns license with version" do expect(described_class.license_version_info("Apache-2.0")).to eq ["Apache", "2.0", false] end it "returns license with version and plus" do expect(described_class.license_version_info("Apache-2.0+")).to eq ["Apache", "2.0", true] end it "returns more complicated license with version" do expect(described_class.license_version_info("CC-BY-3.0-AT")).to eq ["CC-BY", "3.0", false] end it "returns more complicated license with version and plus" do expect(described_class.license_version_info("CC-BY-3.0-AT+")).to eq ["CC-BY", "3.0", true] end it "returns license with -only" do expect(described_class.license_version_info("GPL-3.0-only")).to eq ["GPL", "3.0", false] end it "returns license with -or-later" do expect(described_class.license_version_info("GPL-3.0-or-later")).to eq ["GPL", "3.0", true] end end describe ".licenses_forbid_installation?" do let(:mit_forbidden) { { "MIT" => described_class.license_version_info("MIT") } } let(:epl_1_forbidden) { { "EPL-1.0" => described_class.license_version_info("EPL-1.0") } } let(:epl_1_plus_forbidden) { { "EPL-1.0+" => described_class.license_version_info("EPL-1.0+") } } let(:multiple_forbidden) do { "MIT" => described_class.license_version_info("MIT"), "0BSD" => described_class.license_version_info("0BSD"), } end let(:any_of_license) { { any_of: ["MIT", "0BSD"] } } let(:all_of_license) { { all_of: ["MIT", "0BSD"] } } let(:nested_licenses) do { any_of: [ "MIT", { "MIT" => { with: "LLVM-exception" } }, { any_of: ["MIT", "0BSD"] }, ], } end let(:license_exception) { { "MIT" => { with: "LLVM-exception" } } } it "allows installation with no forbidden licenses" do expect(described_class.licenses_forbid_installation?("MIT", {})).to be false end it "allows installation with non-forbidden license" do expect(described_class.licenses_forbid_installation?("0BSD", mit_forbidden)).to be false end it "forbids installation with forbidden license" do expect(described_class.licenses_forbid_installation?("MIT", mit_forbidden)).to be true end it "allows installation of later license version" do expect(described_class.licenses_forbid_installation?("EPL-2.0", epl_1_forbidden)).to be false end it "forbids installation of later license version with plus in forbidden license list" do expect(described_class.licenses_forbid_installation?("EPL-2.0", epl_1_plus_forbidden)).to be true end it "allows installation when one of the any_of licenses is allowed" do expect(described_class.licenses_forbid_installation?(any_of_license, mit_forbidden)).to be false end it "forbids installation when none of the any_of licenses are allowed" do expect(described_class.licenses_forbid_installation?(any_of_license, multiple_forbidden)).to be true end it "forbids installation when one of the all_of licenses is allowed" do expect(described_class.licenses_forbid_installation?(all_of_license, mit_forbidden)).to be true end it "allows installation with license + exception that aren't forbidden" do expect(described_class.licenses_forbid_installation?(license_exception, epl_1_forbidden)).to be false end it "forbids installation with license + exception that are't forbidden" do expect(described_class.licenses_forbid_installation?(license_exception, mit_forbidden)).to be true end it "allows installation with nested licenses with no forbidden licenses" do expect(described_class.licenses_forbid_installation?(nested_licenses, epl_1_forbidden)).to be false end it "allows installation with nested licenses when second hash item matches" do expect(described_class.licenses_forbid_installation?(nested_licenses, mit_forbidden)).to be false end it "forbids installation with nested licenses when all licenses are forbidden" do expect(described_class.licenses_forbid_installation?(nested_licenses, multiple_forbidden)).to be true end end describe ".forbidden_licenses_include?" do let(:mit_forbidden) { { "MIT" => described_class.license_version_info("MIT") } } let(:epl_1_forbidden) { { "EPL-1.0" => described_class.license_version_info("EPL-1.0") } } let(:epl_1_plus_forbidden) { { "EPL-1.0+" => described_class.license_version_info("EPL-1.0+") } } it "returns false with no forbidden licenses" do expect(described_class.forbidden_licenses_include?("MIT", {})).to be false end it "returns false with no matching forbidden licenses" do expect(described_class.forbidden_licenses_include?("MIT", epl_1_forbidden)).to be false end it "returns true with matching license" do expect(described_class.forbidden_licenses_include?("MIT", mit_forbidden)).to be true end it "returns false with later version of forbidden license" do expect(described_class.forbidden_licenses_include?("EPL-2.0", epl_1_forbidden)).to be false end it "returns true with later version of forbidden license with later versions forbidden" do expect(described_class.forbidden_licenses_include?("EPL-2.0", epl_1_plus_forbidden)).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/utils/bottles/collector_spec.rb
Library/Homebrew/test/utils/bottles/collector_spec.rb
# frozen_string_literal: true require "utils/bottles" RSpec.describe Utils::Bottles::Collector do subject(:collector) { described_class.new } let(:tahoe) { Utils::Bottles::Tag.from_symbol(:tahoe) } let(:sequoia) { Utils::Bottles::Tag.from_symbol(:sequoia) } let(:sonoma) { Utils::Bottles::Tag.from_symbol(:sonoma) } describe "#specification_for" do it "returns passed tags" do collector.add(sonoma, checksum: Checksum.new("foo_checksum"), cellar: "foo_cellar") collector.add(sequoia, checksum: Checksum.new("bar_checksum"), cellar: "bar_cellar") spec = collector.specification_for(sequoia) expect(spec).not_to be_nil expect(spec.tag).to eq(sequoia) expect(spec.checksum).to eq("bar_checksum") expect(spec.cellar).to eq("bar_cellar") end it "returns nil if empty" do expect(collector.specification_for(Utils::Bottles::Tag.from_symbol(:foo))).to be_nil end it "returns nil when there is no match" do collector.add(sequoia, checksum: Checksum.new("bar_checksum"), cellar: "bar_cellar") expect(collector.specification_for(Utils::Bottles::Tag.from_symbol(:foo))).to be_nil end it "uses older tags when needed", :needs_macos do collector.add(sonoma, checksum: Checksum.new("foo_checksum"), cellar: "foo_cellar") expect(collector.send(:find_matching_tag, sonoma)).to eq(sonoma) expect(collector.send(:find_matching_tag, sequoia)).to eq(sonoma) end it "does not use older tags when requested not to", :needs_macos do allow(Homebrew::EnvConfig).to receive_messages(developer?: true, skip_or_later_bottles?: true) allow(OS::Mac.version).to receive(:prerelease?).and_return(true) collector.add(sonoma, checksum: Checksum.new("foo_checksum"), cellar: "foo_cellar") expect(collector.send(:find_matching_tag, sonoma)).to eq(sonoma) expect(collector.send(:find_matching_tag, sequoia)).to be_nil end it "ignores HOMEBREW_SKIP_OR_LATER_BOTTLES on release versions", :needs_macos do allow(Homebrew::EnvConfig).to receive(:skip_or_later_bottles?).and_return(true) allow(OS::Mac.version).to receive(:prerelease?).and_return(false) collector.add(sonoma, checksum: Checksum.new("foo_checksum"), cellar: "foo_cellar") expect(collector.send(:find_matching_tag, sonoma)).to eq(sonoma) expect(collector.send(:find_matching_tag, sequoia)).to eq(sonoma) 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/utils/bottles/bottles_spec.rb
Library/Homebrew/test/utils/bottles/bottles_spec.rb
# frozen_string_literal: true require "utils/bottles" RSpec.describe Utils::Bottles do describe "#tag", :needs_macos do it "returns :big_sur or :arm64_big_sur on Big Sur" do allow(MacOS).to receive(:version).and_return(MacOSVersion.new("11.0")) if Hardware::CPU.intel? expect(described_class.tag).to eq(:big_sur) else expect(described_class.tag).to eq(:arm64_big_sur) end end end describe ".load_tab" do context "when tab_attributes and tabfile are missing" do before do # setup a testball1 dep_name = "testball1" dep_path = CoreTap.instance.new_formula_path(dep_name) dep_path.write <<~RUBY class #{Formulary.class_s(dep_name)} < Formula url "testball1" version "0.1" end RUBY Formulary.cache.delete(dep_path) # setup a testball2, that depends on testball1 formula_name = "testball2" formula_path = CoreTap.instance.new_formula_path(formula_name) formula_path.write <<~RUBY class #{Formulary.class_s(formula_name)} < Formula url "testball2" version "0.1" depends_on "testball1" end RUBY Formulary.cache.delete(formula_path) end it "includes runtime_dependencies" do formula = Formula["testball2"] formula.prefix.mkpath runtime_dependencies = described_class.load_tab(formula).runtime_dependencies expect(runtime_dependencies).not_to be_nil expect(runtime_dependencies.size).to eq(1) expect(runtime_dependencies.first).to include("full_name" => "testball1") 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/utils/bottles/tag_spec.rb
Library/Homebrew/test/utils/bottles/tag_spec.rb
# frozen_string_literal: true require "utils/bottles" RSpec.describe Utils::Bottles::Tag do it "can parse macOS symbols with archs" do symbol = :arm64_big_sur tag = described_class.from_symbol(symbol) expect(tag.system).to eq(:big_sur) expect(tag.arch).to eq(:arm64) expect(tag.to_macos_version).to eq(MacOSVersion.from_symbol(:big_sur)) expect(tag.macos?).to be true expect(tag.linux?).to be false expect(tag.to_sym).to eq(symbol) end it "can parse macOS symbols without archs" do symbol = :big_sur tag = described_class.from_symbol(symbol) expect(tag.system).to eq(:big_sur) expect(tag.arch).to eq(:x86_64) expect(tag.to_macos_version).to eq(MacOSVersion.from_symbol(:big_sur)) expect(tag.macos?).to be true expect(tag.linux?).to be false expect(tag.to_sym).to eq(symbol) end it "can parse Linux symbols" do symbol = :x86_64_linux tag = described_class.from_symbol(symbol) expect(tag.system).to eq(:linux) expect(tag.arch).to eq(:x86_64) expect { tag.to_macos_version }.to raise_error(MacOSVersion::Error) expect(tag.macos?).to be false expect(tag.linux?).to be true expect(tag.to_sym).to eq(symbol) end describe "#==" do it "compares using the standardized arch" do monterey_intel = described_class.new(system: :monterey, arch: :intel) monterex_x86_64 = described_class.new(system: :monterey, arch: :x86_64) expect(monterey_intel).to eq monterex_x86_64 end end describe "#standardized_arch" do it "returns :x86_64 for :intel" do expect(described_class.new(system: :all, arch: :intel).standardized_arch).to eq(:x86_64) end it "returns :arm64 for :arm" do # rubocop:todo RSpec/AggregateExamples expect(described_class.new(system: :all, arch: :arm).standardized_arch).to eq(:arm64) end end describe "#valid_combination?" do it "returns true for Intel" do tag = described_class.new(system: :big_sur, arch: :intel) expect(tag.valid_combination?).to be true tag = described_class.new(system: :linux, arch: :x86_64) expect(tag.valid_combination?).to be true end it "returns false for ARM on macOS Catalina" do tag = described_class.new(system: :catalina, arch: :arm64) expect(tag.valid_combination?).to be false end it "returns true for ARM on macOS Big Sur or newer" do tag = described_class.new(system: :big_sur, arch: :arm64) expect(tag.valid_combination?).to be true tag = described_class.new(system: :monterey, arch: :arm) expect(tag.valid_combination?).to be true tag = described_class.new(system: :ventura, arch: :arm) expect(tag.valid_combination?).to be true end it "returns true for ARM on Linux" do tag = described_class.new(system: :linux, arch: :arm64) expect(tag.valid_combination?).to be true tag = described_class.new(system: :linux, arch: :arm) expect(tag.valid_combination?).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/utils/github/actions_spec.rb
Library/Homebrew/test/utils/github/actions_spec.rb
# frozen_string_literal: true require "utils/github/actions" RSpec.describe GitHub::Actions::Annotation do let(:message) { "lorem ipsum" } describe "#new" do it "fails when the type is wrong" do expect do described_class.new(:fatal, message, file: "file.txt") end.to raise_error(ArgumentError) end end describe "#to_s" do it "escapes newlines" do annotation = described_class.new(:warning, <<~EOS, file: "file.txt") lorem ipsum EOS expect(annotation.to_s).to eq "::warning file=file.txt::lorem%0Aipsum%0A" end it "allows specifying the file" do annotation = described_class.new(:warning, "lorem ipsum", file: "file.txt") expect(annotation.to_s).to eq "::warning file=file.txt::lorem ipsum" end it "allows specifying the title" do annotation = described_class.new(:warning, "lorem ipsum", file: "file.txt", title: "foo") expect(annotation.to_s).to eq "::warning file=file.txt,title=foo::lorem ipsum" end it "allows specifying the file and line" do annotation = described_class.new(:error, "lorem ipsum", file: "file.txt", line: 3) expect(annotation.to_s).to eq "::error file=file.txt,line=3::lorem ipsum" end it "allows specifying the file, line and column" do annotation = described_class.new(:error, "lorem ipsum", file: "file.txt", line: 3, column: 18) expect(annotation.to_s).to eq "::error file=file.txt,line=3,col=18::lorem ipsum" 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/utils/ast/formula_ast_spec.rb
Library/Homebrew/test/utils/ast/formula_ast_spec.rb
# frozen_string_literal: true require "utils/ast" RSpec.describe Utils::AST::FormulaAST do subject(:formula_ast) do described_class.new <<~RUBY class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" license all_of: [ :public_domain, "MIT", "GPL-3.0-or-later" => { with: "Autoconf-exception-3.0" }, ] end RUBY end describe "#replace_stanza" do it "replaces the specified stanza in a formula" do formula_ast.replace_stanza(:license, :public_domain) expect(formula_ast.process).to eq <<~RUBY class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" license :public_domain end RUBY end end describe "#add_stanza" do it "adds the specified stanza to a formula" do formula_ast.add_stanza(:revision, 1) expect(formula_ast.process).to eq <<~RUBY class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" license all_of: [ :public_domain, "MIT", "GPL-3.0-or-later" => { with: "Autoconf-exception-3.0" }, ] revision 1 end RUBY end end describe "#remove_stanza" do context "when stanza to be removed is a single line followed by a blank line" do subject(:formula_ast) do described_class.new <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" license :cannot_represent bottle do sha256 "f7b1fc772c79c20fddf621ccc791090bc1085fcef4da6cca03399424c66e06ca" => :sonoma end end RUBY end let(:new_contents) do <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" bottle do sha256 "f7b1fc772c79c20fddf621ccc791090bc1085fcef4da6cca03399424c66e06ca" => :sonoma end end RUBY end it "removes the line containing the stanza" do formula_ast.remove_stanza(:license) expect(formula_ast.process).to eq(new_contents) end end context "when stanza to be removed is a multiline block followed by a blank line" do subject(:formula_ast) do described_class.new <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" license all_of: [ :public_domain, "MIT", "GPL-3.0-or-later" => { with: "Autoconf-exception-3.0" }, ] bottle do sha256 "f7b1fc772c79c20fddf621ccc791090bc1085fcef4da6cca03399424c66e06ca" => :sonoma end end RUBY end let(:new_contents) do <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" bottle do sha256 "f7b1fc772c79c20fddf621ccc791090bc1085fcef4da6cca03399424c66e06ca" => :sonoma end end RUBY end it "removes the lines containing the stanza" do formula_ast.remove_stanza(:license) expect(formula_ast.process).to eq(new_contents) end end context "when stanza to be removed has a comment on the same line" do subject(:formula_ast) do described_class.new <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" license :cannot_represent # comment bottle do sha256 "f7b1fc772c79c20fddf621ccc791090bc1085fcef4da6cca03399424c66e06ca" => :sonoma end end RUBY end let(:new_contents) do <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" # comment bottle do sha256 "f7b1fc772c79c20fddf621ccc791090bc1085fcef4da6cca03399424c66e06ca" => :sonoma end end RUBY end it "removes the stanza but keeps the comment and its whitespace" do formula_ast.remove_stanza(:license) expect(formula_ast.process).to eq(new_contents) end end context "when stanza to be removed has a comment on the next line" do subject(:formula_ast) do described_class.new <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" license :cannot_represent # comment bottle do sha256 "f7b1fc772c79c20fddf621ccc791090bc1085fcef4da6cca03399424c66e06ca" => :sonoma end end RUBY end let(:new_contents) do <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" # comment bottle do sha256 "f7b1fc772c79c20fddf621ccc791090bc1085fcef4da6cca03399424c66e06ca" => :sonoma end end RUBY end it "removes the stanza but keeps the comment" do formula_ast.remove_stanza(:license) expect(formula_ast.process).to eq(new_contents) end end context "when stanza to be removed has newlines before and after" do subject(:formula_ast) do described_class.new <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" bottle do sha256 "f7b1fc772c79c20fddf621ccc791090bc1085fcef4da6cca03399424c66e06ca" => :sonoma end head do url "https://brew.sh/foo.git" branch "develop" end end RUBY end let(:new_contents) do <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" head do url "https://brew.sh/foo.git" branch "develop" end end RUBY end it "removes the stanza and preceding newline" do formula_ast.remove_stanza(:bottle) expect(formula_ast.process).to eq(new_contents) end end context "when stanza to be removed is at the end of the formula" do subject(:formula_ast) do described_class.new <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" license :cannot_represent bottle do sha256 "f7b1fc772c79c20fddf621ccc791090bc1085fcef4da6cca03399424c66e06ca" => :sonoma end end RUBY end let(:new_contents) do <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" license :cannot_represent end RUBY end it "removes the stanza and preceding newline" do formula_ast.remove_stanza(:bottle) expect(formula_ast.process).to eq(new_contents) end end end describe "#add_bottle_block" do let(:bottle_output) do <<-RUBY bottle do sha256 "f7b1fc772c79c20fddf621ccc791090bc1085fcef4da6cca03399424c66e06ca" => :sonoma end RUBY end context "when `license` is a string" do subject(:formula_ast) do described_class.new <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" license "MIT" end RUBY end let(:new_contents) do <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" license "MIT" bottle do sha256 "f7b1fc772c79c20fddf621ccc791090bc1085fcef4da6cca03399424c66e06ca" => :sonoma end end RUBY end it "adds `bottle` after `license`" do formula_ast.add_bottle_block(bottle_output) expect(formula_ast.process).to eq(new_contents) end end context "when `license` is a symbol" do subject(:formula_ast) do described_class.new <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" license :cannot_represent end RUBY end let(:new_contents) do <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" license :cannot_represent bottle do sha256 "f7b1fc772c79c20fddf621ccc791090bc1085fcef4da6cca03399424c66e06ca" => :sonoma end end RUBY end it "adds `bottle` after `license`" do formula_ast.add_bottle_block(bottle_output) expect(formula_ast.process).to eq(new_contents) end end context "when `license` is multiline" do subject(:formula_ast) do described_class.new <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" license all_of: [ :public_domain, "MIT", "GPL-3.0-or-later" => { with: "Autoconf-exception-3.0" }, ] end RUBY end let(:new_contents) do <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" license all_of: [ :public_domain, "MIT", "GPL-3.0-or-later" => { with: "Autoconf-exception-3.0" }, ] bottle do sha256 "f7b1fc772c79c20fddf621ccc791090bc1085fcef4da6cca03399424c66e06ca" => :sonoma end end RUBY end it "adds `bottle` after `license`" do formula_ast.add_bottle_block(bottle_output) expect(formula_ast.process).to eq(new_contents) end end context "when `head` is a string" do subject(:formula_ast) do described_class.new <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" head "https://brew.sh/foo.git", branch: "develop" end RUBY end let(:new_contents) do <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" head "https://brew.sh/foo.git", branch: "develop" bottle do sha256 "f7b1fc772c79c20fddf621ccc791090bc1085fcef4da6cca03399424c66e06ca" => :sonoma end end RUBY end it "adds `bottle` after `head`" do formula_ast.add_bottle_block(bottle_output) expect(formula_ast.process).to eq(new_contents) end end context "when `head` is a block" do subject(:formula_ast) do described_class.new <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" head do url "https://brew.sh/foo.git" branch "develop" end end RUBY end let(:new_contents) do <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" bottle do sha256 "f7b1fc772c79c20fddf621ccc791090bc1085fcef4da6cca03399424c66e06ca" => :sonoma end head do url "https://brew.sh/foo.git" branch "develop" end end RUBY end it "adds `bottle` before `head`" do formula_ast.add_bottle_block(bottle_output) expect(formula_ast.process).to eq(new_contents) end end context "when there is a comment on the same line" do subject(:formula_ast) do described_class.new <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" # comment end RUBY end let(:new_contents) do <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" # comment bottle do sha256 "f7b1fc772c79c20fddf621ccc791090bc1085fcef4da6cca03399424c66e06ca" => :sonoma end end RUBY end it "adds `bottle` after the comment" do formula_ast.add_bottle_block(bottle_output) expect(formula_ast.process).to eq(new_contents) end end context "when the next line is a comment" do subject(:formula_ast) do described_class.new <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" # comment end RUBY end let(:new_contents) do <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" # comment bottle do sha256 "f7b1fc772c79c20fddf621ccc791090bc1085fcef4da6cca03399424c66e06ca" => :sonoma end end RUBY end it "adds `bottle` after the comment" do formula_ast.add_bottle_block(bottle_output) expect(formula_ast.process).to eq(new_contents) end end context "when the next line is blank and the one after it is a comment" do subject(:formula_ast) do described_class.new <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" # comment end RUBY end let(:new_contents) do <<~RUBY.chomp class Foo < Formula url "https://brew.sh/foo-1.0.tar.gz" bottle do sha256 "f7b1fc772c79c20fddf621ccc791090bc1085fcef4da6cca03399424c66e06ca" => :sonoma end # comment end RUBY end it "adds `bottle` before the comment" do formula_ast.add_bottle_block(bottle_output) expect(formula_ast.process).to eq(new_contents) 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/utils/ast/ast_spec.rb
Library/Homebrew/test/utils/ast/ast_spec.rb
# frozen_string_literal: true require "utils/ast" RSpec.describe Utils::AST do describe ".stanza_text" do let(:compound_license) do <<-RUBY license all_of: [ :public_domain, "MIT", "GPL-3.0-or-later" => { with: "Autoconf-exception-3.0" }, ] RUBY end it "accepts existing stanza text" do expect(described_class.stanza_text(:revision, "revision 1")).to eq("revision 1") expect(described_class.stanza_text(:license, "license :public_domain")).to eq("license :public_domain") expect(described_class.stanza_text(:license, 'license "MIT"')).to eq('license "MIT"') expect(described_class.stanza_text(:license, compound_license)).to eq(compound_license) end it "accepts a number as the stanza value" do expect(described_class.stanza_text(:revision, 1)).to eq("revision 1") end it "accepts a symbol as the stanza value" do expect(described_class.stanza_text(:license, :public_domain)).to eq("license :public_domain") end it "accepts a string as the stanza value" do expect(described_class.stanza_text(:license, "MIT")).to eq('license "MIT"') end it "adds indent to stanza text if specified" do expect(described_class.stanza_text(:revision, "revision 1", indent: 2)).to eq(" revision 1") expect(described_class.stanza_text(:license, 'license "MIT"', indent: 2)).to eq(' license "MIT"') expect(described_class.stanza_text(:license, compound_license, indent: 2)).to eq(compound_license) end it "does not add indent if already indented" do expect(described_class.stanza_text(:revision, " revision 1", indent: 2)).to eq(" revision 1") expect( described_class.stanza_text(:license, compound_license, indent: 2), ).to eq(compound_license) 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/requirements/arch_requirement_spec.rb
Library/Homebrew/test/requirements/arch_requirement_spec.rb
# frozen_string_literal: true require "requirements/arch_requirement" RSpec.describe ArchRequirement do subject(:requirement) { described_class.new([Hardware::CPU.type]) } describe "#satisfied?" do it "supports architecture symbols" do expect(requirement).to be_satisfied 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/requirements/codesign_requirement_spec.rb
Library/Homebrew/test/requirements/codesign_requirement_spec.rb
# frozen_string_literal: true require "requirements/codesign_requirement" RSpec.describe CodesignRequirement do subject(:requirement) do described_class.new([{ identity:, with:, url: }]) end let(:identity) { "lldb_codesign" } let(:with) { "LLDB" } let(:url) do "https://llvm.org/svn/llvm-project/lldb/trunk/docs/code-signing.txt" end describe "#message" do it "includes all parameters" do expect(requirement.message).to include(identity) expect(requirement.message).to include(with) expect(requirement.message).to include(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/requirements/linux_requirement_spec.rb
Library/Homebrew/test/requirements/linux_requirement_spec.rb
# frozen_string_literal: true require "requirements/linux_requirement" RSpec.describe LinuxRequirement do subject(:requirement) { described_class.new } describe "#satisfied?" do it "returns true on Linux" do expect(requirement.satisfied?).to eq(OS.linux?) 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/requirements/macos_requirement_spec.rb
Library/Homebrew/test/requirements/macos_requirement_spec.rb
# frozen_string_literal: true require "requirements/macos_requirement" RSpec.describe MacOSRequirement do subject(:requirement) { described_class.new } let(:macos_oldest_allowed) { MacOSVersion.new(HOMEBREW_MACOS_OLDEST_ALLOWED) } let(:macos_newest_allowed) { MacOSVersion.new(HOMEBREW_MACOS_NEWEST_UNSUPPORTED) } let(:tahoe_major) { MacOSVersion.new("26.0") } describe "#satisfied?" do it "returns true on macOS" do expect(requirement.satisfied?).to eq OS.mac? end it "supports version symbols", :needs_macos do requirement = described_class.new([MacOS.version.to_sym]) expect(requirement).to be_satisfied end it "supports maximum versions", :needs_macos do requirement = described_class.new([:catalina], comparator: "<=") expect(requirement.satisfied?).to eq MacOS.version <= :catalina end end specify "#minimum_version" do no_requirement = described_class.new max_requirement = described_class.new([:tahoe], comparator: "<=") min_requirement = described_class.new([:tahoe], comparator: ">=") exact_requirement = described_class.new([:tahoe], comparator: "==") range_requirement = described_class.new([[:sonoma, :tahoe]], comparator: "==") expect(no_requirement.minimum_version).to eq macos_oldest_allowed expect(max_requirement.minimum_version).to eq macos_oldest_allowed expect(min_requirement.minimum_version).to eq tahoe_major expect(exact_requirement.minimum_version).to eq tahoe_major expect(range_requirement.minimum_version).to eq "14" end specify "#maximum_version" do no_requirement = described_class.new max_requirement = described_class.new([:tahoe], comparator: "<=") min_requirement = described_class.new([:tahoe], comparator: ">=") exact_requirement = described_class.new([:tahoe], comparator: "==") range_requirement = described_class.new([[:sonoma, :tahoe]], comparator: "==") expect(no_requirement.maximum_version).to eq macos_newest_allowed expect(max_requirement.maximum_version).to eq tahoe_major expect(min_requirement.maximum_version).to eq macos_newest_allowed expect(exact_requirement.maximum_version).to eq tahoe_major expect(range_requirement.maximum_version).to eq tahoe_major end specify "#allows?" do no_requirement = described_class.new max_requirement = described_class.new([:sequoia], comparator: "<=") min_requirement = described_class.new([:ventura], comparator: ">=") exact_requirement = described_class.new([:tahoe], comparator: "==") range_requirement = described_class.new([[:sonoma, :tahoe]], comparator: "==") expect(no_requirement.allows?(tahoe_major)).to be true expect(max_requirement.allows?(tahoe_major)).to be false expect(min_requirement.allows?(tahoe_major)).to be true expect(exact_requirement.allows?(tahoe_major)).to be true expect(range_requirement.allows?(tahoe_major)).to be true 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/api/internal_spec.rb
Library/Homebrew/test/api/internal_spec.rb
# frozen_string_literal: true require "api/internal" RSpec.describe Homebrew::API::Internal do let(:cache_dir) { mktmpdir } before do FileUtils.mkdir_p(cache_dir/"internal") stub_const("Homebrew::API::HOMEBREW_CACHE_API", cache_dir) end def mock_curl_download(stdout:) allow(Utils::Curl).to receive(:curl_download) do |*_args, **kwargs| kwargs[:to].write stdout end allow(Homebrew::API).to receive(:verify_and_parse_jws) do |json_data| [true, json_data] end end context "for formulae" do let(:formula_json) do <<~JSON { "formulae": { "foo": ["1.0.0", 0, 0, "09f88b61e36045188ddb1b1ba8e402b9f3debee1770cc4ca91355eeccb5f4a38"], "bar": ["0.4.0_5", 1, 0, "bb6e3408f39a404770529cfce548dc2666e861077acd173825cb3138c27c205a"], "baz": ["10.4.5_2", 0, 2, "404c97537d65ca0b75c389e7d439dcefb9b56f34d3b98017669eda0d0501add7"] }, "aliases": { "foo-alias1": "foo", "foo-alias2": "foo", "bar-alias": "bar" }, "renames": { "foo-old": "foo", "bar-old": "bar", "baz-old": "baz" }, "tap_migrations": { "abc": "some/tap", "def": "another/tap" } } JSON end let(:formula_arrays) do { "foo" => ["1.0.0", 0, 0, "09f88b61e36045188ddb1b1ba8e402b9f3debee1770cc4ca91355eeccb5f4a38"], "bar" => ["0.4.0_5", 1, 0, "bb6e3408f39a404770529cfce548dc2666e861077acd173825cb3138c27c205a"], "baz" => ["10.4.5_2", 0, 2, "404c97537d65ca0b75c389e7d439dcefb9b56f34d3b98017669eda0d0501add7"], } end let(:formula_stubs) do formula_arrays.to_h do |name, (pkg_version, version_scheme, rebuild, sha256)| stub = Homebrew::FormulaStub.new( name: name, pkg_version: PkgVersion.parse(pkg_version), version_scheme: version_scheme, rebuild: rebuild, sha256: sha256, aliases: formulae_aliases.select { |_, new_name| new_name == name }.keys, oldnames: formulae_renames.select { |_, new_name| new_name == name }.keys, ) [name, stub] end end let(:formulae_aliases) do { "foo-alias1" => "foo", "foo-alias2" => "foo", "bar-alias" => "bar", } end let(:formulae_renames) do { "foo-old" => "foo", "bar-old" => "bar", "baz-old" => "baz", } end let(:formula_tap_migrations) do { "abc" => "some/tap", "def" => "another/tap", } end it "returns the expected formula stubs" do mock_curl_download stdout: formula_json formula_stubs.each do |name, stub| expect(described_class.formula_stub(name)).to eq stub end end it "returns the expected formula arrays" do mock_curl_download stdout: formula_json formula_arrays_output = described_class.formula_arrays expect(formula_arrays_output).to eq formula_arrays end it "returns the expected formula alias list" do mock_curl_download stdout: formula_json formula_aliases_output = described_class.formula_aliases expect(formula_aliases_output).to eq formulae_aliases end it "returns the expected formula rename list" do mock_curl_download stdout: formula_json formula_renames_output = described_class.formula_renames expect(formula_renames_output).to eq formulae_renames end it "returns the expected formula tap migrations list" do mock_curl_download stdout: formula_json formula_tap_migrations_output = described_class.formula_tap_migrations expect(formula_tap_migrations_output).to eq formula_tap_migrations end end context "for casks" do let(:cask_json) do <<~JSON { "casks": { "foo": { "version": "1.0.0" }, "bar": { "version": "0.4.0" }, "baz": { "version": "10.4.5" } }, "renames": { "foo-old": "foo", "bar-old": "bar", "baz-old": "baz" }, "tap_migrations": { "abc": "some/tap", "def": "another/tap" } } JSON end let(:cask_hashes) do { "foo" => { "version" => "1.0.0" }, "bar" => { "version" => "0.4.0" }, "baz" => { "version" => "10.4.5" }, } end let(:cask_renames) do { "foo-old" => "foo", "bar-old" => "bar", "baz-old" => "baz", } end let(:cask_tap_migrations) do { "abc" => "some/tap", "def" => "another/tap", } end it "returns the expected cask hashes" do mock_curl_download stdout: cask_json cask_hashes_output = described_class.cask_hashes expect(cask_hashes_output).to eq cask_hashes end it "returns the expected cask rename list" do mock_curl_download stdout: cask_json cask_renames_output = described_class.cask_renames expect(cask_renames_output).to eq cask_renames end it "returns the expected cask tap migrations list" do mock_curl_download stdout: cask_json cask_tap_migrations_output = described_class.cask_tap_migrations expect(cask_tap_migrations_output).to eq cask_tap_migrations 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/api/cask_spec.rb
Library/Homebrew/test/api/cask_spec.rb
# frozen_string_literal: true require "api" RSpec.describe Homebrew::API::Cask do let(:cache_dir) { mktmpdir } before do stub_const("Homebrew::API::HOMEBREW_CACHE_API", cache_dir) end def mock_curl_download(stdout:) allow(Utils::Curl).to receive(:curl_download) do |*_args, **kwargs| kwargs[:to].write stdout end allow(Homebrew::API).to receive(:verify_and_parse_jws) do |json_data| [true, json_data] end end describe "::all_casks" do let(:casks_json) do <<~EOS [{ "token": "foo", "url": "https://brew.sh/foo" }, { "token": "bar", "url": "https://brew.sh/bar" }] EOS end let(:casks_hash) do { "foo" => { "url" => "https://brew.sh/foo" }, "bar" => { "url" => "https://brew.sh/bar" }, } end it "returns the expected cask JSON list" do mock_curl_download stdout: casks_json casks_output = described_class.all_casks expect(casks_output).to eq casks_hash end end describe "::source_download", :needs_macos do let(:cask) do cask = Cask::CaskLoader::FromAPILoader.new( "everything", from_json: JSON.parse((TEST_FIXTURE_DIR/"cask/everything.json").read.strip), ).load(config: nil) cask end before do allow(Homebrew::API).to receive(:fetch_json_api_file).and_return([[], true]) allow_any_instance_of(Homebrew::API::SourceDownload).to receive(:fetch) allow_any_instance_of(Homebrew::API::SourceDownload).to receive(:symlink_location).and_return( TEST_FIXTURE_DIR/"cask/Casks/everything.rb", ) end it "specifies the correct URL and sha256" do expect(Homebrew::API::SourceDownload).to receive(:new).with( "https://raw.githubusercontent.com/Homebrew/homebrew-cask/abcdef1234567890abcdef1234567890abcdef12/Casks/everything.rb", Checksum.new("d3c19b564ee5a17f22191599ad795a6cc9c4758d0e1269f2d13207155b378dea"), any_args, ).and_call_original described_class.source_download(cask) 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/api/formula_spec.rb
Library/Homebrew/test/api/formula_spec.rb
# frozen_string_literal: true require "api" RSpec.describe Homebrew::API::Formula do let(:cache_dir) { mktmpdir } before do stub_const("Homebrew::API::HOMEBREW_CACHE_API", cache_dir) end def mock_curl_download(stdout:) allow(Utils::Curl).to receive(:curl_download) do |*_args, **kwargs| kwargs[:to].write stdout end allow(Homebrew::API).to receive(:verify_and_parse_jws) do |json_data| [true, json_data] end end describe "::all_formulae" do let(:formulae_json) do <<~EOS [{ "name": "foo", "url": "https://brew.sh/foo", "aliases": ["foo-alias1", "foo-alias2"] }, { "name": "bar", "url": "https://brew.sh/bar", "aliases": ["bar-alias"] }, { "name": "baz", "url": "https://brew.sh/baz", "aliases": [] }] EOS end let(:formulae_hash) do { "foo" => { "url" => "https://brew.sh/foo", "aliases" => ["foo-alias1", "foo-alias2"] }, "bar" => { "url" => "https://brew.sh/bar", "aliases" => ["bar-alias"] }, "baz" => { "url" => "https://brew.sh/baz", "aliases" => [] }, } end let(:formulae_aliases) do { "foo-alias1" => "foo", "foo-alias2" => "foo", "bar-alias" => "bar", } end it "returns the expected formula JSON list" do mock_curl_download stdout: formulae_json formulae_output = described_class.all_formulae expect(formulae_output).to eq formulae_hash end it "returns the expected formula alias list" do mock_curl_download stdout: formulae_json aliases_output = described_class.all_aliases expect(aliases_output).to eq formulae_aliases 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/keg_relocate/text_spec.rb
Library/Homebrew/test/keg_relocate/text_spec.rb
# frozen_string_literal: true require "keg_relocate" RSpec.describe Keg do subject(:keg) { described_class.new(HOMEBREW_CELLAR/"foo/1.0.0") } let(:dir) { mktmpdir } let(:file) { dir/"file.txt" } let(:placeholder) { "@@PLACEHOLDER@@" } before do (HOMEBREW_CELLAR/"foo/1.0.0").mkpath end def setup_file(placeholders: false) path = placeholders ? placeholder : dir file.atomic_write <<~EOS #{path}/file.txt /foo#{path}/file.txt foo/bar:#{path}/file.txt foo/bar:/foo#{path}/file.txt #{path}/bar.txt:#{path}/baz.txt EOS end def setup_relocation(placeholders: false) relocation = described_class::Relocation.new if placeholders relocation.add_replacement_pair :dir, placeholder, dir.to_s else relocation.add_replacement_pair :dir, dir.to_s, placeholder, path: true end relocation end specify "::text_matches_in_file" do setup_file result = described_class.text_matches_in_file(file, placeholder, [], [], nil) expect(result.count).to eq 0 result = described_class.text_matches_in_file(file, dir.to_s, [], [], nil) expect(result.count).to eq 2 end describe "#replace_text_in_files" do specify "with paths" do setup_file relocation = setup_relocation keg.replace_text_in_files(relocation, files: [file]) contents = File.read file expect(contents).to eq <<~EOS #{placeholder}/file.txt /foo#{dir}/file.txt foo/bar:#{placeholder}/file.txt foo/bar:/foo#{dir}/file.txt #{placeholder}/bar.txt:#{placeholder}/baz.txt EOS end specify "with placeholders" do setup_file placeholders: true relocation = setup_relocation placeholders: true keg.replace_text_in_files(relocation, files: [file]) contents = File.read file expect(contents).to eq <<~EOS #{dir}/file.txt /foo#{dir}/file.txt foo/bar:#{dir}/file.txt foo/bar:/foo#{dir}/file.txt #{dir}/bar.txt:#{dir}/baz.txt EOS 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/keg_relocate/binary_relocation_spec.rb
Library/Homebrew/test/keg_relocate/binary_relocation_spec.rb
# frozen_string_literal: true require "keg_relocate" RSpec.describe Keg do subject(:keg) { described_class.new(HOMEBREW_CELLAR/"foo/1.0.0") } let(:dir) { HOMEBREW_CELLAR/"foo/1.0.0" } let(:newdir) { HOMEBREW_CELLAR/"foo" } let(:binary_file) { dir/"file.bin" } before do dir.mkpath end def setup_binary_file binary_file.atomic_write <<~EOS \x00#{dir}\x00 EOS end describe "#relocate_build_prefix" do specify "replace prefix in binary files" do setup_binary_file keg.relocate_build_prefix(keg, dir, newdir) old_prefix_matches = Set.new keg.each_unique_file_matching(dir) do |file| old_prefix_matches << file end expect(old_prefix_matches.size).to eq 0 new_prefix_matches = Set.new keg.each_unique_file_matching(newdir) do |file| new_prefix_matches << file end expect(new_prefix_matches.size).to eq 1 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/keg_relocate/relocation_spec.rb
Library/Homebrew/test/keg_relocate/relocation_spec.rb
# frozen_string_literal: true require "keg_relocate" RSpec.describe Keg::Relocation do let(:prefix) { HOMEBREW_PREFIX.to_s } let(:cellar) { HOMEBREW_CELLAR.to_s } let(:repository) { HOMEBREW_REPOSITORY.to_s } let(:library) { HOMEBREW_LIBRARY.to_s } let(:prefix_placeholder) { "@@HOMEBREW_PREFIX@@" } let(:cellar_placeholder) { "@@HOMEBREW_CELLAR@@" } let(:repository_placeholder) { "@@HOMEBREW_REPOSITORY@@" } let(:library_placeholder) { "@@HOMEBREW_LIBRARY@@" } let(:escaped_prefix) { /(?:(?<=-F|-I|-L|-isystem)|(?<![a-zA-Z0-9]))#{Regexp.escape(HOMEBREW_PREFIX)}/o } let(:escaped_cellar) { /(?:(?<=-F|-I|-L|-isystem)|(?<![a-zA-Z0-9]))#{HOMEBREW_CELLAR}/o } def setup_relocation relocation = described_class.new relocation.add_replacement_pair :prefix, prefix, prefix_placeholder, path: true relocation.add_replacement_pair :cellar, /#{cellar}/o, cellar_placeholder, path: true relocation.add_replacement_pair :repository_placeholder, repository_placeholder, repository relocation.add_replacement_pair :library_placeholder, library_placeholder, library relocation end specify "#add_replacement_pair" do relocation = setup_relocation expect(relocation.replacement_pair_for(:prefix)).to eq [escaped_prefix, prefix_placeholder] expect(relocation.replacement_pair_for(:cellar)).to eq [escaped_cellar, cellar_placeholder] expect(relocation.replacement_pair_for(:repository_placeholder)).to eq [repository_placeholder, repository] expect(relocation.replacement_pair_for(:library_placeholder)).to eq [library_placeholder, library] end specify "#replace_text!" do relocation = setup_relocation text = +"foo" relocation.replace_text!(text) expect(text).to eq "foo" text = <<~TEXT #{prefix}/foo #{cellar}/foo foo#{prefix}/bar foo#{cellar}/bar #{repository_placeholder}/foo foo#{library_placeholder}/bar TEXT relocation.replace_text!(text) expect(text).to eq <<~REPLACED #{prefix_placeholder}/foo #{cellar_placeholder}/foo foo#{prefix}/bar foo#{cellar}/bar #{repository}/foo foo#{library}/bar REPLACED end specify "::path_to_regex" do expect(described_class.path_to_regex(prefix)).to eq escaped_prefix expect(described_class.path_to_regex("foo.bar")).to eq(/(?:(?<=-F|-I|-L|-isystem)|(?<![a-zA-Z0-9]))foo\.bar/) expect(described_class.path_to_regex(/#{cellar}/o)).to eq escaped_cellar expect(described_class.path_to_regex(/foo.bar/)).to eq(/(?:(?<=-F|-I|-L|-isystem)|(?<![a-zA-Z0-9]))foo.bar/) 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/keg_relocate/grep_spec.rb
Library/Homebrew/test/keg_relocate/grep_spec.rb
# frozen_string_literal: true require "keg_relocate" RSpec.describe Keg do subject(:keg) { described_class.new(HOMEBREW_CELLAR/"foo/1.0.0") } let(:dir) { HOMEBREW_CELLAR/"foo/1.0.0" } let(:text_file) { dir/"file.txt" } let(:binary_file) { dir/"file.bin" } before do dir.mkpath end def setup_text_file text_file.atomic_write <<~EOS #{dir}/file.txt /foo#{dir}/file.txt foo/bar:#{dir}/file.txt foo/bar:/foo#{dir}/file.txt #{dir}/bar.txt:#{dir}/baz.txt EOS end def setup_binary_file binary_file.atomic_write <<~EOS \x00 EOS end describe "#each_unique_file_matching" do specify "find string matches to path" do setup_text_file string_matches = Set.new keg.each_unique_file_matching(dir) do |file| string_matches << file end expect(string_matches.size).to eq 1 end end describe "#binary_file?" do specify "test if file has null bytes" do setup_binary_file expect(keg.binary_file?(binary_file)).to be true setup_text_file expect(keg.binary_file?(text_file)).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/download_strategies/subversion_spec.rb
Library/Homebrew/test/download_strategies/subversion_spec.rb
# frozen_string_literal: true require "download_strategy" RSpec.describe SubversionDownloadStrategy do subject(:strategy) { described_class.new(url, name, version, **specs) } let(:name) { "foo" } let(:url) { "https://example.com/foo.tar.gz" } let(:version) { "1.2.3" } let(:specs) { {} } describe "#fetch" do context "with :trust_cert set" do let(:specs) { { trust_cert: true } } it "adds the appropriate svn args" do expect(strategy).to receive(:system_command!) .with("svn", hash_including(args: array_including("--trust-server-cert", "--non-interactive"))) .and_return(instance_double(SystemCommand::Result)) strategy.fetch end end context "with :revision set" do let(:specs) { { revision: "10" } } it "adds svn arguments for :revision" do expect(strategy).to receive(:system_command!) .with("svn", hash_including(args: array_including_cons("-r", "10"))) .and_return(instance_double(SystemCommand::Result)) strategy.fetch 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/download_strategies/curl_github_packages_spec.rb
Library/Homebrew/test/download_strategies/curl_github_packages_spec.rb
# frozen_string_literal: true require "download_strategy" RSpec.describe CurlGitHubPackagesDownloadStrategy do subject(:strategy) { described_class.new(url, name, version, **specs) } let(:name) { "foo" } let(:url) { "https://#{GitHubPackages::URL_DOMAIN}/v2/homebrew/core/spec_test/manifests/1.2.3" } let(:version) { "1.2.3" } let(:specs) { { headers: ["Accept: application/vnd.oci.image.index.v1+json"] } } let(:authorization) { nil } let(:head_response) do <<~HTTP HTTP/2 200\r content-length: 12671\r content-type: application/vnd.oci.image.index.v1+json\r docker-content-digest: sha256:7d752ee92d9120e3884b452dce15328536a60d468023ea8e9f4b09839a5442e5\r docker-distribution-api-version: registry/2.0\r etag: "sha256:7d752ee92d9120e3884b452dce15328536a60d468023ea8e9f4b09839a5442e5"\r date: Sun, 02 Apr 2023 22:45:08 GMT\r x-github-request-id: 8814:FA5A:14DAFB5:158D7A2:642A0574\r HTTP end describe "#fetch" do before do stub_const("HOMEBREW_GITHUB_PACKAGES_AUTH", authorization) if authorization.present? allow(strategy).to receive(:curl_version).and_return(Version.new("8.7.1")) allow(strategy).to receive(:system_command) .with( /curl/, hash_including(args: array_including("--head")), ) .twice .and_return(instance_double( SystemCommand::Result, success?: true, exit_status: instance_double(Process::Status, exitstatus: 0), stdout: head_response, )) strategy.temporary_path.dirname.mkpath FileUtils.touch strategy.temporary_path end it "calls curl with anonymous authentication headers" do expect(strategy).to receive(:system_command) .with( /curl/, hash_including(args: array_including_cons("--header", "Authorization: Bearer QQ==")), ) .at_least(:once) .and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) strategy.fetch end context "with GitHub Packages authentication defined" do let(:authorization) { "Bearer dead-beef-cafe" } it "calls curl with the provided header value" do expect(strategy).to receive(:system_command) .with( /curl/, hash_including(args: array_including_cons("--header", "Authorization: #{authorization}")), ) .at_least(:once) .and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) strategy.fetch 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/download_strategies/git_spec.rb
Library/Homebrew/test/download_strategies/git_spec.rb
# frozen_string_literal: true require "download_strategy" RSpec.describe GitDownloadStrategy do subject(:strategy) { described_class.new(url, name, version) } let(:name) { "baz" } let(:url) { "https://github.com/homebrew/foo" } let(:version) { nil } let(:cached_location) { subject.cached_location } before do @commit_id = 1 FileUtils.mkpath cached_location end def git_commit_all system "git", "add", "--all" # Allow instance variables here to have nice commit messages. # rubocop:disable RSpec/InstanceVariable system "git", "commit", "-m", "commit number #{@commit_id}" @commit_id += 1 # rubocop:enable RSpec/InstanceVariable end def setup_git_repo system "git", "-c", "init.defaultBranch=master", "init" system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo" FileUtils.touch "README" git_commit_all end describe "#source_modified_time" do it "returns the right modification time" do cached_location.cd do setup_git_repo end expect(strategy.source_modified_time.to_i).to eq(1_485_115_153) end end specify "#last_commit" do cached_location.cd do setup_git_repo FileUtils.touch "LICENSE" git_commit_all end expect(strategy.last_commit).to eq("f68266e") end describe "#fetch_last_commit" do let(:url) { "file://#{remote_repo}" } let(:version) { Version.new("HEAD") } let(:remote_repo) { HOMEBREW_PREFIX/"remote_repo" } before { remote_repo.mkpath } after { FileUtils.rm_rf remote_repo } it "fetches the hash of the last commit" do remote_repo.cd do setup_git_repo FileUtils.touch "LICENSE" git_commit_all end expect(strategy.fetch_last_commit).to eq("f68266e") 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/download_strategies/vcs_spec.rb
Library/Homebrew/test/download_strategies/vcs_spec.rb
# frozen_string_literal: true require "download_strategy" RSpec.describe VCSDownloadStrategy do let(:url) { "https://example.com/bar" } let(:version) { nil } describe "#cached_location" do it "returns the path of the cached resource" do allow_any_instance_of(described_class).to receive(:cache_tag).and_return("foo") downloader = Class.new(described_class).new(url, "baz", version) expect(downloader.cached_location).to eq(HOMEBREW_CACHE/"baz--foo") 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/download_strategies/curl_spec.rb
Library/Homebrew/test/download_strategies/curl_spec.rb
# frozen_string_literal: true require "download_strategy" RSpec.describe CurlDownloadStrategy do subject(:strategy) { described_class.new(url, name, version, **specs) } let(:name) { "foo" } let(:url) { "https://example.com/foo.tar.gz" } let(:version) { "1.2.3" } let(:specs) { { user: "download:123456" } } let(:artifact_domain) { nil } let(:headers) do { "accept-ranges" => "bytes", "content-length" => "37182", } end before do allow(strategy).to receive(:curl_headers).with(any_args) .and_return({ responses: [{ headers: }] }) end it "parses the opts and sets the corresponding args" do expect(strategy.send(:_curl_args)).to eq(["--user", "download:123456"]) end describe "#fetch" do before do allow(Homebrew::EnvConfig).to receive(:artifact_domain).and_return(artifact_domain) strategy.temporary_path.dirname.mkpath FileUtils.touch strategy.temporary_path end it "calls curl with default arguments" do expect(strategy).to receive(:curl).with( "--remote-time", "--output", an_instance_of(String), # example.com supports partial requests. "--continue-at", "-", "--location", url, an_instance_of(Hash) ) strategy.fetch end context "with an explicit user agent" do let(:specs) { { user_agent: "Mozilla/25.0.1" } } it "adds the appropriate curl args" do expect(strategy).to receive(:system_command) .with( /curl/, hash_including(args: array_including_cons("--user-agent", "Mozilla/25.0.1")), ) .at_least(:once) .and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) strategy.fetch end end context "with a generalized fake user agent" do alias_matcher :a_string_matching, :match let(:specs) { { user_agent: :fake } } it "adds the appropriate curl args" do expect(strategy).to receive(:system_command) .with( /curl/, hash_including(args: array_including_cons( "--user-agent", a_string_matching(/Mozilla.*Mac OS X 10_15_7.*AppleWebKit/), )), ) .at_least(:once) .and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) strategy.fetch end end context "with cookies set" do let(:specs) do { cookies: { coo: "k/e", mon: "ster", }, } end it "adds the appropriate curl args and does not URL-encode the cookies" do expect(strategy).to receive(:system_command) .with( /curl/, hash_including(args: array_including_cons("-b", "coo=k/e;mon=ster")), ) .at_least(:once) .and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) strategy.fetch end end context "with referer set" do let(:specs) { { referer: "https://somehost/also" } } it "adds the appropriate curl args" do expect(strategy).to receive(:system_command) .with( /curl/, hash_including(args: array_including_cons("-e", "https://somehost/also")), ) .at_least(:once) .and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) strategy.fetch end end context "with headers set" do alias_matcher :a_string_matching, :match let(:specs) { { headers: ["foo", "bar"] } } it "adds the appropriate curl args" do expect(strategy).to receive(:system_command) .with( /curl/, hash_including( args: array_including_cons("--header", "foo").and(array_including_cons("--header", "bar")), ), ) .at_least(:once) .and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) strategy.fetch end end context "with artifact_domain set" do let(:artifact_domain) { "https://mirror.example.com/oci" } context "with an asset hosted under example.com" do it "leaves the URL unchanged" do expect(strategy).to receive(:system_command) .with( /curl/, hash_including(args: array_including_cons(url)), ) .at_least(:once) .and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) strategy.fetch end end context "with an asset hosted under #{GitHubPackages::URL_DOMAIN} (HTTP)" do let(:resource_path) { "v2/homebrew/core/spec/manifests/0.0" } let(:url) { "http://#{GitHubPackages::URL_DOMAIN}/#{resource_path}" } let(:status) { instance_double(Process::Status, success?: true, exitstatus: 0) } it "rewrites the URL correctly" do expect(strategy).to receive(:system_command) .with( /curl/, hash_including(args: array_including_cons("#{artifact_domain}/#{resource_path}")), ) .at_least(:once) .and_return(SystemCommand::Result.new(["curl"], [[:stdout, ""]], status, secrets: [])) strategy.fetch end end context "with an asset hosted under #{GitHubPackages::URL_DOMAIN} (HTTPS)" do let(:resource_path) { "v2/homebrew/core/spec/manifests/0.0" } let(:url) { "https://#{GitHubPackages::URL_DOMAIN}/#{resource_path}" } let(:status) { instance_double(Process::Status, success?: true, exitstatus: 0) } it "rewrites the URL correctly" do expect(strategy).to receive(:system_command) .with( /curl/, hash_including(args: array_including_cons("#{artifact_domain}/#{resource_path}")), ) .at_least(:once) .and_return(SystemCommand::Result.new(["curl"], [[:stdout, ""]], status, secrets: [])) strategy.fetch end end end end describe "#cached_location" do subject(:cached_location) { strategy.cached_location } context "when URL ends with file" do it "falls back to the file name in the URL" do expect(cached_location).to eq( HOMEBREW_CACHE/"downloads/3d1c0ae7da22be9d83fb1eb774df96b7c4da71d3cf07e1cb28555cf9a5e5af70--foo.tar.gz", ) end end context "when URL file is in middle" do let(:url) { "https://example.com/foo.tar.gz/from/this/mirror" } it "falls back to the file name in the URL" do expect(cached_location).to eq( HOMEBREW_CACHE/"downloads/1ab61269ba52c83994510b1e28dd04167a2f2e8393a35a9c50c1f7d33fd8f619--foo.tar.gz", ) end end context "with a file name trailing the URL path" do let(:url) { "https://example.com/cask.dmg" } it "falls back to the file extension in the URL" do expect(cached_location.extname).to eq(".dmg") end end context "with a file name trailing the first query parameter" do let(:url) { "https://example.com/download?file=cask.zip&a=1" } it "falls back to the file extension in the URL" do expect(cached_location.extname).to eq(".zip") end end context "with a file name trailing the second query parameter" do let(:url) { "https://example.com/dl?a=1&file=cask.zip&b=2" } it "falls back to the file extension in the URL" do expect(cached_location.extname).to eq(".zip") end end context "with an unusually long query string" do let(:url) do [ "https://node49152.ssl.fancycdn.example.com", "/fancycdn/node/49152/file/upload/download", "?cask_class=zf920df", "&cask_group=2348779087242312", "&cask_archive_file_name=cask.zip", "&signature=CGmDulxL8pmutKTlCleNTUY%2FyO9Xyl5u9yVZUE0", "uWrjadjuz67Jp7zx3H7NEOhSyOhu8nzicEHRBjr3uSoOJzwkLC8L", "BLKnz%2B2X%2Biq5m6IdwSVFcLp2Q1Hr2kR7ETn3rF1DIq5o0lHC", "yzMmyNe5giEKJNW8WF0KXriULhzLTWLSA3ZTLCIofAdRiiGje1kN", "YY3C0SBqymQB8CG3ONn5kj7CIGbxrDOq5xI2ZSJdIyPysSX7SLvE", "DBw2KdR24q9t1wfjS9LUzelf5TWk6ojj8p9%2FHjl%2Fi%2FVCXN", "N4o1mW%2FMayy2tTY1qcC%2FTmqI1ulZS8SNuaSgr9Iys9oDF1%2", "BPK%2B4Sg==", ].join end it "falls back to the file extension in the URL" do expect(cached_location.extname).to eq(".zip") expect(cached_location.to_path.length).to be_between(0, 255) 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/download_strategies/abstract_spec.rb
Library/Homebrew/test/download_strategies/abstract_spec.rb
# frozen_string_literal: true require "download_strategy" RSpec.describe AbstractDownloadStrategy do subject(:strategy) { Class.new(described_class).new(url, name, version, **specs) } let(:specs) { {} } let(:name) { "foo" } let(:url) { "https://example.com/foo.tar.gz" } let(:version) { nil } let(:args) { %w[foo bar baz] } specify "#source_modified_time" do mktmpdir("mtime").cd do FileUtils.touch "foo", mtime: Time.now - 10 FileUtils.touch "bar", mtime: Time.now - 100 FileUtils.ln_s "not-exist", "baz" expect(strategy.source_modified_time).to eq(File.mtime("foo")) 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/download_strategies/curl_post_spec.rb
Library/Homebrew/test/download_strategies/curl_post_spec.rb
# frozen_string_literal: true require "download_strategy" RSpec.describe CurlPostDownloadStrategy do subject(:strategy) { described_class.new(url, name, version, **specs) } let(:name) { "foo" } let(:url) { "https://example.com/foo.tar.gz" } let(:version) { "1.2.3" } let(:specs) { {} } let(:head_response) do <<~HTTP HTTP/1.1 200\r Content-Disposition: attachment; filename="foo.tar.gz" HTTP end describe "#fetch" do before do allow(strategy).to receive(:curl_version).and_return(Version.new("8.6.0")) allow(strategy).to receive(:system_command) .with( /curl/, hash_including(args: array_including("--head")), ) .twice .and_return(instance_double( SystemCommand::Result, success?: true, exit_status: instance_double(Process::Status, exitstatus: 0), stdout: head_response, )) strategy.temporary_path.dirname.mkpath FileUtils.touch strategy.temporary_path end context "with :using and :data specified" do let(:specs) do { using: :post, data: { form: "data", is: "good", }, } end it "adds the appropriate curl args" do expect(strategy).to receive(:system_command) .with( /curl/, hash_including(args: array_including_cons("-d", "form=data").and(array_including_cons("-d", "is=good"))), ) .at_least(:once) .and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) strategy.fetch end end context "with :using but no :data" do let(:specs) { { using: :post } } it "adds the appropriate curl args" do expect(strategy).to receive(:system_command) .with( /curl/, hash_including(args: array_including_cons("-X", "POST")), ) .at_least(:once) .and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) strategy.fetch 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/download_strategies/github_git_spec.rb
Library/Homebrew/test/download_strategies/github_git_spec.rb
# frozen_string_literal: true require "download_strategy" RSpec.describe GitHubGitDownloadStrategy do subject(:strategy) { described_class.new(url, name, version) } let(:name) { "brew" } let(:url) { "https://github.com/homebrew/brew.git" } let(:version) { nil } it "parses the URL and sets the corresponding instance variables" do expect(strategy.instance_variable_get(:@user)).to eq("homebrew") expect(strategy.instance_variable_get(:@repo)).to eq("brew") 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/download_strategies/detector_spec.rb
Library/Homebrew/test/download_strategies/detector_spec.rb
# frozen_string_literal: true require "download_strategy" RSpec.describe DownloadStrategyDetector do describe "::detect" do subject(:strategy_detector) { described_class.detect(url, strategy) } let(:url) { "invalidurl" } let(:strategy) { nil } context "when given Git URL" do let(:url) { "git://example.com/foo.git" } it { is_expected.to eq(GitDownloadStrategy) } end context "when given SSH Git URL" do let(:url) { "ssh://git@example.com/foo.git" } it { is_expected.to eq(GitDownloadStrategy) } end context "when given a GitHub Git URL" do let(:url) { "https://github.com/homebrew/brew.git" } it { is_expected.to eq(GitHubGitDownloadStrategy) } end it "defaults to curl" do expect(strategy_detector).to eq(CurlDownloadStrategy) end it "raises an error when passed an unrecognized strategy" do expect do described_class.detect("foo", Class.new) end.to raise_error(TypeError) 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/bundle/tap_installer_spec.rb
Library/Homebrew/test/bundle/tap_installer_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/tap_installer" require "bundle/tap_dumper" RSpec.describe Homebrew::Bundle::TapInstaller do describe ".installed_taps" do before do Homebrew::Bundle::TapDumper.reset! end it "calls Homebrew" do expect { described_class.installed_taps }.not_to raise_error end end context "when tap is installed" do before do allow(described_class).to receive(:installed_taps).and_return(["homebrew/cask"]) end it "skips" do expect(Homebrew::Bundle).not_to receive(:system) expect(described_class.preinstall!("homebrew/cask")).to be(false) end end context "when tap is not installed" do before do allow(described_class).to receive(:installed_taps).and_return([]) end it "taps" do expect(Homebrew::Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "tap", "homebrew/cask", verbose: false).and_return(true) expect(described_class.preinstall!("homebrew/cask")).to be(true) expect(described_class.install!("homebrew/cask")).to be(true) end context "with clone target" do it "taps" do expect(Homebrew::Bundle).to \ receive(:system).with(HOMEBREW_BREW_FILE, "tap", "homebrew/cask", "clone_target_path", verbose: false).and_return(true) expect(described_class.preinstall!("homebrew/cask", clone_target: "clone_target_path")).to be(true) expect(described_class.install!("homebrew/cask", clone_target: "clone_target_path")).to be(true) end it "fails" do expect(Homebrew::Bundle).to \ receive(:system).with(HOMEBREW_BREW_FILE, "tap", "homebrew/cask", "clone_target_path", verbose: false).and_return(false) expect(described_class.preinstall!("homebrew/cask", clone_target: "clone_target_path")).to be(true) expect(described_class.install!("homebrew/cask", clone_target: "clone_target_path")).to be(false) 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/bundle/go_installer_spec.rb
Library/Homebrew/test/bundle/go_installer_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/go_installer" RSpec.describe Homebrew::Bundle::GoInstaller do context "when Go is not installed" do before do described_class.reset! allow(Homebrew::Bundle).to receive(:go_installed?).and_return(false) end it "tries to install go" do expect(Homebrew::Bundle).to \ receive(:system).with(HOMEBREW_BREW_FILE, "install", "--formula", "go", verbose: false) .and_return(true) expect { described_class.preinstall!("github.com/charmbracelet/crush") }.to raise_error(RuntimeError) end end context "when Go is installed" do before do allow(Homebrew::Bundle).to receive(:go_installed?).and_return(true) end context "when package is installed" do before do allow(described_class).to receive(:installed_packages) .and_return(["github.com/charmbracelet/crush"]) end it "skips" do expect(Homebrew::Bundle).not_to receive(:system) expect(described_class.preinstall!("github.com/charmbracelet/crush")).to be(false) end end context "when package is not installed" do before do allow(Homebrew::Bundle).to receive(:which_go).and_return(Pathname.new("go")) allow(described_class).to receive(:installed_packages).and_return([]) end it "installs package" do expect(Homebrew::Bundle).to \ receive(:system).with("go", "install", "github.com/charmbracelet/crush@latest", verbose: false) .and_return(true) expect(described_class.preinstall!("github.com/charmbracelet/crush")).to be(true) expect(described_class.install!("github.com/charmbracelet/crush")).to be(true) 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/bundle/bundle_spec.rb
Library/Homebrew/test/bundle/bundle_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/dsl" RSpec.describe Homebrew::Bundle do context "when the system call succeeds" do it "omits all stdout output if verbose is false" do expect { described_class.system "echo", "foo", verbose: false }.not_to output.to_stdout_from_any_process end it "emits all stdout output if verbose is true" do expect { described_class.system "echo", "foo", verbose: true }.to output("foo\n").to_stdout_from_any_process end end context "when the system call fails" do it "emits all stdout output even if verbose is false" do expect do described_class.system "/bin/bash", "-c", "echo foo && false", verbose: false end.to output("foo\n").to_stdout_from_any_process end it "emits all stdout output only once if verbose is true" do expect do described_class.system "/bin/bash", "-c", "echo foo && true", verbose: true end.to output("foo\n").to_stdout_from_any_process end end context "when checking for homebrew/cask", :needs_macos do it "finds it when present" do allow(File).to receive(:directory?).with("#{HOMEBREW_PREFIX}/Caskroom").and_return(true) allow(File).to receive(:directory?) .with("#{HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-cask") .and_return(true) expect(described_class.cask_installed?).to be(true) end end context "when checking for mas", :needs_macos do it "finds it when present" do stub_formula_loader formula("mas") { url "mas-1.0" } allow(described_class).to receive(:which).and_return(true) expect(described_class.mas_installed?).to be(true) end end describe ".mark_as_installed_on_request!", :no_api do subject(:mark_installed!) { described_class.mark_as_installed_on_request!(entries) } let(:entries) { dsl.entries } let(:dsl) { Homebrew::Bundle::Dsl.new(Pathname.new("/fake/Brewfile")) } let(:tabfile) { Pathname.new("/fake/INSTALL_RECEIPT.json") } before do allow(DevelopmentTools).to receive_messages(needs_libc_formula?: false, needs_compiler_formula?: false) allow_any_instance_of(Pathname).to receive(:read).and_return(brewfile_content) allow(tabfile).to receive_messages(blank?: false, exist?: true) end context "when formula is installed but not marked as installed_on_request" do let(:brewfile_content) { "brew 'myformula'" } let(:tab) { instance_double(Tab, installed_on_request: false, tabfile:) } before do allow(Formula).to receive(:installed_formula_names).and_return(["myformula"]) allow(Tab).to receive(:for_name).with("myformula").and_return(tab) end it "sets installed_on_request=true and writes" do expect(tab).to receive(:installed_on_request=).with(true) expect(tab).to receive(:write) mark_installed! end end context "when formula is not installed" do let(:brewfile_content) { "brew 'notinstalled'" } before do allow(Formula).to receive(:installed_formula_names).and_return([]) end it "skips the formula" do expect(Tab).not_to receive(:for_name) mark_installed! end end context "when formula is already marked as installed_on_request" do let(:brewfile_content) { "brew 'alreadymarked'" } let(:tab) { instance_double(Tab, installed_on_request: true, tabfile:) } before do allow(Formula).to receive(:installed_formula_names).and_return(["alreadymarked"]) allow(Tab).to receive(:for_name).with("alreadymarked").and_return(tab) end it "skips writing" do expect(tab).not_to receive(:installed_on_request=) expect(tab).not_to receive(:write) mark_installed! 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/bundle/flatpak_installer_spec.rb
Library/Homebrew/test/bundle/flatpak_installer_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/flatpak_installer" RSpec.describe Homebrew::Bundle::FlatpakInstaller do context "when Flatpak is not installed", :needs_linux do before do described_class.reset! allow(Homebrew::Bundle).to receive(:flatpak_installed?).and_return(false) end it "returns false without attempting installation" do expect(Homebrew::Bundle).not_to receive(:system) expect(described_class.preinstall!("org.gnome.Calculator")).to be(false) expect(described_class.install!("org.gnome.Calculator")).to be(true) end end context "when Flatpak is installed", :needs_linux do before do allow(Homebrew::Bundle).to receive(:flatpak_installed?).and_return(true) end context "when package is installed" do before do allow(described_class).to receive(:installed_packages) .and_return([{ name: "org.gnome.Calculator", remote: "flathub" }]) end it "skips" do expect(Homebrew::Bundle).not_to receive(:system) expect(described_class.preinstall!("org.gnome.Calculator")).to be(false) end end context "when package is not installed" do before do allow(Homebrew::Bundle).to receive(:which_flatpak).and_return(Pathname.new("flatpak")) allow(described_class).to receive(:installed_packages).and_return([]) end describe "Tier 1: no URL (flathub default)" do it "installs package from flathub" do expect(Homebrew::Bundle).to \ receive(:system).with("flatpak", "install", "-y", "--system", "flathub", "org.gnome.Calculator", verbose: false) .and_return(true) expect(described_class.preinstall!("org.gnome.Calculator")).to be(true) expect(described_class.install!("org.gnome.Calculator")).to be(true) end it "installs package from named remote" do expect(Homebrew::Bundle).to \ receive(:system).with("flatpak", "install", "-y", "--system", "fedora", "org.gnome.Calculator", verbose: false) .and_return(true) expect(described_class.preinstall!("org.gnome.Calculator", remote: "fedora")).to be(true) expect(described_class.install!("org.gnome.Calculator", remote: "fedora")).to be(true) end end describe "Tier 2: URL only (single-app remote)" do it "creates single-app remote with -origin suffix" do allow(described_class).to receive(:get_remote_url).and_return(nil) expect(Homebrew::Bundle).to \ receive(:system).with("flatpak", "remote-add", "--if-not-exists", "--system", "--no-gpg-verify", "org.godotengine.Godot-origin", "https://dl.flathub.org/beta-repo/", verbose: false) .and_return(true) expect(Homebrew::Bundle).to \ receive(:system).with("flatpak", "install", "-y", "--system", "org.godotengine.Godot-origin", "org.godotengine.Godot", verbose: false) .and_return(true) expect(described_class.preinstall!("org.godotengine.Godot", remote: "https://dl.flathub.org/beta-repo/")) .to be(true) expect(described_class.install!("org.godotengine.Godot", remote: "https://dl.flathub.org/beta-repo/")) .to be(true) end it "replaces single-app remote when URL changes" do allow(described_class).to receive(:get_remote_url) .with(anything, "org.godotengine.Godot-origin") .and_return("https://old.url/repo/") expect(Homebrew::Bundle).to \ receive(:system).with("flatpak", "remote-delete", "--system", "--force", "org.godotengine.Godot-origin", verbose: false) .and_return(true) expect(Homebrew::Bundle).to \ receive(:system).with("flatpak", "remote-add", "--if-not-exists", "--system", "--no-gpg-verify", "org.godotengine.Godot-origin", "https://dl.flathub.org/beta-repo/", verbose: false) .and_return(true) expect(Homebrew::Bundle).to \ receive(:system).with("flatpak", "install", "-y", "--system", "org.godotengine.Godot-origin", "org.godotengine.Godot", verbose: false) .and_return(true) expect(described_class.install!("org.godotengine.Godot", remote: "https://dl.flathub.org/beta-repo/")) .to be(true) end it "installs from .flatpakref directly" do allow(described_class).to receive(:`).with("flatpak list --app --columns=application,origin 2>/dev/null") .and_return("org.example.App\texample-origin\n") expect(Homebrew::Bundle).to \ receive(:system).with("flatpak", "install", "-y", "--system", "https://example.com/app.flatpakref", verbose: false) .and_return(true) expect(described_class.install!("org.example.App", remote: "https://example.com/app.flatpakref")) .to be(true) end end describe "Tier 3: URL + name (shared remote)" do it "creates named shared remote" do allow(described_class).to receive(:get_remote_url).and_return(nil) expect(Homebrew::Bundle).to \ receive(:system).with("flatpak", "remote-add", "--if-not-exists", "--system", "--no-gpg-verify", "flathub-beta", "https://dl.flathub.org/beta-repo/", verbose: false) .and_return(true) expect(Homebrew::Bundle).to \ receive(:system).with("flatpak", "install", "-y", "--system", "flathub-beta", "org.godotengine.Godot", verbose: false) .and_return(true) expect(described_class.install!("org.godotengine.Godot", remote: "flathub-beta", url: "https://dl.flathub.org/beta-repo/")) .to be(true) end it "warns but uses existing remote with different URL" do allow(described_class).to receive(:get_remote_url) .with(anything, "flathub-beta") .and_return("https://different.url/repo/") # Should NOT try to add remote (uses existing) expect(Homebrew::Bundle).not_to receive(:system) .with("flatpak", "remote-add", any_args) # Should NOT try to delete remote (user explicitly named it) expect(Homebrew::Bundle).not_to receive(:system) .with("flatpak", "remote-delete", any_args) expect(Homebrew::Bundle).to \ receive(:system).with("flatpak", "install", "-y", "--system", "flathub-beta", "org.godotengine.Godot", verbose: false) .and_return(true) expect(described_class.install!("org.godotengine.Godot", remote: "flathub-beta", url: "https://dl.flathub.org/beta-repo/")) .to be(true) end it "reuses existing shared remote when URL matches" do allow(described_class).to receive(:get_remote_url) .with(anything, "flathub-beta") .and_return("https://dl.flathub.org/beta-repo/") # Should NOT try to add remote (already exists with same URL) expect(Homebrew::Bundle).not_to receive(:system) .with("flatpak", "remote-add", any_args) expect(Homebrew::Bundle).to \ receive(:system).with("flatpak", "install", "-y", "--system", "flathub-beta", "org.godotengine.Godot", verbose: false) .and_return(true) expect(described_class.install!("org.godotengine.Godot", remote: "flathub-beta", url: "https://dl.flathub.org/beta-repo/")) .to be(true) end end end end describe ".generate_single_app_remote_name" do it "generates name with -origin suffix" do expect(described_class.generate_single_app_remote_name("org.godotengine.Godot")) .to eq("org.godotengine.Godot-origin") end it "handles various app ID formats" do expect(described_class.generate_single_app_remote_name("com.example.App")) .to eq("com.example.App-origin") 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/bundle/brew_services_spec.rb
Library/Homebrew/test/bundle/brew_services_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/brew_services" RSpec.describe Homebrew::Bundle::BrewServices do describe ".started_services" do before do described_class.reset! end it "returns started services" do allow(Utils).to receive(:safe_popen_read).and_return <<~EOS nginx started homebrew.mxcl.nginx.plist apache stopped homebrew.mxcl.apache.plist mysql started homebrew.mxcl.mysql.plist EOS expect(described_class.started_services).to contain_exactly("nginx", "mysql") end end context "when brew-services is installed" do context "when the service is stopped" do it "when the service is started" do allow(described_class).to receive(:started_services).and_return(%w[nginx]) expect(Homebrew::Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "services", "stop", "nginx", verbose: false).and_return(true) expect(described_class.stop("nginx")).to be(true) expect(described_class.started_services).not_to include("nginx") end it "when the service is already stopped" do allow(described_class).to receive(:started_services).and_return(%w[]) expect(Homebrew::Bundle).not_to receive(:system).with(HOMEBREW_BREW_FILE, "services", "stop", "nginx", verbose: false) expect(described_class.stop("nginx")).to be(true) expect(described_class.started_services).not_to include("nginx") end end it "starts the service" do allow(described_class).to receive(:started_services).and_return([]) expect(Homebrew::Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "services", "start", "nginx", verbose: false).and_return(true) expect(described_class.start("nginx")).to be(true) expect(described_class.started_services).to include("nginx") end it "runs the service" do allow(described_class).to receive(:started_services).and_return([]) expect(Homebrew::Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "services", "run", "nginx", verbose: false).and_return(true) expect(described_class.run("nginx")).to be(true) expect(described_class.started_services).to include("nginx") end it "restarts the service" do allow(described_class).to receive(:started_services).and_return([]) expect(Homebrew::Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "services", "restart", "nginx", verbose: false).and_return(true) expect(described_class.restart("nginx")).to be(true) expect(described_class.started_services).to include("nginx") end end describe ".versioned_service_file" do let(:foo) do instance_double( Formula, name: "fooformula", version: "1.0", rack: HOMEBREW_CELLAR/"fooformula", plist_name: "homebrew.mxcl.fooformula", service_name: "fooformula", ) end shared_examples "returns the versioned service file" do it "returns the versioned service file" do expect(Formula).to receive(:[]).with(foo.name).and_return(foo) expect(Homebrew::Bundle).to receive(:formula_versions_from_env).with(foo.name).and_return(foo.version) prefix = foo.rack/"1.0" allow(FileTest).to receive(:directory?).and_call_original expect(FileTest).to receive(:directory?).with(prefix.to_s).and_return(true) service_file = prefix/service_basename allow(FileTest).to receive(:file?).and_call_original expect(FileTest).to receive(:file?).with(service_file.to_s).and_return(true) expect(described_class.versioned_service_file(foo.name)).to eq(service_file) end end context "with launchctl" do before do allow(Homebrew::Services::System).to receive(:launchctl?).and_return(true) end let(:service_basename) { "#{foo.plist_name}.plist" } include_examples "returns the versioned service file" end context "with systemd" do before do allow(Homebrew::Services::System).to receive(:launchctl?).and_return(false) end let(:service_basename) { "#{foo.service_name}.service" } include_examples "returns the versioned service file" 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/bundle/cask_installer_spec.rb
Library/Homebrew/test/bundle/cask_installer_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/cask_dumper" require "bundle/cask_installer" RSpec.describe Homebrew::Bundle::CaskInstaller do describe ".installed_casks" do before do Homebrew::Bundle::CaskDumper.reset! end it "shells out" do expect { described_class.installed_casks }.not_to raise_error end end describe ".cask_installed_and_up_to_date?" do it "returns result" do described_class.reset! allow(described_class).to receive_messages(installed_casks: ["foo", "baz"], outdated_casks: ["baz"]) expect(described_class.cask_installed_and_up_to_date?("foo")).to be(true) expect(described_class.cask_installed_and_up_to_date?("baz")).to be(false) end end context "when brew-cask is not installed" do describe ".outdated_casks" do it "returns empty array" do described_class.reset! expect(described_class.outdated_casks).to eql([]) end end end context "when brew-cask is installed" do before do Homebrew::Bundle::CaskDumper.reset! allow(Homebrew::Bundle).to receive(:cask_installed?).and_return(true) end describe ".outdated_casks" do it "returns empty array" do described_class.reset! expect(described_class.outdated_casks).to eql([]) end end context "when cask is installed" do before do Homebrew::Bundle::CaskDumper.reset! allow(described_class).to receive(:installed_casks).and_return(["google-chrome"]) end it "skips" do expect(Homebrew::Bundle).not_to receive(:system) expect(described_class.preinstall!("google-chrome")).to be(false) end end context "when cask is outdated" do before do allow(described_class).to receive_messages(installed_casks: ["google-chrome"], outdated_casks: ["google-chrome"]) end it "upgrades" do expect(Homebrew::Bundle).to \ receive(:system).with(HOMEBREW_BREW_FILE, "upgrade", "--cask", "google-chrome", verbose: false) .and_return(true) expect(described_class.preinstall!("google-chrome")).to be(true) expect(described_class.install!("google-chrome")).to be(true) end end context "when cask is outdated and uses auto-update" do before do described_class.reset! allow(Homebrew::Bundle::CaskDumper).to receive_messages(cask_names: ["opera"], outdated_cask_names: []) allow(Homebrew::Bundle::CaskDumper).to receive(:cask_is_outdated_using_greedy?).with("opera").and_return(true) end it "upgrades" do expect(Homebrew::Bundle).to \ receive(:system).with(HOMEBREW_BREW_FILE, "upgrade", "--cask", "opera", verbose: false) .and_return(true) expect(described_class.preinstall!("opera", greedy: true)).to be(true) expect(described_class.install!("opera", greedy: true)).to be(true) end end context "when cask is not installed" do before do allow(described_class).to receive(:installed_casks).and_return([]) end it "installs cask" do expect(Homebrew::Bundle).to receive(:brew).with("install", "--cask", "google-chrome", "--adopt", verbose: false) .and_return(true) expect(described_class.preinstall!("google-chrome")).to be(true) expect(described_class.install!("google-chrome")).to be(true) end it "installs cask with arguments" do expect(Homebrew::Bundle).to( receive(:brew).with("install", "--cask", "firefox", "--appdir=/Applications", "--adopt", verbose: false) .and_return(true), ) expect(described_class.preinstall!("firefox", args: { appdir: "/Applications" })).to be(true) expect(described_class.install!("firefox", args: { appdir: "/Applications" })).to be(true) end it "reports a failure" do expect(Homebrew::Bundle).to receive(:brew).with("install", "--cask", "google-chrome", "--adopt", verbose: false) .and_return(false) expect(described_class.preinstall!("google-chrome")).to be(true) expect(described_class.install!("google-chrome")).to be(false) end context "with boolean arguments" do it "includes a flag if true" do expect(Homebrew::Bundle).to receive(:brew).with("install", "--cask", "iterm", "--force", verbose: false) .and_return(true) expect(described_class.preinstall!("iterm", args: { force: true })).to be(true) expect(described_class.install!("iterm", args: { force: true })).to be(true) end it "does not include a flag if false" do expect(Homebrew::Bundle).to receive(:brew).with("install", "--cask", "iterm", "--adopt", verbose: false) .and_return(true) expect(described_class.preinstall!("iterm", args: { force: false })).to be(true) expect(described_class.install!("iterm", args: { force: false })).to be(true) end end end context "when the postinstall option is provided" do before do Homebrew::Bundle::CaskDumper.reset! allow(Homebrew::Bundle::CaskDumper).to receive_messages(cask_names: ["google-chrome"], outdated_cask_names: ["google-chrome"]) allow(Homebrew::Bundle).to receive(:brew).and_return(true) allow(described_class).to receive(:upgrading?).and_return(true) end it "runs the postinstall command" do expect(Kernel).to receive(:system).with("custom command").and_return(true) expect(described_class.preinstall!("google-chrome", postinstall: "custom command")).to be(true) expect(described_class.install!("google-chrome", postinstall: "custom command")).to be(true) end it "reports a failure when postinstall fails" do expect(Kernel).to receive(:system).with("custom command").and_return(false) expect(described_class.preinstall!("google-chrome", postinstall: "custom command")).to be(true) expect(described_class.install!("google-chrome", postinstall: "custom command")).to be(false) 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/bundle/cask_dumper_spec.rb
Library/Homebrew/test/bundle/cask_dumper_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/cask_dumper" require "cask" RSpec.describe Homebrew::Bundle::CaskDumper do subject(:dumper) { described_class } context "when brew-cask is not installed" do before do described_class.reset! allow(Homebrew::Bundle).to receive(:cask_installed?).and_return(false) end it "returns empty list" do expect(dumper.cask_names).to be_empty end it "dumps as empty string" do # rubocop:todo RSpec/AggregateExamples expect(dumper.dump).to eql("") end end context "when there is no cask" do before do described_class.reset! allow(Homebrew::Bundle).to receive(:cask_installed?).and_return(true) allow(described_class).to receive(:`).and_return("") end it "returns empty list" do expect(dumper.cask_names).to be_empty end it "dumps as empty string" do # rubocop:todo RSpec/AggregateExamples expect(dumper.dump).to eql("") end it "doesn’t want to greedily update a non-installed cask" do expect(dumper.cask_is_outdated_using_greedy?("foo")).to be(false) end end context "when casks `foo`, `bar` and `baz` are installed, with `baz` being a formula requirement" do let(:foo) { instance_double(Cask::Cask, to_s: "foo", desc: nil, config: nil) } let(:baz) { instance_double(Cask::Cask, to_s: "baz", desc: "Software", config: nil) } let(:bar) do instance_double( Cask::Cask, to_s: "bar", desc: nil, config: instance_double( Cask::Config, explicit: { fontdir: "/Library/Fonts", languages: ["zh-TW"], }, ) ) end before do described_class.reset! allow(Homebrew::Bundle).to receive(:cask_installed?).and_return(true) allow(Cask::Caskroom).to receive(:casks).and_return([foo, bar, baz]) end it "returns list %w[foo bar baz]" do expect(dumper.cask_names).to eql(%w[foo bar baz]) end it "dumps as `cask 'baz'` and `cask 'foo' cask 'bar'` plus descriptions and config values" do expected = <<~EOS cask "foo" cask "bar", args: { fontdir: "/Library/Fonts", language: "zh-TW" } # Software cask "baz" EOS expect(dumper.dump(describe: true)).to eql(expected.chomp) end it "doesn’t want to greedily update a non-installed cask" do expect(dumper.cask_is_outdated_using_greedy?("qux")).to be(false) end it "wants to greedily update foo if there is an update available" do expect(foo).to receive(:outdated?).with(greedy: true).and_return(true) expect(dumper.cask_is_outdated_using_greedy?("foo")).to be(true) end it "does not want to greedily update bar if there is no update available" do expect(bar).to receive(:outdated?).with(greedy: true).and_return(false) expect(dumper.cask_is_outdated_using_greedy?("bar")).to be(false) end end describe "#cask_oldnames" do before do described_class.reset! end it "returns an empty string when no casks are installed" do expect(dumper.cask_oldnames).to eql({}) end it "returns a hash with installed casks old names" do foo = instance_double(Cask::Cask, to_s: "foo", old_tokens: ["oldfoo"], full_name: "qux/quuz/foo") bar = instance_double(Cask::Cask, to_s: "bar", old_tokens: [], full_name: "bar") allow(Cask::Caskroom).to receive(:casks).and_return([foo, bar]) allow(Homebrew::Bundle).to receive(:cask_installed?).and_return(true) expect(dumper.cask_oldnames).to eql({ "qux/quuz/oldfoo" => "qux/quuz/foo", "oldfoo" => "qux/quuz/foo", }) end end describe "#formula_dependencies" do context "when the given casks don't have formula dependencies" do before do described_class.reset! end it "returns an empty array" do expect(dumper.formula_dependencies(["foo"])).to eql([]) end end context "when multiple casks have the same dependency" do before do described_class.reset! foo = instance_double(Cask::Cask, to_s: "foo", depends_on: { formula: ["baz", "qux"] }) bar = instance_double(Cask::Cask, to_s: "bar", depends_on: {}) allow(Cask::Caskroom).to receive(:casks).and_return([foo, bar]) allow(Homebrew::Bundle).to receive(:cask_installed?).and_return(true) end it "returns an array of unique formula dependencies" do expect(dumper.formula_dependencies(["foo", "bar"])).to eql(["baz", "qux"]) 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/bundle/brewfile_spec.rb
Library/Homebrew/test/bundle/brewfile_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/brewfile" RSpec.describe Homebrew::Bundle::Brewfile do describe "path" do subject(:path) do described_class.path(dash_writes_to_stdout:, global: has_global, file: file_value) end let(:dash_writes_to_stdout) { false } let(:env_bundle_file_global_value) { nil } let(:env_bundle_file_value) { nil } let(:env_user_config_home_value) { "/Users/username/.homebrew" } let(:env_home_value) { "/Users/username" } let(:file_value) { nil } let(:has_global) { false } let(:config_dir_exist) { false } let(:config_dir_brewfile_exist) { false } let(:home_dir_brewfile_exist) { false } before do allow(ENV).to receive(:fetch).and_return(nil) allow(ENV).to receive(:fetch).with("HOMEBREW_BUNDLE_FILE_GLOBAL", any_args) .and_return(env_bundle_file_global_value) allow(ENV).to receive(:fetch).with("HOMEBREW_BUNDLE_FILE", any_args) .and_return(env_bundle_file_value) allow(ENV).to receive(:fetch).with("HOMEBREW_USER_CONFIG_HOME", any_args) .and_return(env_user_config_home_value) allow(File).to receive(:exist?).with("/Users/username/.homebrew/Brewfile") .and_return(config_dir_brewfile_exist) allow(File).to receive(:exist?).with("/Users/username/.Brewfile") .and_return(home_dir_brewfile_exist) allow(Dir).to receive(:home).and_return(env_home_value) allow(Dir).to receive(:exist?).with("/Users/username/.homebrew") .and_return(config_dir_exist) end context "when `file` is specified with a relative path" do let(:file_value) { "path/to/Brewfile" } let(:expected_pathname) { Pathname.new(file_value).expand_path(Dir.pwd) } it "returns the expected path" do expect(path).to eq(expected_pathname) end context "with a configured HOMEBREW_BUNDLE_FILE" do let(:env_bundle_file_value) { "/path/to/Brewfile" } it "returns the value specified by `file` path" do expect(path).to eq(expected_pathname) end end context "with an empty HOMEBREW_BUNDLE_FILE" do let(:env_bundle_file_value) { "" } it "returns the value specified by `file` path" do expect(path).to eq(expected_pathname) end end end context "when `file` is specified with an absolute path" do let(:file_value) { "/tmp/random_file" } let(:expected_pathname) { Pathname.new(file_value) } it "returns the expected path" do expect(path).to eq(expected_pathname) end context "with a configured HOMEBREW_BUNDLE_FILE" do let(:env_bundle_file_value) { "/path/to/Brewfile" } it "returns the value specified by `file` path" do expect(path).to eq(expected_pathname) end end context "with an empty HOMEBREW_BUNDLE_FILE" do let(:env_bundle_file_value) { "" } it "returns the value specified by `file` path" do expect(path).to eq(expected_pathname) end end end context "when `file` is specified with `-`" do let(:file_value) { "-" } let(:expected_pathname) { Pathname.new("/dev/stdin") } it "returns stdin by default" do expect(path).to eq(expected_pathname) end context "with a configured HOMEBREW_BUNDLE_FILE" do let(:env_bundle_file_value) { "/path/to/Brewfile" } it "returns the value specified by `file` path" do expect(path).to eq(expected_pathname) end end context "with an empty HOMEBREW_BUNDLE_FILE" do let(:env_bundle_file_value) { "" } it "returns the value specified by `file` path" do expect(path).to eq(expected_pathname) end end context "when `dash_writes_to_stdout` is true" do let(:expected_pathname) { Pathname.new("/dev/stdout") } let(:dash_writes_to_stdout) { true } it "returns stdout" do expect(path).to eq(expected_pathname) end context "with a configured HOMEBREW_BUNDLE_FILE" do let(:env_bundle_file_value) { "/path/to/Brewfile" } it "returns the value specified by `file` path" do expect(path).to eq(expected_pathname) end end context "with an empty HOMEBREW_BUNDLE_FILE" do let(:env_bundle_file_value) { "" } it "returns the value specified by `file` path" do expect(path).to eq(expected_pathname) end end end end context "when `global` is true" do let(:has_global) { true } let(:expected_pathname) { Pathname.new("#{Dir.home}/.Brewfile") } it "returns the expected path" do expect(path).to eq(expected_pathname) end context "when HOMEBREW_BUNDLE_FILE_GLOBAL is set" do let(:env_bundle_file_global_value) { "/path/to/Brewfile" } let(:expected_pathname) { Pathname.new(env_bundle_file_global_value) } it "returns the value specified by the environment variable" do expect(path).to eq(expected_pathname) end end context "when HOMEBREW_BUNDLE_FILE is set" do let(:env_bundle_file_value) { "/path/to/Brewfile" } it "returns the value specified by the variable" do expect { path }.to raise_error(RuntimeError) end end context "when HOMEBREW_BUNDLE_FILE is `` (empty)" do let(:env_bundle_file_value) { "" } it "returns the value specified by `file` path" do expect(path).to eq(expected_pathname) end end context "when HOMEBREW_USER_CONFIG_HOME/Brewfile exists" do let(:config_dir_brewfile_exist) { true } let(:config_dir_exist) { true } let(:home_dir_brewfile_exist) { true } let(:expected_pathname) { Pathname.new("#{env_user_config_home_value}/Brewfile") } it "returns the expected path" do expect(path).to eq(expected_pathname) end end context "when empty HOMEBREW_USER_CONFIG_HOME exists, and .Brewfile does not" do let(:config_dir_exist) { true } let(:expected_pathname) { Pathname.new("#{env_user_config_home_value}/Brewfile") } it "returns the expected path" do expect(path).to eq(expected_pathname) end end context "when empty HOMEBREW_USER_CONFIG_HOME and .Brewfile exist" do let(:config_dir_exist) { true } let(:home_dir_brewfile_exist) { true } let(:expected_pathname) { Pathname.new("#{env_home_value}/.Brewfile") } it "returns the expected path" do expect(path).to eq(expected_pathname) end end end context "when HOMEBREW_BUNDLE_FILE has a value" do let(:env_bundle_file_value) { "/path/to/Brewfile" } it "returns the expected path" do expect(path).to eq(Pathname.new(env_bundle_file_value)) end describe "that is `` (empty)" do let(:env_bundle_file_value) { "" } it "defaults to `${PWD}/Brewfile`" do expect(path).to eq(Pathname.new("Brewfile").expand_path(Dir.pwd)) end end describe "that is `nil`" do let(:env_bundle_file_value) { nil } it "defaults to `${PWD}/Brewfile`" do expect(path).to eq(Pathname.new("Brewfile").expand_path(Dir.pwd)) 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/bundle/dsl_spec.rb
Library/Homebrew/test/bundle/dsl_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/dsl" RSpec.describe Homebrew::Bundle::Dsl do def dsl_from_string(string) described_class.new(StringIO.new(string)) end context "with a DSL example" do subject(:dsl) do dsl_from_string <<~EOS # frozen_string_literal: true cask_args appdir: '/Applications' tap 'homebrew/cask' tap 'telemachus/brew', 'https://telemachus@bitbucket.org/telemachus/brew.git' tap 'auto/update', 'https://bitbucket.org/auto/update.git' brew 'imagemagick' brew 'mysql@5.6', restart_service: true, link: true, conflicts_with: ['mysql'] brew 'emacs', args: ['with-cocoa', 'with-gnutls'], link: :overwrite cask 'google-chrome' cask 'java' unless system '/usr/libexec/java_home --failfast' cask 'firefox', args: { appdir: '~/my-apps/Applications' } mas '1Password', id: 443987910 vscode 'GitHub.codespaces' go 'github.com/charmbracelet/crush' cargo 'ripgrep' EOS end before do allow_any_instance_of(described_class).to receive(:system) .with("/usr/libexec/java_home --failfast") .and_return(false) end it "processes input" do # Keep in sync with the README expect(dsl.cask_arguments).to eql(appdir: "/Applications") expect(dsl.entries[0].name).to eql("homebrew/cask") expect(dsl.entries[1].name).to eql("telemachus/brew") expect(dsl.entries[1].options).to eql(clone_target: "https://telemachus@bitbucket.org/telemachus/brew.git") expect(dsl.entries[2].options).to eql(clone_target: "https://bitbucket.org/auto/update.git") expect(dsl.entries[3].name).to eql("imagemagick") expect(dsl.entries[4].name).to eql("mysql@5.6") expect(dsl.entries[4].options).to eql(restart_service: true, link: true, conflicts_with: ["mysql"]) expect(dsl.entries[5].name).to eql("emacs") expect(dsl.entries[5].options).to eql(args: ["with-cocoa", "with-gnutls"], link: :overwrite) expect(dsl.entries[6].name).to eql("google-chrome") expect(dsl.entries[7].name).to eql("java") expect(dsl.entries[8].name).to eql("firefox") expect(dsl.entries[8].options).to eql(args: { appdir: "~/my-apps/Applications" }, full_name: "firefox") expect(dsl.entries[9].name).to eql("1Password") expect(dsl.entries[9].options).to eql(id: 443_987_910) expect(dsl.entries[10].name).to eql("GitHub.codespaces") expect(dsl.entries[11].name).to eql("github.com/charmbracelet/crush") expect(dsl.entries[12].name).to eql("ripgrep") end end context "with multiple cask_args" do subject(:dsl) do dsl_from_string <<~EOS cask_args appdir: '/global-apps' cask_args require_sha: true cask_args appdir: '~/my-apps' EOS end it "merges the arguments" do expect(dsl.cask_arguments).to eql(appdir: "~/my-apps", require_sha: true) end end context "with flatpak entries" do it "processes flatpak without options" do dsl = dsl_from_string 'flatpak "org.gnome.Calculator"' expect(dsl.entries[0].name).to eql("org.gnome.Calculator") expect(dsl.entries[0].options[:remote]).to eql("flathub") end it "processes flatpak with remote option" do dsl = dsl_from_string 'flatpak "com.custom.App", remote: "custom-repo"' expect(dsl.entries[0].name).to eql("com.custom.App") expect(dsl.entries[0].options[:remote]).to eql("custom-repo") end it "processes flatpak with explicit flathub remote" do dsl = dsl_from_string 'flatpak "org.gnome.Calculator", remote: "flathub"' expect(dsl.entries[0].name).to eql("org.gnome.Calculator") expect(dsl.entries[0].options[:remote]).to eql("flathub") end it "processes flatpak with URL remote" do dsl = dsl_from_string 'flatpak "org.godotengine.Godot", remote: "https://dl.flathub.org/beta-repo/"' expect(dsl.entries[0].name).to eql("org.godotengine.Godot") expect(dsl.entries[0].options[:remote]).to eql("https://dl.flathub.org/beta-repo/") end end context "with invalid input" do it "handles completely invalid code" do expect { dsl_from_string "abcdef" }.to raise_error(RuntimeError) end it "handles valid commands but with invalid options" do expect { dsl_from_string "brew 1" }.to raise_error(RuntimeError) expect { dsl_from_string "cask 1" }.to raise_error(RuntimeError) expect { dsl_from_string "tap 1" }.to raise_error(RuntimeError) expect { dsl_from_string "cask_args ''" }.to raise_error(RuntimeError) end it "errors on bad options" do expect { dsl_from_string "brew 'foo', ['bad_option']" }.to raise_error(RuntimeError) expect { dsl_from_string "cask 'foo', ['bad_option']" }.to raise_error(RuntimeError) expect { dsl_from_string "tap 'foo', ['bad_clone_target']" }.to raise_error(RuntimeError) expect { dsl_from_string "flatpak 'foo', ['bad_option']" }.to raise_error(RuntimeError) end end it ".sanitize_brew_name" do expect(described_class.send(:sanitize_brew_name, "homebrew/homebrew/foo")).to eql("foo") expect(described_class.send(:sanitize_brew_name, "homebrew/homebrew-bar/foo")).to eql("homebrew/bar/foo") expect(described_class.send(:sanitize_brew_name, "homebrew/bar/foo")).to eql("homebrew/bar/foo") expect(described_class.send(:sanitize_brew_name, "foo")).to eql("foo") end it ".sanitize_tap_name" do expect(described_class.send(:sanitize_tap_name, "homebrew/homebrew-foo")).to eql("homebrew/foo") expect(described_class.send(:sanitize_tap_name, "homebrew/foo")).to eql("homebrew/foo") end it ".sanitize_cask_name" do expect(described_class.send(:sanitize_cask_name, "homebrew/cask-versions/adoptopenjdk8")).to eql("adoptopenjdk8") expect(described_class.send(:sanitize_cask_name, "adoptopenjdk8")).to eql("adoptopenjdk8") 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/bundle/mac_app_store_installer_spec.rb
Library/Homebrew/test/bundle/mac_app_store_installer_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/mac_app_store_installer" RSpec.describe Homebrew::Bundle::MacAppStoreInstaller do before do stub_formula_loader formula("mas") { url "mas-1.0" } end describe ".installed_app_ids" do it "shells out" do expect { described_class.installed_app_ids }.not_to raise_error end end describe ".app_id_installed_and_up_to_date?" do it "returns result" do allow(described_class).to receive_messages(installed_app_ids: [123, 456], outdated_app_ids: [456]) expect(described_class.app_id_installed_and_up_to_date?(123)).to be(true) expect(described_class.app_id_installed_and_up_to_date?(456)).to be(false) end end context "when mas is not installed" do before do allow(Homebrew::Bundle).to receive(:mas_installed?).and_return(false) end it "tries to install mas" do expect(Homebrew::Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "install", "mas", verbose: false).and_return(true) expect { described_class.preinstall!("foo", 123) }.to raise_error(RuntimeError) end describe ".outdated_app_ids" do it "does not shell out" do expect(described_class).not_to receive(:`) described_class.reset! described_class.outdated_app_ids end end end context "when mas is installed" do before do allow(Homebrew::Bundle).to receive(:mas_installed?).and_return(true) end describe ".outdated_app_ids" do it "returns app ids" do expect(described_class).to receive(:`).and_return("foo 123") described_class.reset! described_class.outdated_app_ids end end context "when app is installed" do before do allow(described_class).to receive(:installed_app_ids).and_return([123]) end it "skips" do expect(Homebrew::Bundle).not_to receive(:system) expect(described_class.preinstall!("foo", 123)).to be(false) end end context "when app is outdated" do before do allow(described_class).to receive_messages(installed_app_ids: [123], outdated_app_ids: [123]) end it "upgrades" do expect(Homebrew::Bundle).to receive(:system).with("mas", "upgrade", "123", verbose: false).and_return(true) expect(described_class.preinstall!("foo", 123)).to be(true) expect(described_class.install!("foo", 123)).to be(true) end end context "when app is not installed" do before do allow(described_class).to receive(:installed_app_ids).and_return([]) end it "installs app" do expect(Homebrew::Bundle).to receive(:system).with("mas", "install", "123", verbose: false).and_return(true) expect(described_class.preinstall!("foo", 123)).to be(true) expect(described_class.install!("foo", 123)).to be(true) 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/bundle/tap_dumper_spec.rb
Library/Homebrew/test/bundle/tap_dumper_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/skipper" require "bundle/tap_dumper" RSpec.describe Homebrew::Bundle::TapDumper do subject(:dumper) { described_class } context "when there is no tap" do before do described_class.reset! allow(Tap).to receive(:select).and_return [] end it "returns empty list" do expect(dumper.tap_names).to be_empty end it "dumps as empty string" do # rubocop:todo RSpec/AggregateExamples expect(dumper.dump).to eql("") end end context "with taps" do before do described_class.reset! bar = instance_double(Tap, name: "bitbucket/bar", custom_remote?: true, remote: "https://bitbucket.org/bitbucket/bar.git") baz = instance_double(Tap, name: "homebrew/baz", custom_remote?: false) foo = instance_double(Tap, name: "homebrew/foo", custom_remote?: false) ENV["HOMEBREW_GITHUB_API_TOKEN_BEFORE"] = ENV.fetch("HOMEBREW_GITHUB_API_TOKEN", nil) ENV["HOMEBREW_GITHUB_API_TOKEN"] = "some-token" private_tap = instance_double(Tap, name: "privatebrew/private", custom_remote?: true, remote: "https://#{ENV.fetch("HOMEBREW_GITHUB_API_TOKEN")}@github.com/privatebrew/homebrew-private") allow(Tap).to receive(:select).and_return [bar, baz, foo, private_tap] end after do ENV["HOMEBREW_GITHUB_API_TOKEN"] = ENV.fetch("HOMEBREW_GITHUB_API_TOKEN_BEFORE", nil) ENV.delete("HOMEBREW_GITHUB_API_TOKEN_BEFORE") end it "returns list of information" do expect(dumper.tap_names).not_to be_empty end it "dumps output" do expected_output = <<~EOS tap "bitbucket/bar", "https://bitbucket.org/bitbucket/bar.git" tap "homebrew/baz" tap "homebrew/foo" tap "privatebrew/private", "https://\#{ENV.fetch("HOMEBREW_GITHUB_API_TOKEN")}@github.com/privatebrew/homebrew-private" EOS expect(dumper.dump).to eql(expected_output.chomp) 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/bundle/cargo_dumper_spec.rb
Library/Homebrew/test/bundle/cargo_dumper_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/cargo_dumper" RSpec.describe Homebrew::Bundle::CargoDumper do subject(:dumper) { described_class } context "when cargo is not installed" do before do described_class.reset! allow(Homebrew::Bundle).to receive(:cargo_installed?).and_return(false) end it "returns an empty list" do expect(dumper.packages).to be_empty end it "dumps an empty string" do # rubocop:todo RSpec/AggregateExamples expect(dumper.dump).to eql("") end end context "when cargo is installed" do before do described_class.reset! allow(Homebrew::Bundle).to receive_messages(cargo_installed?: true, which_cargo: Pathname.new("cargo")) end it "returns package list" do allow(described_class).to receive(:`).with("cargo install --list").and_return(<<~EOS) ripgrep v13.0.0: rg bat v0.24.0 (/Users/test/.cargo/bin/bat) EOS expect(dumper.packages).to eql(%w[ripgrep bat]) end it "dumps package list" do allow(dumper).to receive(:packages).and_return(["ripgrep", "bat"]) expect(dumper.dump).to eql("cargo \"ripgrep\"\ncargo \"bat\"") 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/bundle/go_dumper_spec.rb
Library/Homebrew/test/bundle/go_dumper_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/go_dumper" RSpec.describe Homebrew::Bundle::GoDumper do subject(:dumper) { described_class } context "when go is not installed" do before do described_class.reset! allow(Homebrew::Bundle).to receive(:go_installed?).and_return(false) end it "returns an empty list" do expect(dumper.packages).to be_empty end it "dumps an empty string" do # rubocop:todo RSpec/AggregateExamples expect(dumper.dump).to eql("") end end context "when go is installed" do before do described_class.reset! allow(Homebrew::Bundle).to receive(:which_go).and_return(Pathname.new("go")) end it "returns package list" do allow(described_class).to receive(:`).with("go env GOBIN").and_return("") allow(described_class).to receive(:`).with("go env GOPATH").and_return("/Users/test/go") allow(File).to receive(:directory?).with("/Users/test/go/bin").and_return(true) allow(Dir).to receive(:glob).with("/Users/test/go/bin/*").and_return(["/Users/test/go/bin/crush"]) allow(File).to receive(:executable?).with("/Users/test/go/bin/crush").and_return(true) allow(File).to receive(:directory?).with("/Users/test/go/bin/crush").and_return(false) allow(described_class).to receive(:`).with("go version -m \"/Users/test/go/bin/crush\" 2>/dev/null") .and_return("\tpath\tgithub.com/charmbracelet/crush\n") expect(dumper.packages).to eql(["github.com/charmbracelet/crush"]) end it "dumps package list" do allow(dumper).to receive(:packages).and_return(["github.com/charmbracelet/crush"]) expect(dumper.dump).to eql('go "github.com/charmbracelet/crush"') 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/bundle/dumper_spec.rb
Library/Homebrew/test/bundle/dumper_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/dumper" require "bundle/formula_dumper" require "bundle/tap_dumper" require "bundle/cask_dumper" require "bundle/mac_app_store_dumper" require "bundle/vscode_extension_dumper" require "bundle/brew_services" require "bundle/go_dumper" require "bundle/cargo_dumper" require "cask" RSpec.describe Homebrew::Bundle::Dumper do subject(:dumper) { described_class } before do ENV["HOMEBREW_BUNDLE_FILE"] = "" allow(Homebrew::Bundle).to \ receive_messages(cask_installed?: true, mas_installed?: false, vscode_installed?: false) allow(Homebrew::Bundle).to receive_messages(go_installed?: false, cargo_installed?: false) Homebrew::Bundle::FormulaDumper.reset! Homebrew::Bundle::TapDumper.reset! Homebrew::Bundle::CaskDumper.reset! Homebrew::Bundle::MacAppStoreDumper.reset! Homebrew::Bundle::VscodeExtensionDumper.reset! Homebrew::Bundle::GoDumper.reset! Homebrew::Bundle::CargoDumper.reset! Homebrew::Bundle::BrewServices.reset! chrome = instance_double(Cask::Cask, full_name: "google-chrome", to_s: "google-chrome", config: nil) java = instance_double(Cask::Cask, full_name: "java", to_s: "java", config: nil) iterm2beta = instance_double(Cask::Cask, full_name: "homebrew/cask-versions/iterm2-beta", to_s: "iterm2-beta", config: nil) allow(Cask::Caskroom).to receive(:casks).and_return([chrome, java, iterm2beta]) allow(Homebrew::Bundle::GoDumper).to receive(:`).and_return("") allow(Homebrew::Bundle::CargoDumper).to receive(:`).and_return("") allow(Tap).to receive(:select).and_return([]) end it "generates output" do expect(dumper.build_brewfile( describe: false, no_restart: false, formulae: true, taps: true, casks: true, mas: true, vscode: true, go: true, cargo: true, flatpak: false )).to eql("cask \"google-chrome\"\ncask \"java\"\ncask \"iterm2-beta\"\n") end it "determines the brewfile correctly" do expect(dumper.brewfile_path).to eql(Pathname.new(Dir.pwd).join("Brewfile")) 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/bundle/mac_app_store_dumper_spec.rb
Library/Homebrew/test/bundle/mac_app_store_dumper_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/mac_app_store_dumper" RSpec.describe Homebrew::Bundle::MacAppStoreDumper do subject(:dumper) { described_class } context "when mas is not installed" do before do described_class.reset! allow(Homebrew::Bundle).to receive(:mas_installed?).and_return(false) end it "returns empty list" do expect(dumper.apps).to be_empty end it "dumps as empty string" do # rubocop:todo RSpec/AggregateExamples expect(dumper.dump).to eql("") end end context "when there is no apps" do before do described_class.reset! allow(Homebrew::Bundle).to receive(:mas_installed?).and_return(true) allow(described_class).to receive(:`).and_return("") end it "returns empty list" do expect(dumper.apps).to be_empty end it "dumps as empty string" do # rubocop:todo RSpec/AggregateExamples expect(dumper.dump).to eql("") end end context "when apps `foo`, `bar` and `baz` are installed" do before do described_class.reset! allow(Homebrew::Bundle).to receive(:mas_installed?).and_return(true) allow(described_class).to receive(:`).and_return("123 foo (1.0)\n456 bar (2.0)\n789 baz (3.0)") end it "returns list %w[foo bar baz]" do expect(dumper.apps).to eql([["123", "foo"], ["456", "bar"], ["789", "baz"]]) end end context "when apps `foo`, `bar`, `baz` and `qux` are installed including right-justified IDs" do before do described_class.reset! allow(Homebrew::Bundle).to receive(:mas_installed?).and_return(true) allow(described_class).to receive(:`).and_return("123 foo (1.0)\n456 bar (2.0)\n789 baz (3.0)") allow(described_class).to receive(:`).and_return("123 foo (1.0)\n456 bar (2.0)\n789 baz (3.0)\n 10 qux (4.0)") end it "returns list %w[foo bar baz qux]" do expect(dumper.apps).to eql([["123", "foo"], ["456", "bar"], ["789", "baz"], ["10", "qux"]]) end end context "with invalid app details" do let(:invalid_mas_output) do <<~HEREDOC 497799835 Xcode (9.2) 425424353 The Unarchiver (4.0.0) 08981434 iMovie (10.1.8) 409201541 Pages (7.1) 123456789 123AppNameWithNumbers (1.0) 409203825 Numbers (5.1) 944924917 Pastebin It! (1.0) 123456789 My (cool) app (1.0) 987654321 an-app-i-use (2.1) 123457867 App name with many spaces (1.0) 893489734 my,comma,app (2.2) 832423434 another_app_name (1.0) 543213432 My App? (1.0) 688963445 app;with;semicolons (1.0) 123345384 my 😊 app (2.0) 896732467 你好 (1.1) 634324555 مرحبا (1.0) 234324325 áéíóú (1.0) 310633997 non>‎<printing>⁣<characters (1.0) HEREDOC end let(:expected_app_details_array) do [ ["497799835", "Xcode"], ["425424353", "The Unarchiver"], ["08981434", "iMovie"], ["409201541", "Pages"], ["123456789", "123AppNameWithNumbers"], ["409203825", "Numbers"], ["944924917", "Pastebin It!"], ["123456789", "My (cool) app"], ["987654321", "an-app-i-use"], ["123457867", "App name with many spaces"], ["893489734", "my,comma,app"], ["832423434", "another_app_name"], ["543213432", "My App?"], ["688963445", "app;with;semicolons"], ["123345384", "my 😊 app"], ["896732467", "你好"], ["634324555", "مرحبا"], ["234324325", "áéíóú"], ["310633997", "non><printing><characters"], ] end let(:expected_mas_dumped_output) do <<~HEREDOC mas "123AppNameWithNumbers", id: 123456789 mas "an-app-i-use", id: 987654321 mas "another_app_name", id: 832423434 mas "App name with many spaces", id: 123457867 mas "app;with;semicolons", id: 688963445 mas "iMovie", id: 08981434 mas "My (cool) app", id: 123456789 mas "My App?", id: 543213432 mas "my 😊 app", id: 123345384 mas "my,comma,app", id: 893489734 mas "non><printing><characters", id: 310633997 mas "Numbers", id: 409203825 mas "Pages", id: 409201541 mas "Pastebin It!", id: 944924917 mas "The Unarchiver", id: 425424353 mas "Xcode", id: 497799835 mas "áéíóú", id: 234324325 mas "مرحبا", id: 634324555 mas "你好", id: 896732467 HEREDOC end before do described_class.reset! allow(Homebrew::Bundle).to receive(:mas_installed?).and_return(true) allow(described_class).to receive(:`).and_return(invalid_mas_output) end it "returns only valid apps" do expect(dumper.apps).to eql(expected_app_details_array) end it "dumps excluding invalid apps" do # rubocop:todo RSpec/AggregateExamples expect(dumper.dump).to eq(expected_mas_dumped_output.strip) end end context "with the new format after mas-cli/mas#339" do let(:new_mas_output) do <<~HEREDOC 1440147259 AdGuard for Safari (1.9.13) 497799835 Xcode (12.5) 425424353 The Unarchiver (4.3.1) HEREDOC end let(:expected_app_details_array) do [ ["1440147259", "AdGuard for Safari"], ["497799835", "Xcode"], ["425424353", "The Unarchiver"], ] end before do described_class.reset! allow(Homebrew::Bundle).to receive(:mas_installed?).and_return(true) allow(described_class).to receive(:`).and_return(new_mas_output) end it "parses the app names without trailing whitespace" do expect(dumper.apps).to eql(expected_app_details_array) 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/bundle/vscode_extension_dumper_spec.rb
Library/Homebrew/test/bundle/vscode_extension_dumper_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/vscode_extension_dumper" RSpec.describe Homebrew::Bundle::VscodeExtensionDumper do subject(:dumper) { described_class } context "when vscode is not installed" do before do described_class.reset! allow(Homebrew::Bundle).to receive(:vscode_installed?).and_return(false) allow(described_class).to receive(:`).and_return("") end it "returns an empty list" do expect(dumper.extensions).to be_empty end it "dumps an empty string" do # rubocop:todo RSpec/AggregateExamples expect(dumper.dump).to eql("") end end context "when vscode is installed" do before do described_class.reset! allow(Homebrew::Bundle).to receive(:which_vscode).and_return(Pathname.new("code")) end it "returns package list" do output = <<~EOF catppuccin.catppuccin-vsc davidanson.vscode-markdownlint streetsidesoftware.code-spell-checker tamasfe.even-better-toml EOF allow(described_class).to receive(:`) .with('"code" --list-extensions 2>/dev/null') .and_return(output) expect(dumper.extensions).to eql([ "catppuccin.catppuccin-vsc", "davidanson.vscode-markdownlint", "streetsidesoftware.code-spell-checker", "tamasfe.even-better-toml", ]) 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/bundle/skipper_spec.rb
Library/Homebrew/test/bundle/skipper_spec.rb
# frozen_string_literal: true require "ostruct" require "bundle" require "bundle/skipper" require "bundle/dsl" RSpec.describe Homebrew::Bundle::Skipper do subject(:skipper) { described_class } before do allow(ENV).to receive(:[]).and_return(nil) allow(ENV).to receive(:[]).with("HOMEBREW_BUNDLE_BREW_SKIP").and_return("mysql") allow(ENV).to receive(:[]).with("HOMEBREW_BUNDLE_TAP_SKIP").and_return("org/repo") allow(Formatter).to receive(:warning) skipper.instance_variable_set(:@skipped_entries, nil) skipper.instance_variable_set(:@failed_taps, nil) end describe ".skip?" do context "with a listed formula" do let(:entry) { Homebrew::Bundle::Dsl::Entry.new(:brew, "mysql") } it "returns true" do expect(skipper.skip?(entry)).to be true end end context "with an unbottled formula on ARM" do let(:entry) { Homebrew::Bundle::Dsl::Entry.new(:brew, "mysql") } it "returns true" do allow(Hardware::CPU).to receive(:arm?).and_return(true) allow(Homebrew).to receive(:default_prefix?).and_return(true) stub_formula_loader formula("mysql") { url "mysql-1.0" } expect(skipper.skip?(entry)).to be true end end context "with an unlisted cask", :needs_macos do let(:entry) { Homebrew::Bundle::Dsl::Entry.new(:cask, "java") } it "returns false" do expect(skipper.skip?(entry)).to be false end end context "with a flatpak entry", :needs_macos do let(:entry) { Homebrew::Bundle::Dsl::Entry.new(:flatpak, "org.gnome.Calculator") } it "skips on macOS with warning" do expect($stdout).to receive(:puts).with( Formatter.warning("Skipping flatpak org.gnome.Calculator (unsupported on macOS)"), ) expect(skipper.skip?(entry)).to be true end it "skips silently when silent flag is set" do expect($stdout).not_to receive(:puts) expect(skipper.skip?(entry, silent: true)).to be true end end context "with a flatpak entry on Linux", :needs_linux do let(:entry) { Homebrew::Bundle::Dsl::Entry.new(:flatpak, "org.gnome.Calculator") } it "does not skip" do expect(skipper.skip?(entry)).to be false end end context "with a listed formula in a failed tap" do let(:entry) { Homebrew::Bundle::Dsl::Entry.new(:brew, "org/repo/formula") } it "returns true" do skipper.tap_failed!("org/repo") expect(skipper.skip?(entry)).to be true end end end describe ".failed_tap!" do context "with a tap" do let(:tap) { Homebrew::Bundle::Dsl::Entry.new(:tap, "org/repo-b") } let(:entry) { Homebrew::Bundle::Dsl::Entry.new(:brew, "org/repo-b/formula") } it "returns false" do expect(skipper.skip?(entry)).to be false skipper.tap_failed! tap.name expect(skipper.skip?(entry)).to be true 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/bundle/remover_spec.rb
Library/Homebrew/test/bundle/remover_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/remover" RSpec.describe Homebrew::Bundle::Remover do subject(:remover) { described_class } let(:name) { "foo" } before { allow(Formulary).to receive(:factory).with(name).and_raise(FormulaUnavailableError.new(name)) } it "raises no errors when requested" do expect { remover.possible_names(name, raise_error: false) }.not_to raise_error 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/bundle/formula_installer_spec.rb
Library/Homebrew/test/bundle/formula_installer_spec.rb
# frozen_string_literal: true require "bundle" require "formula" require "bundle/formula_installer" require "bundle/formula_dumper" require "bundle/brew_services" RSpec.describe Homebrew::Bundle::FormulaInstaller do let(:formula_name) { "mysql" } let(:options) { { args: ["with-option"] } } let(:installer) { described_class.new(formula_name, options) } before do # don't try to load gcc/glibc allow(DevelopmentTools).to receive_messages(needs_libc_formula?: false, needs_compiler_formula?: false) stub_formula_loader formula(formula_name) { url "mysql-1.0" } end context "when the formula is installed" do before do allow_any_instance_of(described_class).to receive(:installed?).and_return(true) end context "with a true start_service option" do before do allow_any_instance_of(described_class).to receive(:install_change_state!).and_return(true) allow_any_instance_of(described_class).to receive(:installed?).and_return(true) allow(Homebrew::Bundle).to receive(:brew).with("link", formula_name, verbose: false).and_return(true) end context "when service is already running" do before do allow(Homebrew::Bundle::BrewServices).to receive(:started?).with(formula_name).and_return(true) end context "with a successful installation" do it "start service" do expect(Homebrew::Bundle::BrewServices).not_to receive(:start) described_class.preinstall!(formula_name, start_service: true) described_class.install!(formula_name, start_service: true) end end context "with a skipped installation" do it "start service" do expect(Homebrew::Bundle::BrewServices).not_to receive(:start) described_class.install!(formula_name, preinstall: false, start_service: true) end end end context "when service is not running" do before do allow(Homebrew::Bundle::BrewServices).to receive(:started?).with(formula_name).and_return(false) end context "with a successful installation" do it "start service" do expect(Homebrew::Bundle::BrewServices).to \ receive(:start).with(formula_name, file: nil, verbose: false).and_return(true) described_class.preinstall!(formula_name, start_service: true) described_class.install!(formula_name, start_service: true) end end context "with a skipped installation" do it "start service" do expect(Homebrew::Bundle::BrewServices).to \ receive(:start).with(formula_name, file: nil, verbose: false).and_return(true) described_class.install!(formula_name, preinstall: false, start_service: true) end end end end context "with an always restart_service option" do before do allow_any_instance_of(described_class).to receive(:install_change_state!).and_return(true) allow_any_instance_of(described_class).to receive(:installed?).and_return(true) allow(Homebrew::Bundle).to receive(:brew).with("link", formula_name, verbose: false).and_return(true) end context "with a successful installation" do it "restart service" do expect(Homebrew::Bundle::BrewServices).to \ receive(:restart).with(formula_name, file: nil, verbose: false).and_return(true) described_class.preinstall!(formula_name, restart_service: :always) described_class.install!(formula_name, restart_service: :always) end end context "with a skipped installation" do it "restart service" do expect(Homebrew::Bundle::BrewServices).to \ receive(:restart).with(formula_name, file: nil, verbose: false).and_return(true) described_class.install!(formula_name, preinstall: false, restart_service: :always) end end end context "when the link option is true" do before do allow_any_instance_of(described_class).to receive(:install_change_state!).and_return(true) end it "links formula" do allow_any_instance_of(described_class).to receive(:linked?).and_return(false) expect(Homebrew::Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "link", "mysql", verbose: false).and_return(true) described_class.preinstall!(formula_name, link: true) described_class.install!(formula_name, link: true) end it "force-links keg-only formula" do allow_any_instance_of(described_class).to receive(:linked?).and_return(false) allow_any_instance_of(described_class).to receive(:keg_only?).and_return(true) expect(Homebrew::Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "link", "--force", "mysql", verbose: false).and_return(true) described_class.preinstall!(formula_name, link: true) described_class.install!(formula_name, link: true) end end context "when the link option is :overwrite" do before do allow_any_instance_of(described_class).to receive(:install_change_state!).and_return(true) end it "overwrite links formula" do allow_any_instance_of(described_class).to receive(:linked?).and_return(false) expect(Homebrew::Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "link", "--overwrite", "mysql", verbose: false).and_return(true) described_class.preinstall!(formula_name, link: :overwrite) described_class.install!(formula_name, link: :overwrite) end end context "when the link option is false" do before do allow_any_instance_of(described_class).to receive(:install_change_state!).and_return(true) end it "unlinks formula" do allow_any_instance_of(described_class).to receive(:linked?).and_return(true) expect(Homebrew::Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "unlink", "mysql", verbose: false).and_return(true) described_class.preinstall!(formula_name, link: false) described_class.install!(formula_name, link: false) end end context "when the link option is nil and formula is unlinked and not keg-only" do before do allow_any_instance_of(described_class).to receive(:install_change_state!).and_return(true) allow_any_instance_of(described_class).to receive(:linked?).and_return(false) allow_any_instance_of(described_class).to receive(:keg_only?).and_return(false) end it "links formula" do expect(Homebrew::Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "link", "mysql", verbose: false).and_return(true) described_class.preinstall!(formula_name, link: nil) described_class.install!(formula_name, link: nil) end end context "when the link option is nil and formula is linked and keg-only" do before do allow_any_instance_of(described_class).to receive(:install_change_state!).and_return(true) allow_any_instance_of(described_class).to receive(:linked?).and_return(true) allow_any_instance_of(described_class).to receive(:keg_only?).and_return(true) end it "unlinks formula" do expect(Homebrew::Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "unlink", "mysql", verbose: false).and_return(true) described_class.preinstall!(formula_name, link: nil) described_class.install!(formula_name, link: nil) end end context "when the conflicts_with option is provided" do before do allow(Homebrew::Bundle::FormulaDumper).to receive(:formulae_by_full_name).and_call_original allow(Homebrew::Bundle::FormulaDumper).to receive(:formulae_by_full_name).with("mysql").and_return( name: "mysql", conflicts_with: ["mysql55"], ) allow(described_class).to receive(:formula_installed?).and_return(true) allow_any_instance_of(described_class).to receive(:install_formula!).and_return(true) allow_any_instance_of(described_class).to receive(:upgrade_formula!).and_return(true) end it "unlinks conflicts and stops their services" do verbose = false allow_any_instance_of(described_class).to receive(:linked?).and_return(true) expect(Homebrew::Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "unlink", "mysql55", verbose:).and_return(true) expect(Homebrew::Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "unlink", "mysql56", verbose:).and_return(true) expect(Homebrew::Bundle::BrewServices).to receive(:stop).with("mysql55", verbose:).and_return(true) expect(Homebrew::Bundle::BrewServices).to receive(:stop).with("mysql56", verbose:).and_return(true) expect(Homebrew::Bundle::BrewServices).to receive(:restart).with(formula_name, file: nil, verbose:).and_return(true) described_class.preinstall!(formula_name, restart_service: :always, conflicts_with: ["mysql56"]) described_class.install!(formula_name, restart_service: :always, conflicts_with: ["mysql56"]) end it "prints a message" do allow_any_instance_of(described_class).to receive(:linked?).and_return(true) allow_any_instance_of(described_class).to receive(:puts) verbose = true expect(Homebrew::Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "unlink", "mysql55", verbose:).and_return(true) expect(Homebrew::Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "unlink", "mysql56", verbose:).and_return(true) expect(Homebrew::Bundle::BrewServices).to receive(:stop).with("mysql55", verbose:).and_return(true) expect(Homebrew::Bundle::BrewServices).to receive(:stop).with("mysql56", verbose:).and_return(true) expect(Homebrew::Bundle::BrewServices).to receive(:restart).with(formula_name, file: nil, verbose:).and_return(true) described_class.preinstall!(formula_name, restart_service: :always, conflicts_with: ["mysql56"], verbose: true) described_class.install!(formula_name, restart_service: :always, conflicts_with: ["mysql56"], verbose: true) end end context "when the postinstall option is provided" do before do allow_any_instance_of(described_class).to receive(:install_change_state!).and_return(true) allow_any_instance_of(described_class).to receive(:installed?).and_return(true) allow(Homebrew::Bundle).to receive(:brew).with("link", formula_name, verbose: false).and_return(true) end context "when formula has changed" do before do allow_any_instance_of(described_class).to receive(:changed?).and_return(true) end it "runs the postinstall command" do expect(Kernel).to receive(:system).with("custom command").and_return(true) described_class.preinstall!(formula_name, postinstall: "custom command") described_class.install!(formula_name, postinstall: "custom command") end it "reports a failure" do expect(Kernel).to receive(:system).with("custom command").and_return(false) described_class.preinstall!(formula_name, postinstall: "custom command") expect(described_class.install!(formula_name, postinstall: "custom command")).to be(false) end end context "when formula has not changed" do before do allow_any_instance_of(described_class).to receive(:changed?).and_return(false) end it "does not run the postinstall command" do expect(Kernel).not_to receive(:system) described_class.preinstall!(formula_name, postinstall: "custom command") described_class.install!(formula_name, postinstall: "custom command") end end end context "when the version_file option is provided" do before do Homebrew::Bundle.reset! allow_any_instance_of(described_class).to receive(:install_change_state!).and_return(true) allow_any_instance_of(described_class).to receive(:installed?).and_return(true) allow_any_instance_of(described_class).to receive(:linked?).and_return(true) end let(:version_file) { "version.txt" } let(:version) { "1.0" } context "when formula versions are changed and specified by the environment" do before do allow_any_instance_of(described_class).to receive(:changed?).and_return(false) ENV["HOMEBREW_BUNDLE_EXEC_FORMULA_VERSION_#{formula_name.upcase}"] = version end it "writes the version to the file" do expect(File).to receive(:write).with(version_file, "#{version}\n") described_class.preinstall!(formula_name, version_file:) described_class.install!(formula_name, version_file:) end end context "when using the latest formula" do it "writes the version to the file" do expect(File).to receive(:write).with(version_file, "#{version}\n") described_class.preinstall!(formula_name, version_file:) described_class.install!(formula_name, version_file:) end end end end context "when a formula isn't installed" do before do allow_any_instance_of(described_class).to receive(:installed?).and_return(false) allow_any_instance_of(described_class).to receive(:install_change_state!).and_return(false) end it "did not call restart service" do expect(Homebrew::Bundle::BrewServices).not_to receive(:restart) described_class.preinstall!(formula_name, restart_service: true) end end describe ".outdated_formulae" do it "calls Homebrew" do described_class.reset! expect(Homebrew::Bundle::FormulaDumper).to receive(:formulae).and_return( [ { name: "a", outdated?: true }, { name: "b", outdated?: true }, { name: "c", outdated?: false }, ], ) expect(described_class.outdated_formulae).to eql(%w[a b]) end end describe ".pinned_formulae" do it "calls Homebrew" do described_class.reset! expect(Homebrew::Bundle::FormulaDumper).to receive(:formulae).and_return( [ { name: "a", pinned?: true }, { name: "b", pinned?: true }, { name: "c", pinned?: false }, ], ) expect(described_class.pinned_formulae).to eql(%w[a b]) end end describe ".formula_installed_and_up_to_date?" do before do Homebrew::Bundle::FormulaDumper.reset! described_class.reset! allow(described_class).to receive(:outdated_formulae).and_return(%w[bar]) allow_any_instance_of(Formula).to receive(:outdated?).and_return(true) allow(Homebrew::Bundle::FormulaDumper).to receive(:formulae).and_return [ { name: "foo", full_name: "homebrew/tap/foo", aliases: ["foobar"], args: [], version: "1.0", dependencies: [], requirements: [], }, { name: "bar", full_name: "bar", aliases: [], args: [], version: "1.0", dependencies: [], requirements: [], }, ] stub_formula_loader formula("foo") { url "foo-1.0" } stub_formula_loader formula("bar") { url "bar-1.0" } end it "returns result" do expect(described_class.formula_installed_and_up_to_date?("foo")).to be(true) expect(described_class.formula_installed_and_up_to_date?("foobar")).to be(true) expect(described_class.formula_installed_and_up_to_date?("bar")).to be(false) expect(described_class.formula_installed_and_up_to_date?("baz")).to be(false) end end context "when brew is installed" do context "when no formula is installed" do before do allow(described_class).to receive(:installed_formulae).and_return([]) allow_any_instance_of(described_class).to receive(:conflicts_with).and_return([]) allow_any_instance_of(described_class).to receive(:linked?).and_return(true) end it "install formula" do expect(Homebrew::Bundle).to receive(:system) .with(HOMEBREW_BREW_FILE, "install", "--formula", formula_name, "--with-option", verbose: false) .and_return(true) expect(installer.preinstall!).to be(true) expect(installer.install!).to be(true) end it "reports a failure" do expect(Homebrew::Bundle).to receive(:system) .with(HOMEBREW_BREW_FILE, "install", "--formula", formula_name, "--with-option", verbose: false) .and_return(false) expect(installer.preinstall!).to be(true) expect(installer.install!).to be(false) end end context "when formula is installed" do before do allow(described_class).to receive(:installed_formulae).and_return([formula_name]) allow_any_instance_of(described_class).to receive(:conflicts_with).and_return([]) allow_any_instance_of(described_class).to receive(:linked?).and_return(true) allow_any_instance_of(Formula).to receive(:outdated?).and_return(true) end context "when formula upgradable" do before do allow(described_class).to receive(:outdated_formulae).and_return([formula_name]) end it "upgrade formula" do expect(Homebrew::Bundle).to \ receive(:system).with(HOMEBREW_BREW_FILE, "upgrade", "--formula", formula_name, verbose: false) .and_return(true) expect(installer.preinstall!).to be(true) expect(installer.install!).to be(true) end it "reports a failure" do expect(Homebrew::Bundle).to \ receive(:system).with(HOMEBREW_BREW_FILE, "upgrade", "--formula", formula_name, verbose: false) .and_return(false) expect(installer.preinstall!).to be(true) expect(installer.install!).to be(false) end context "when formula pinned" do before do allow(described_class).to receive(:pinned_formulae).and_return([formula_name]) end it "does not upgrade formula" do expect(Homebrew::Bundle).not_to \ receive(:system).with(HOMEBREW_BREW_FILE, "upgrade", "--formula", formula_name, verbose: false) expect(installer.preinstall!).to be(false) end end context "when formula not upgraded" do before do allow(described_class).to receive(:outdated_formulae).and_return([]) end it "does not upgrade formula" do expect(Homebrew::Bundle).not_to receive(:system) expect(installer.preinstall!).to be(false) end end end end end describe "#changed?" do it "is false by default" do expect(described_class.new(formula_name).changed?).to be(false) end end describe "#start_service?" do it "is false by default" do expect(described_class.new(formula_name).start_service?).to be(false) end context "when the start_service option is true" do it "is true" do expect(described_class.new(formula_name, start_service: true).start_service?).to be(true) end end end describe "#start_service_needed?" do context "when a service is already started" do before do allow(Homebrew::Bundle::BrewServices).to receive(:started?).with(formula_name).and_return(true) end it "is false by default" do expect(described_class.new(formula_name).start_service_needed?).to be(false) end it "is false with {start_service: true}" do # rubocop:todo RSpec/AggregateExamples expect(described_class.new(formula_name, start_service: true).start_service_needed?).to be(false) end it "is false with {restart_service: true}" do # rubocop:todo RSpec/AggregateExamples expect(described_class.new(formula_name, restart_service: true).start_service_needed?).to be(false) end it "is false with {restart_service: :changed}" do # rubocop:todo RSpec/AggregateExamples expect(described_class.new(formula_name, restart_service: :changed).start_service_needed?).to be(false) end it "is false with {restart_service: :always}" do # rubocop:todo RSpec/AggregateExamples expect(described_class.new(formula_name, restart_service: :always).start_service_needed?).to be(false) end end context "when a service is not started" do before do allow(Homebrew::Bundle::BrewServices).to receive(:started?).with(formula_name).and_return(false) end it "is false by default" do expect(described_class.new(formula_name).start_service_needed?).to be(false) end it "is true if {start_service: true}" do # rubocop:todo RSpec/AggregateExamples expect(described_class.new(formula_name, start_service: true).start_service_needed?).to be(true) end it "is true if {restart_service: true}" do # rubocop:todo RSpec/AggregateExamples expect(described_class.new(formula_name, restart_service: true).start_service_needed?).to be(true) end it "is true if {restart_service: :changed}" do # rubocop:todo RSpec/AggregateExamples expect(described_class.new(formula_name, restart_service: :changed).start_service_needed?).to be(true) end it "is true if {restart_service: :always}" do # rubocop:todo RSpec/AggregateExamples expect(described_class.new(formula_name, restart_service: :always).start_service_needed?).to be(true) end end end describe "#restart_service?" do it "is false by default" do expect(described_class.new(formula_name).restart_service?).to be(false) end context "when the restart_service option is true" do it "is true" do expect(described_class.new(formula_name, restart_service: true).restart_service?).to be(true) end end context "when the restart_service option is always" do it "is true" do expect(described_class.new(formula_name, restart_service: :always).restart_service?).to be(true) end end context "when the restart_service option is changed" do it "is true" do expect(described_class.new(formula_name, restart_service: :changed).restart_service?).to be(true) end end end describe "#restart_service_needed?" do it "is false by default" do expect(described_class.new(formula_name).restart_service_needed?).to be(false) end context "when a service is unchanged" do before do allow_any_instance_of(described_class).to receive(:changed?).and_return(false) end it "is false with {restart_service: true}" do expect(described_class.new(formula_name, restart_service: true).restart_service_needed?).to be(false) end it "is true with {restart_service: :always}" do # rubocop:todo RSpec/AggregateExamples expect(described_class.new(formula_name, restart_service: :always).restart_service_needed?).to be(true) end it "is false if {restart_service: :changed}" do # rubocop:todo RSpec/AggregateExamples expect(described_class.new(formula_name, restart_service: :changed).restart_service_needed?).to be(false) end end context "when a service is changed" do before do allow_any_instance_of(described_class).to receive(:changed?).and_return(true) end it "is true with {restart_service: true}" do expect(described_class.new(formula_name, restart_service: true).restart_service_needed?).to be(true) end it "is true with {restart_service: :always}" do # rubocop:todo RSpec/AggregateExamples expect(described_class.new(formula_name, restart_service: :always).restart_service_needed?).to be(true) end it "is true if {restart_service: :changed}" do # rubocop:todo RSpec/AggregateExamples expect(described_class.new(formula_name, restart_service: :changed).restart_service_needed?).to be(true) 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/bundle/formula_dumper_spec.rb
Library/Homebrew/test/bundle/formula_dumper_spec.rb
# frozen_string_literal: true require "ostruct" require "bundle" require "bundle/formula_dumper" require "tsort" require "formula" require "tab" require "utils/bottles" # TODO: remove OpenStruct usage # rubocop:todo Style/OpenStructUse RSpec.describe Homebrew::Bundle::FormulaDumper do subject(:dumper) { described_class } let(:foo) do instance_double(Formula, name: "foo", desc: "foobar", oldnames: ["oldfoo"], full_name: "qux/quuz/foo", any_version_installed?: true, aliases: ["foobar"], runtime_dependencies: [], deps: [], conflicts: [], any_installed_prefix: nil, linked?: false, keg_only?: true, pinned?: false, outdated?: false, stable: OpenStruct.new(bottle_defined?: false, bottled?: false), tap: OpenStruct.new(official?: false)) end let(:foo_hash) do { aliases: ["foobar"], any_version_installed?: true, args: [], bottle: false, bottled: false, build_dependencies: [], conflicts_with: [], dependencies: [], desc: "foobar", full_name: "qux/quuz/foo", installed_as_dependency?: false, installed_on_request?: false, link?: nil, name: "foo", oldnames: ["oldfoo"], outdated?: false, pinned?: false, poured_from_bottle?: false, version: nil, official_tap: false, } end let(:bar) do linked_keg = Pathname("/usr/local").join("var").join("homebrew").join("linked").join("bar") instance_double(Formula, name: "bar", desc: "barfoo", oldnames: [], full_name: "bar", any_version_installed?: true, aliases: [], runtime_dependencies: [], deps: [], conflicts: [], any_installed_prefix: nil, linked?: true, keg_only?: false, pinned?: true, outdated?: true, linked_keg:, stable: OpenStruct.new(bottle_defined?: true, bottled?: true), tap: OpenStruct.new(official?: true), bottle_hash: { cellar: ":any", files: { big_sur: { sha256: "abcdef", url: "https://brew.sh//foo-1.0.big_sur.bottle.tar.gz", }, }, }) end let(:bar_hash) do { aliases: [], any_version_installed?: true, args: [], bottle: { cellar: ":any", files: { big_sur: { sha256: "abcdef", url: "https://brew.sh//foo-1.0.big_sur.bottle.tar.gz", }, }, }, bottled: true, build_dependencies: [], conflicts_with: [], dependencies: [], desc: "barfoo", full_name: "bar", installed_as_dependency?: false, installed_on_request?: false, link?: nil, name: "bar", oldnames: [], outdated?: true, pinned?: true, poured_from_bottle?: true, version: "1.0", official_tap: true, } end let(:baz) do instance_double(Formula, name: "baz", desc: "", oldnames: [], full_name: "bazzles/bizzles/baz", any_version_installed?: true, aliases: [], runtime_dependencies: [OpenStruct.new(name: "bar")], deps: [OpenStruct.new(name: "bar", build?: true)], conflicts: [], any_installed_prefix: nil, linked?: false, keg_only?: false, pinned?: false, outdated?: false, stable: OpenStruct.new(bottle_defined?: false, bottled?: false), tap: OpenStruct.new(official?: false)) end let(:baz_hash) do { aliases: [], any_version_installed?: true, args: [], bottle: false, bottled: false, build_dependencies: ["bar"], conflicts_with: [], dependencies: ["bar"], desc: "", full_name: "bazzles/bizzles/baz", installed_as_dependency?: false, installed_on_request?: false, link?: false, name: "baz", oldnames: [], outdated?: false, pinned?: false, poured_from_bottle?: false, version: nil, official_tap: false, } end before do described_class.reset! end describe "#formulae" do it "returns an empty array when no formulae are installed" do expect(dumper.formulae).to be_empty end end describe "#formulae_by_full_name" do it "returns an empty hash when no formulae are installed" do expect(dumper.formulae_by_full_name).to eql({}) end it "returns an empty hash for an unavailable formula" do expect(Formula).to receive(:[]).with("bar").and_raise(FormulaUnavailableError.new("bar")) expect(dumper.formulae_by_full_name("bar")).to eql({}) end it "exits on cyclic exceptions" do expect(Formula).to receive(:installed).and_return([foo, bar, baz]) expect_any_instance_of(Homebrew::Bundle::FormulaDumper::Topo).to receive(:tsort).and_raise( TSort::Cyclic, 'topological sort failed: ["foo", "bar"]', ) expect { dumper.formulae_by_full_name }.to raise_error(SystemExit) end it "returns a hash for a formula" do expect(Formula).to receive(:[]).with("qux/quuz/foo").and_return(foo) expect(dumper.formulae_by_full_name("qux/quuz/foo")).to eql(foo_hash) end it "returns an array for all formulae" do expect(Formula).to receive(:installed).and_return([foo, bar, baz]) expect(bar.linked_keg).to receive(:realpath).and_return(OpenStruct.new(basename: "1.0")) expect(Tab).to receive(:for_keg).with(bar.linked_keg).and_return( instance_double(Tab, installed_as_dependency: false, installed_on_request: false, poured_from_bottle: true, runtime_dependencies: [], used_options: []), ) expect(dumper.formulae_by_full_name).to eql({ "bar" => bar_hash, "qux/quuz/foo" => foo_hash, "bazzles/bizzles/baz" => baz_hash, }) end end describe "#formulae_by_name" do it "returns a hash for a formula" do expect(Formula).to receive(:[]).with("foo").and_return(foo) expect(dumper.formulae_by_name("foo")).to eql(foo_hash) end end describe "#dump" do it "returns a dump string with installed formulae" do expect(Formula).to receive(:installed).and_return([foo, bar, baz]) allow(Utils).to receive(:safe_popen_read).and_return("") expected = <<~EOS # barfoo brew "bar" brew "bazzles/bizzles/baz", link: false # foobar brew "qux/quuz/foo" EOS expect(dumper.dump(describe: true)).to eql(expected.chomp) end end describe "#formula_aliases" do it "returns an empty string when no formulae are installed" do expect(dumper.formula_aliases).to eql({}) end it "returns a hash with installed formulae aliases" do expect(Formula).to receive(:installed).and_return([foo, bar, baz]) expect(dumper.formula_aliases).to eql({ "qux/quuz/foobar" => "qux/quuz/foo", "foobar" => "qux/quuz/foo", }) end end describe "#formula_oldnames" do it "returns an empty string when no formulae are installed" do expect(dumper.formula_oldnames).to eql({}) end it "returns a hash with installed formulae old names" do expect(Formula).to receive(:installed).and_return([foo, bar, baz]) expect(dumper.formula_oldnames).to eql({ "qux/quuz/oldfoo" => "qux/quuz/foo", "oldfoo" => "qux/quuz/foo", }) end end end # rubocop:enable Style/OpenStructUse
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/bundle/vscode_extension_installer_spec.rb
Library/Homebrew/test/bundle/vscode_extension_installer_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/vscode_extension_installer" require "extend/kernel" RSpec.describe Homebrew::Bundle::VscodeExtensionInstaller do context "when VSCode is not installed" do before do described_class.reset! allow(Homebrew::Bundle).to receive_messages(vscode_installed?: false, cask_installed?: true) end it "tries to install vscode" do expect(Homebrew::Bundle).to \ receive(:system).with(HOMEBREW_BREW_FILE, "install", "--cask", "visual-studio-code", verbose: false) .and_return(true) expect { described_class.preinstall!("foo") }.to raise_error(RuntimeError) end end context "when VSCode is installed" do before do allow(Homebrew::Bundle).to receive(:which_vscode).and_return(Pathname("code")) end context "when extension is installed" do before do allow(described_class).to receive(:installed_extensions).and_return(["foo"]) end it "skips" do expect(Homebrew::Bundle).not_to receive(:system) expect(described_class.preinstall!("foo")).to be(false) end it "skips ignoring case" do expect(Homebrew::Bundle).not_to receive(:system) expect(described_class.preinstall!("Foo")).to be(false) end end context "when extension is not installed" do before do allow(described_class).to receive(:installed_extensions).and_return([]) end it "installs extension" do expect(Homebrew::Bundle).to \ receive(:system).with(Pathname("code"), "--install-extension", "foo", verbose: false).and_return(true) expect(described_class.preinstall!("foo")).to be(true) expect(described_class.install!("foo")).to be(true) end it "installs extension when euid != uid and Process::UID.re_exchangeable? returns true" do expect(Process).to receive(:euid).and_return(1).once expect(Process::UID).to receive(:re_exchangeable?).and_return(true).once expect(Process::UID).to receive(:re_exchange).twice expect(Homebrew::Bundle).to \ receive(:system).with(Pathname("code"), "--install-extension", "foo", verbose: false).and_return(true) expect(described_class.preinstall!("foo")).to be(true) expect(described_class.install!("foo")).to be(true) end it "installs extension when euid != uid and Process::UID.re_exchangeable? returns false" do expect(Process).to receive(:euid).and_return(1).once expect(Process::UID).to receive(:re_exchangeable?).and_return(false).once expect(Process::Sys).to receive(:seteuid).twice expect(Homebrew::Bundle).to \ receive(:system).with(Pathname("code"), "--install-extension", "foo", verbose: false).and_return(true) expect(described_class.preinstall!("foo")).to be(true) expect(described_class.install!("foo")).to be(true) 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/bundle/flatpak_checker_spec.rb
Library/Homebrew/test/bundle/flatpak_checker_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/flatpak_checker" require "bundle/flatpak_installer" RSpec.describe Homebrew::Bundle::Checker::FlatpakChecker do subject(:checker) { described_class.new } let(:entry) { Homebrew::Bundle::Dsl::Entry.new(:flatpak, "org.gnome.Calculator") } before do allow(Homebrew::Bundle::FlatpakInstaller).to receive(:package_installed?).and_return(false) end describe "#installed_and_up_to_date?", :needs_linux do it "returns false when package is not installed" do expect(checker.installed_and_up_to_date?("org.gnome.Calculator")).to be(false) end it "returns true when package is installed" do allow(Homebrew::Bundle::FlatpakInstaller).to receive(:package_installed?).and_return(true) expect(checker.installed_and_up_to_date?("org.gnome.Calculator")).to be(true) end describe "3-tier remote handling" do it "checks Tier 1 package with default remote (flathub)" do allow(Homebrew::Bundle::FlatpakInstaller).to receive(:package_installed?) .with("org.gnome.Calculator", remote: "flathub") .and_return(true) result = checker.installed_and_up_to_date?( { name: "org.gnome.Calculator", options: {} }, ) expect(result).to be(true) end it "checks Tier 1 package with named remote" do allow(Homebrew::Bundle::FlatpakInstaller).to receive(:package_installed?) .with("org.gnome.Calculator", remote: "fedora") .and_return(true) result = checker.installed_and_up_to_date?( { name: "org.gnome.Calculator", options: { remote: "fedora" } }, ) expect(result).to be(true) end it "checks Tier 2 package with URL remote (resolves to single-app remote)" do allow(Homebrew::Bundle::FlatpakInstaller).to receive(:package_installed?) .with("org.godotengine.Godot", remote: "org.godotengine.Godot-origin") .and_return(true) result = checker.installed_and_up_to_date?( { name: "org.godotengine.Godot", options: { remote: "https://dl.flathub.org/beta-repo/" } }, ) expect(result).to be(true) end it "checks Tier 2 package with .flatpakref by name only" do allow(Homebrew::Bundle::FlatpakInstaller).to receive(:package_installed?) .with("org.example.App") .and_return(true) result = checker.installed_and_up_to_date?( { name: "org.example.App", options: { remote: "https://example.com/app.flatpakref" } }, ) expect(result).to be(true) end it "checks Tier 3 package with URL and remote name" do allow(Homebrew::Bundle::FlatpakInstaller).to receive(:package_installed?) .with("org.godotengine.Godot", remote: "flathub-beta") .and_return(true) result = checker.installed_and_up_to_date?( { name: "org.godotengine.Godot", options: { remote: "flathub-beta", url: "https://dl.flathub.org/beta-repo/" } }, ) expect(result).to be(true) end end end describe "#failure_reason", :needs_linux do it "returns the correct failure message" do expect(checker.failure_reason("org.gnome.Calculator", no_upgrade: false)) .to eq("Flatpak org.gnome.Calculator needs to be installed.") end it "returns the correct failure message for hash package" do expect(checker.failure_reason({ name: "org.gnome.Calculator", options: {} }, no_upgrade: false)) .to eq("Flatpak org.gnome.Calculator needs to be installed.") end end context "when on macOS", :needs_macos do it "flatpak is not available" do expect(Homebrew::Bundle.flatpak_installed?).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/bundle/cargo_installer_spec.rb
Library/Homebrew/test/bundle/cargo_installer_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/cargo_installer" RSpec.describe Homebrew::Bundle::CargoInstaller do context "when Cargo is not installed" do before do described_class.reset! allow(Homebrew::Bundle).to receive(:cargo_installed?).and_return(false) end it "tries to install rust" do expect(Homebrew::Bundle).to \ receive(:system).with(HOMEBREW_BREW_FILE, "install", "--formula", "rust", verbose: false) .and_return(true) expect { described_class.preinstall!("ripgrep") }.to raise_error(RuntimeError) end end context "when Cargo is installed" do before do allow(Homebrew::Bundle).to receive(:cargo_installed?).and_return(true) end context "when package is installed" do before do allow(described_class).to receive(:installed_packages) .and_return(["ripgrep"]) end it "skips" do expect(Homebrew::Bundle).not_to receive(:system) expect(described_class.preinstall!("ripgrep")).to be(false) end end context "when package is not installed" do before do allow(Homebrew::Bundle).to receive(:which_cargo).and_return(Pathname.new("/tmp/rust/bin/cargo")) allow(described_class).to receive(:installed_packages).and_return([]) end it "installs package" do expect(Homebrew::Bundle).to receive(:system) do |*args, verbose:| expect(ENV.fetch("PATH", "")).to start_with("/tmp/rust/bin:") expect(args).to eq(["/tmp/rust/bin/cargo", "install", "--locked", "ripgrep"]) expect(verbose).to be(false) true end expect(described_class.preinstall!("ripgrep")).to be(true) expect(described_class.install!("ripgrep")).to be(true) 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/bundle/flatpak_dumper_spec.rb
Library/Homebrew/test/bundle/flatpak_dumper_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/flatpak_dumper" RSpec.describe Homebrew::Bundle::FlatpakDumper do subject(:dumper) { described_class } context "when flatpak is not installed" do before do described_class.reset! allow(Homebrew::Bundle).to receive(:flatpak_installed?).and_return(false) end it "returns an empty list and dumps an empty string" do expect(dumper.packages).to be_empty expect(dumper.dump).to eql("") end end context "when flatpak is installed", :needs_linux do before do described_class.reset! allow(Homebrew::Bundle).to receive_messages(flatpak_installed?: true, which_flatpak: Pathname.new("flatpak")) end it "returns remote URLs" do allow(described_class).to receive(:`).with("flatpak remote-list --system --columns=name,url 2>/dev/null") .and_return("flathub\thttps://dl.flathub.org/repo/\nfedora\thttps://registry.fedoraproject.org/\n") expect(dumper.remote_urls).to eql({ "flathub" => "https://dl.flathub.org/repo/", "fedora" => "https://registry.fedoraproject.org/", }) end it "returns package list with remotes and URLs" do allow(described_class).to receive(:`).with("flatpak list --app --columns=application,origin 2>/dev/null") .and_return("org.gnome.Calculator\tflathub\ncom.spotify.Client\tflathub\n") allow(described_class).to receive(:`).with("flatpak remote-list --system --columns=name,url 2>/dev/null") .and_return("flathub\thttps://dl.flathub.org/repo/\n") expect(dumper.packages_with_remotes).to eql([ { name: "com.spotify.Client", remote: "flathub", remote_url: "https://dl.flathub.org/repo/" }, { name: "org.gnome.Calculator", remote: "flathub", remote_url: "https://dl.flathub.org/repo/" }, ]) end it "returns package names only" do allow(described_class).to receive(:`).with("flatpak list --app --columns=application,origin 2>/dev/null") .and_return("org.gnome.Calculator\tflathub\ncom.spotify.Client\tflathub\n") allow(described_class).to receive(:`).with("flatpak remote-list --system --columns=name,url 2>/dev/null") .and_return("flathub\thttps://dl.flathub.org/repo/\n") expect(dumper.packages).to eql(["com.spotify.Client", "org.gnome.Calculator"]) end describe "3-tier dump format" do it "dumps Tier 1 packages without remote (flathub default)" do allow(dumper).to receive(:packages_with_remotes).and_return([ { name: "org.gnome.Calculator", remote: "flathub", remote_url: "https://dl.flathub.org/repo/" }, { name: "com.spotify.Client", remote: "flathub", remote_url: "https://dl.flathub.org/repo/" }, ]) expect(dumper.dump).to eql("flatpak \"org.gnome.Calculator\"\nflatpak \"com.spotify.Client\"") end it "dumps Tier 2 packages with URL only (single-app remote)" do allow(dumper).to receive(:packages_with_remotes).and_return([ { name: "org.godotengine.Godot", remote: "org.godotengine.Godot-origin", remote_url: "https://dl.flathub.org/beta-repo/" }, ]) expect(dumper.dump).to eql( "flatpak \"org.godotengine.Godot\", remote: \"https://dl.flathub.org/beta-repo/\"", ) end it "dumps Tier 2 packages with remote name if URL not available" do allow(dumper).to receive(:packages_with_remotes).and_return([ { name: "org.example.App", remote: "org.example.App-origin", remote_url: nil }, ]) expect(dumper.dump).to eql( "flatpak \"org.example.App\", remote: \"org.example.App-origin\"", ) end it "dumps Tier 3 packages with remote name and URL (shared remote)" do allow(dumper).to receive(:packages_with_remotes).and_return([ { name: "org.godotengine.Godot", remote: "flathub-beta", remote_url: "https://dl.flathub.org/beta-repo/" }, ]) expect(dumper.dump).to eql( "flatpak \"org.godotengine.Godot\", remote: \"flathub-beta\", url: \"https://dl.flathub.org/beta-repo/\"", ) end it "dumps named remote without URL when URL is not available" do allow(dumper).to receive(:packages_with_remotes).and_return([ { name: "com.custom.App", remote: "custom-repo", remote_url: nil }, ]) expect(dumper.dump).to eql( "flatpak \"com.custom.App\", remote: \"custom-repo\"", ) end it "dumps mixed packages correctly" do allow(dumper).to receive(:packages_with_remotes).and_return([ { name: "com.spotify.Client", remote: "flathub", remote_url: "https://dl.flathub.org/repo/" }, { name: "org.godotengine.Godot", remote: "org.godotengine.Godot-origin", remote_url: "https://dl.flathub.org/beta-repo/" }, { name: "io.github.dvlv.boxbuddyrs", remote: "flathub-beta", remote_url: "https://dl.flathub.org/beta-repo/" }, ]) expect(dumper.dump).to eql( "flatpak \"com.spotify.Client\"\n" \ "flatpak \"org.godotengine.Godot\", remote: \"https://dl.flathub.org/beta-repo/\"\n" \ "flatpak \"io.github.dvlv.boxbuddyrs\", remote: \"flathub-beta\", url: \"https://dl.flathub.org/beta-repo/\"", ) end end it "handles packages without origin" do allow(described_class).to receive(:`).with("flatpak list --app --columns=application,origin 2>/dev/null") .and_return("org.gnome.Calculator\n") allow(described_class).to receive(:`).with("flatpak remote-list --system --columns=name,url 2>/dev/null") .and_return("flathub\thttps://dl.flathub.org/repo/\n") expect(dumper.packages_with_remotes).to eql([ { name: "org.gnome.Calculator", remote: "flathub", remote_url: "https://dl.flathub.org/repo/" }, ]) 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/bundle/installer_spec.rb
Library/Homebrew/test/bundle/installer_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/dsl" require "bundle/installer" RSpec.describe Homebrew::Bundle::Installer do let(:formula_entry) { Homebrew::Bundle::Dsl::Entry.new(:brew, "mysql") } let(:cask_options) { { args: {}, full_name: "homebrew/cask/google-chrome" } } let(:cask_entry) { Homebrew::Bundle::Dsl::Entry.new(:cask, "google-chrome", cask_options) } before do allow(Homebrew::Bundle::Skipper).to receive(:skip?).and_return(false) allow(Homebrew::Bundle::FormulaInstaller).to receive_messages(formula_upgradable?: false, install!: true) allow(Homebrew::Bundle::FormulaInstaller).to receive_messages(formula_installed_and_up_to_date?: false, preinstall!: true) allow(Homebrew::Bundle::CaskInstaller).to receive_messages(cask_upgradable?: false, install!: true) allow(Homebrew::Bundle::CaskInstaller).to receive_messages(installable_or_upgradable?: true, preinstall!: true) allow(Homebrew::Bundle::TapInstaller).to receive_messages(preinstall!: true, install!: true, installed_taps: []) end it "prefetches installable formulae and casks before installing" do allow(Homebrew::Bundle::TapInstaller).to receive(:installed_taps).and_return(["homebrew/cask"]) allow(Homebrew::Bundle::FormulaInstaller).to receive(:formula_installed_and_up_to_date?) .with("mysql", no_upgrade: false).and_return(false) allow(Homebrew::Bundle::CaskInstaller).to receive(:installable_or_upgradable?) .with("google-chrome", no_upgrade: false, **cask_options).and_return(true) expect(Homebrew::Bundle).to receive(:brew) .with("fetch", "mysql", "homebrew/cask/google-chrome", verbose: false) .ordered .and_return(true) expect(Homebrew::Bundle::FormulaInstaller).to receive(:preinstall!) .with("mysql", no_upgrade: false, verbose: false) .ordered .and_return(true) expect(Homebrew::Bundle::CaskInstaller).to receive(:preinstall!) .with("google-chrome", **cask_options, no_upgrade: false, verbose: false) .ordered .and_return(true) described_class.install!([formula_entry, cask_entry], verbose: false, force: false, quiet: true) end it "skips fetching when no formulae or casks need installation or upgrade" do allow(Homebrew::Bundle::FormulaInstaller).to receive(:formula_installed_and_up_to_date?) .with("mysql", no_upgrade: true).and_return(true) expect(Homebrew::Bundle).not_to receive(:brew).with("fetch", any_args) described_class.install!([formula_entry], no_upgrade: true, quiet: true) end it "skips fetching formulae from untapped taps" do tap_entry = Homebrew::Bundle::Dsl::Entry.new(:tap, "homebrew/foo") tapped_formula_entry = Homebrew::Bundle::Dsl::Entry.new(:brew, "homebrew/foo/bar") allow(Homebrew::Bundle::FormulaInstaller).to receive(:formula_installed_and_up_to_date?) .with("homebrew/foo/bar", no_upgrade: false).and_return(false) expect(Homebrew::Bundle).not_to receive(:brew).with("fetch", any_args) described_class.install!([tap_entry, tapped_formula_entry], quiet: true) 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/bundle/commands/remove_spec.rb
Library/Homebrew/test/bundle/commands/remove_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/commands/remove" require "cask/cask_loader" RSpec.describe Homebrew::Bundle::Commands::Remove do subject(:remove) do described_class.run(*args, type:, global:, file:) end before { File.write(file, content) } after { FileUtils.rm_f file } let(:global) { false } context "when called with a valid formula" do let(:args) { ["hello"] } let(:type) { :brew } let(:file) { "/tmp/some_random_brewfile#{Random.rand(2 ** 16)}" } let(:content) do <<~BREWFILE brew "hello" BREWFILE end before do stub_formula_loader formula("hello") { url "hello-1.0" } end it "removes entries from the given Brewfile" do expect { remove }.not_to raise_error expect(File.read(file)).not_to include("#{type} \"#{args.first}\"") end end context "when called with no type" do let(:args) { ["foo"] } let(:type) { :none } let(:file) { "/tmp/some_random_brewfile#{Random.rand(2 ** 16)}" } let(:content) do <<~BREWFILE tap "someone/tap" brew "foo" cask "foo" BREWFILE end it "removes all matching entries from the given Brewfile" do expect { remove }.not_to raise_error expect(File.read(file)).not_to include(args.first) end context "with arguments that match entries only when considering formula aliases" do let(:foo) do instance_double( Formula, name: "foo", full_name: "qux/quuz/foo", oldnames: ["oldfoo"], aliases: ["foobar"], ) end let(:args) { ["foobar"] } it "suggests using `--formula` to match against formula aliases" do expect(Formulary).to receive(:factory).with("foobar").and_return(foo) expect { remove }.not_to raise_error expect(File.read(file)).to eq(content) # FIXME: Why doesn't this work? # expect { remove }.to output("--formula").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/bundle/commands/install_spec.rb
Library/Homebrew/test/bundle/commands/install_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/commands/install" require "bundle/cask_dumper" require "bundle/skipper" RSpec.describe Homebrew::Bundle::Commands::Install do before do allow_any_instance_of(IO).to receive(:puts) end context "when a Brewfile is not found" do it "raises an error" do allow_any_instance_of(Pathname).to receive(:read).and_raise(Errno::ENOENT) expect { described_class.run }.to raise_error(RuntimeError) end end context "when a Brewfile is found", :no_api do before do Homebrew::Bundle::CaskDumper.reset! allow(Homebrew::Bundle).to receive(:brew).and_return(true) allow(Homebrew::Bundle::FormulaInstaller).to receive(:formula_installed_and_up_to_date?).and_return(false) allow(Homebrew::Bundle::CaskInstaller).to receive(:installable_or_upgradable?).and_return(true) allow(Homebrew::Bundle::TapInstaller).to receive(:installed_taps).and_return([]) end let(:brewfile_contents) do <<~EOS tap 'phinze/cask' brew 'mysql', conflicts_with: ['mysql56'] cask 'phinze/cask/google-chrome', greedy: true mas '1Password', id: 443987910 vscode 'GitHub.codespaces' flatpak 'org.gnome.Calculator' EOS end it "does not raise an error" do allow(Homebrew::Bundle::TapInstaller).to receive(:preinstall!).and_return(false) allow(Homebrew::Bundle::VscodeExtensionInstaller).to receive(:preinstall!).and_return(false) allow(Homebrew::Bundle::FlatpakInstaller).to receive(:preinstall!).and_return(false) allow(Homebrew::Bundle::FormulaInstaller).to receive_messages(preinstall!: true, install!: true) allow(Homebrew::Bundle::CaskInstaller).to receive_messages(preinstall!: true, install!: true) allow(Homebrew::Bundle::MacAppStoreInstaller).to receive_messages(preinstall!: true, install!: true) allow_any_instance_of(Pathname).to receive(:read).and_return(brewfile_contents) expect { described_class.run }.not_to raise_error end it "#dsl returns a valid DSL" do allow(Homebrew::Bundle::TapInstaller).to receive(:preinstall!).and_return(false) allow(Homebrew::Bundle::VscodeExtensionInstaller).to receive(:preinstall!).and_return(false) allow(Homebrew::Bundle::FlatpakInstaller).to receive(:preinstall!).and_return(false) allow(Homebrew::Bundle::FormulaInstaller).to receive_messages(preinstall!: true, install!: true) allow(Homebrew::Bundle::CaskInstaller).to receive_messages(preinstall!: true, install!: true) allow(Homebrew::Bundle::MacAppStoreInstaller).to receive_messages(preinstall!: true, install!: true) allow_any_instance_of(Pathname).to receive(:read).and_return(brewfile_contents) described_class.run expect(described_class.dsl.entries.first.name).to eql("phinze/cask") end it "does not raise an error when skippable" do expect(Homebrew::Bundle::FormulaInstaller).not_to receive(:install!) allow(Homebrew::Bundle::Skipper).to receive(:skip?).and_return(true) allow_any_instance_of(Pathname).to receive(:read) .and_return("brew 'mysql'") expect { described_class.run }.not_to raise_error end it "exits on failures" do allow(Homebrew::Bundle::FormulaInstaller).to receive_messages(preinstall!: true, install!: false) allow(Homebrew::Bundle::CaskInstaller).to receive_messages(preinstall!: true, install!: false) allow(Homebrew::Bundle::MacAppStoreInstaller).to receive_messages(preinstall!: true, install!: false) allow(Homebrew::Bundle::TapInstaller).to receive_messages(preinstall!: true, install!: false) allow(Homebrew::Bundle::VscodeExtensionInstaller).to receive_messages(preinstall!: true, install!: false) allow(Homebrew::Bundle::FlatpakInstaller).to receive_messages(preinstall!: true, install!: false) allow_any_instance_of(Pathname).to receive(:read).and_return(brewfile_contents) expect { described_class.run }.to raise_error(SystemExit) end it "skips installs from failed taps" do allow(Homebrew::Bundle::CaskInstaller).to receive(:preinstall!).and_return(false) allow(Homebrew::Bundle::TapInstaller).to receive_messages(preinstall!: true, install!: false) allow(Homebrew::Bundle::FormulaInstaller).to receive_messages(preinstall!: true, install!: true) allow(Homebrew::Bundle::MacAppStoreInstaller).to receive_messages(preinstall!: true, install!: true) allow(Homebrew::Bundle::VscodeExtensionInstaller).to receive_messages(preinstall!: true, install!: true) allow(Homebrew::Bundle::FlatpakInstaller).to receive_messages(preinstall!: true, install!: true) allow_any_instance_of(Pathname).to receive(:read).and_return(brewfile_contents) expect { described_class.run }.to raise_error(SystemExit) end it "marks Brewfile formulae as installed_on_request after installing" do allow(Homebrew::Bundle::TapInstaller).to receive(:preinstall!).and_return(false) allow(Homebrew::Bundle::VscodeExtensionInstaller).to receive(:preinstall!).and_return(false) allow(Homebrew::Bundle::FlatpakInstaller).to receive(:preinstall!).and_return(false) allow(Homebrew::Bundle::FormulaInstaller).to receive_messages(preinstall!: true, install!: true) allow(Homebrew::Bundle::CaskInstaller).to receive_messages(preinstall!: true, install!: true) allow(Homebrew::Bundle::MacAppStoreInstaller).to receive_messages(preinstall!: true, install!: true) allow_any_instance_of(Pathname).to receive(:read).and_return("brew 'test_formula'") expect(Homebrew::Bundle).to receive(:mark_as_installed_on_request!) described_class.run 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/bundle/commands/check_spec.rb
Library/Homebrew/test/bundle/commands/check_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/commands/check" require "bundle/brew_checker" require "bundle/cask_checker" require "bundle/mac_app_store_checker" require "bundle/vscode_extension_checker" require "bundle/formula_installer" require "bundle/cask_installer" require "bundle/mac_app_store_installer" require "bundle/dsl" require "bundle/skipper" RSpec.describe Homebrew::Bundle::Commands::Check, :no_api do let(:do_check) do described_class.run(no_upgrade:, verbose:) end let(:no_upgrade) { false } let(:verbose) { false } before do Homebrew::Bundle::Checker.reset! allow_any_instance_of(IO).to receive(:puts) stub_formula_loader formula("mas") { url "mas-1.0" } end context "when dependencies are satisfied" do it "does not raise an error" do allow_any_instance_of(Pathname).to receive(:read).and_return("") nothing = [] allow(Homebrew::Bundle::Checker).to receive_messages(casks_to_install: nothing, formulae_to_install: nothing, apps_to_install: nothing, taps_to_tap: nothing, extensions_to_install: nothing) expect { do_check }.not_to raise_error end end context "when no dependencies are specified" do it "does not raise an error" do allow_any_instance_of(Pathname).to receive(:read).and_return("") allow_any_instance_of(Homebrew::Bundle::Dsl).to receive(:entries).and_return([]) expect { do_check }.not_to raise_error end end context "when casks are not installed", :needs_macos do it "raises an error" do allow(Homebrew::Bundle).to receive(:cask_installed?).and_return(true) allow(Homebrew::Bundle::CaskDumper).to receive(:casks).and_return([]) allow(Homebrew::Bundle::FormulaInstaller).to receive(:upgradable_formulae).and_return([]) allow_any_instance_of(Pathname).to receive(:read).and_return("cask 'abc'") expect { do_check }.to raise_error(SystemExit) end end context "when formulae are not installed" do let(:verbose) { true } it "raises an error and outputs to stdout" do allow(Homebrew::Bundle::CaskDumper).to receive(:casks).and_return([]) allow(Homebrew::Bundle::FormulaInstaller).to receive(:upgradable_formulae).and_return([]) allow_any_instance_of(Pathname).to receive(:read).and_return("brew 'abc'") expect { do_check }.to raise_error(SystemExit).and \ output(/brew bundle can't satisfy your Brewfile's dependencies/).to_stdout end it "partially outputs when HOMEBREW_BUNDLE_CHECK_ALREADY_OUTPUT_FORMULAE_ERRORS is set" do allow(Homebrew::Bundle::CaskDumper).to receive(:casks).and_return([]) allow(Homebrew::Bundle::FormulaInstaller).to receive(:upgradable_formulae).and_return([]) allow_any_instance_of(Pathname).to receive(:read).and_return("brew 'abc'") ENV["HOMEBREW_BUNDLE_CHECK_ALREADY_OUTPUT_FORMULAE_ERRORS"] = "abc" expect { do_check }.to raise_error(SystemExit).and \ output("Satisfy missing dependencies with `brew bundle install`.\n").to_stdout end it "does not raise error on skippable formula" do allow(Homebrew::Bundle::CaskDumper).to receive(:casks).and_return([]) allow(Homebrew::Bundle::FormulaInstaller).to receive(:upgradable_formulae).and_return([]) allow(Homebrew::Bundle::Skipper).to receive(:skip?).and_return(true) allow_any_instance_of(Pathname).to receive(:read).and_return("brew 'abc'") expect { do_check }.not_to raise_error end end context "when taps are not tapped" do it "raises an error" do allow(Homebrew::Bundle::CaskDumper).to receive(:casks).and_return([]) allow(Homebrew::Bundle::FormulaInstaller).to receive(:upgradable_formulae).and_return([]) allow_any_instance_of(Pathname).to receive(:read).and_return("tap 'abc/def'") expect { do_check }.to raise_error(SystemExit) end end context "when apps are not installed", :needs_macos do it "raises an error" do allow(Homebrew::Bundle::MacAppStoreDumper).to receive(:app_ids).and_return([]) allow(Homebrew::Bundle::FormulaInstaller).to receive(:upgradable_formulae).and_return([]) allow_any_instance_of(Pathname).to receive(:read).and_return("mas 'foo', id: 123") expect { do_check }.to raise_error(SystemExit) end end context "when service is not started and app not installed" do let(:verbose) { true } let(:expected_output) do <<~MSG brew bundle can't satisfy your Brewfile's dependencies. → App foo needs to be installed or updated. → Service def needs to be started. Satisfy missing dependencies with `brew bundle install`. MSG end before do Homebrew::Bundle::Checker.reset! allow_any_instance_of(Homebrew::Bundle::Checker::MacAppStoreChecker).to \ receive(:installed_and_up_to_date?).and_return(false) allow(Homebrew::Bundle::FormulaInstaller).to receive_messages(installed_formulae: ["abc", "def"], upgradable_formulae: []) allow(Homebrew::Bundle::BrewServices).to receive(:started?).with("abc").and_return(true) allow(Homebrew::Bundle::BrewServices).to receive(:started?).with("def").and_return(false) end it "does not raise error when no service needs to be started" do Homebrew::Bundle::Checker.reset! allow_any_instance_of(Pathname).to receive(:read).and_return("brew 'abc'") expect(Homebrew::Bundle::FormulaInstaller.installed_formulae).to include("abc") expect(Homebrew::Bundle::CaskInstaller.installed_casks).not_to include("abc") expect(Homebrew::Bundle::BrewServices.started?("abc")).to be(true) expect { do_check }.not_to raise_error end context "when restart_service is true" do it "raises an error" do allow_any_instance_of(Pathname) .to receive(:read).and_return("brew 'abc', restart_service: true\nbrew 'def', restart_service: true") allow_any_instance_of(Homebrew::Bundle::Checker::MacAppStoreChecker) .to receive(:format_checkable).and_return(1 => "foo") expect { do_check }.to raise_error(SystemExit).and output(expected_output).to_stdout end end context "when start_service is true" do it "raises an error" do allow_any_instance_of(Pathname) .to receive(:read).and_return("brew 'abc', start_service: true\nbrew 'def', start_service: true") allow_any_instance_of(Homebrew::Bundle::Checker::MacAppStoreChecker) .to receive(:format_checkable).and_return(1 => "foo") expect { do_check }.to raise_error(SystemExit).and output(expected_output).to_stdout end end end context "when app not installed and `no_upgrade` is true" do let(:expected_output) do <<~MSG brew bundle can't satisfy your Brewfile's dependencies. → App foo needs to be installed. Satisfy missing dependencies with `brew bundle install`. MSG end let(:no_upgrade) { true } let(:verbose) { true } before do Homebrew::Bundle::Checker.reset! allow_any_instance_of(Homebrew::Bundle::Checker::MacAppStoreChecker).to \ receive(:installed_and_up_to_date?).and_return(false) allow(Homebrew::Bundle::FormulaInstaller).to receive(:installed_formulae).and_return(["abc", "def"]) end it "raises an error that doesn't mention upgrade" do allow_any_instance_of(Pathname).to receive(:read).and_return("brew 'abc'") allow_any_instance_of(Homebrew::Bundle::Checker::MacAppStoreChecker).to \ receive(:format_checkable).and_return(1 => "foo") expect { do_check }.to raise_error(SystemExit).and output(expected_output).to_stdout end end context "when extension not installed" do let(:expected_output) do <<~MSG brew bundle can't satisfy your Brewfile's dependencies. → VSCode Extension foo needs to be installed. Satisfy missing dependencies with `brew bundle install`. MSG end let(:verbose) { true } before do Homebrew::Bundle::Checker.reset! allow_any_instance_of(Homebrew::Bundle::Checker::VscodeExtensionChecker).to \ receive(:installed_and_up_to_date?).and_return(false) end it "raises an error that doesn't mention upgrade" do allow_any_instance_of(Pathname).to receive(:read).and_return("vscode 'foo'") expect { do_check }.to raise_error(SystemExit).and output(expected_output).to_stdout end end context "when there are taps to install" do before do allow_any_instance_of(Pathname).to receive(:read).and_return("") allow(Homebrew::Bundle::Checker).to receive(:taps_to_tap).and_return(["asdf"]) end it "does not check for casks" do expect(Homebrew::Bundle::Checker).not_to receive(:casks_to_install) expect { do_check }.to raise_error(SystemExit) end it "does not check for formulae" do expect(Homebrew::Bundle::Checker).not_to receive(:formulae_to_install) expect { do_check }.to raise_error(SystemExit) end it "does not check for apps" do expect(Homebrew::Bundle::Checker).not_to receive(:apps_to_install) expect { do_check }.to raise_error(SystemExit) end end context "when there are VSCode extensions to install" do before do allow_any_instance_of(Pathname).to receive(:read).and_return("") allow(Homebrew::Bundle::Checker).to receive(:extensions_to_install).and_return(["asdf"]) end it "does not check for formulae" do expect(Homebrew::Bundle::Checker).not_to receive(:formulae_to_install) expect { do_check }.to raise_error(SystemExit) end it "does not check for apps" do expect(Homebrew::Bundle::Checker).not_to receive(:apps_to_install) expect { do_check }.to raise_error(SystemExit) end end context "when there are formulae to install" do before do allow_any_instance_of(Pathname).to receive(:read).and_return("") allow(Homebrew::Bundle::Checker).to \ receive_messages(taps_to_tap: [], casks_to_install: [], apps_to_install: [], formulae_to_install: ["one"]) end it "does not start formulae" do expect(Homebrew::Bundle::Checker).not_to receive(:formulae_to_start) expect { do_check }.to raise_error(SystemExit) end end context "when verbose mode is not enabled" do it "stops checking after the first missing formula" do allow(Homebrew::Bundle::CaskDumper).to receive(:casks).and_return([]) allow(Homebrew::Bundle::FormulaInstaller).to receive(:upgradable_formulae).and_return([]) allow_any_instance_of(Pathname).to receive(:read).and_return("brew 'abc'\nbrew 'def'") expect_any_instance_of(Homebrew::Bundle::Checker::BrewChecker).to \ receive(:exit_early_check).once.and_call_original expect { do_check }.to raise_error(SystemExit) end it "stops checking after the first missing cask", :needs_macos do allow_any_instance_of(Pathname).to receive(:read).and_return("cask 'abc'\ncask 'def'") expect_any_instance_of(Homebrew::Bundle::Checker::CaskChecker).to \ receive(:exit_early_check).once.and_call_original expect { do_check }.to raise_error(SystemExit) end it "stops checking after the first missing mac app", :needs_macos do allow_any_instance_of(Pathname).to receive(:read).and_return("mas 'foo', id: 123\nmas 'bar', id: 456") expect_any_instance_of(Homebrew::Bundle::Checker::MacAppStoreChecker).to \ receive(:exit_early_check).once.and_call_original expect { do_check }.to raise_error(SystemExit) end it "stops checking after the first VSCode extension" do allow_any_instance_of(Pathname).to receive(:read).and_return("vscode 'abc'\nvscode 'def'") expect_any_instance_of(Homebrew::Bundle::Checker::VscodeExtensionChecker).to \ receive(:exit_early_check).once.and_call_original expect { do_check }.to raise_error(SystemExit) end end context "when a new checker fails to implement installed_and_up_to_date" do it "raises an exception" do stub_const("TestChecker", Class.new(Homebrew::Bundle::Checker::Base) do class_eval("PACKAGE_TYPE = :test", __FILE__, __LINE__) end.freeze) test_entry = Homebrew::Bundle::Dsl::Entry.new(:test, "test") expect { TestChecker.new.find_actionable([test_entry]) }.to raise_error(NotImplementedError) 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/bundle/commands/list_spec.rb
Library/Homebrew/test/bundle/commands/list_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/commands/list" TYPES_AND_DEPS = { taps: "phinze/cask", formulae: "mysql", casks: "google-chrome", mas: "1Password", vscode: "shopify.ruby-lsp", go: "github.com/charmbracelet/crush", cargo: "ripgrep", }.freeze COMBINATIONS = begin keys = TYPES_AND_DEPS.keys 1.upto(keys.length).flat_map do |i| keys.combination(i).take((1..keys.length).reduce(:*) || 1) end.sort end.freeze RSpec.describe Homebrew::Bundle::Commands::List do subject(:list) do described_class.run( global: false, file: nil, formulae: formulae, casks: casks, taps: taps, mas: mas, vscode: vscode, go: go, cargo: cargo, flatpak: false, ) end let(:formulae) { true } let(:casks) { false } let(:taps) { false } let(:mas) { false } let(:vscode) { false } let(:go) { false } let(:cargo) { false } before do allow_any_instance_of(IO).to receive(:puts) end describe "outputs dependencies to stdout" do before do allow_any_instance_of(Pathname).to receive(:read).and_return( <<~EOS, tap 'phinze/cask' brew 'mysql', conflicts_with: ['mysql56'] cask 'google-chrome' mas '1Password', id: 443987910 vscode 'shopify.ruby-lsp' go 'github.com/charmbracelet/crush' cargo 'ripgrep' EOS ) end it "only shows brew deps when no options are passed" do expect { list }.to output("mysql\n").to_stdout end describe "limiting when certain options are passed" do COMBINATIONS.each do |options_list| opts_string = options_list.map { |o| "`#{o}`" }.join(" and ") verb = (options_list.length == 1) ? "is" : "are" words = options_list.join(" and ") context "when #{opts_string} #{verb} passed" do let(:formulae) { options_list.include?(:formulae) } let(:casks) { options_list.include?(:casks) } let(:taps) { options_list.include?(:taps) } let(:mas) { options_list.include?(:mas) } let(:vscode) { options_list.include?(:vscode) } let(:go) { options_list.include?(:go) } let(:cargo) { options_list.include?(:cargo) } it "shows only #{words}" do expected = options_list.map { |opt| TYPES_AND_DEPS[opt] }.join("\n") expect { list }.to output("#{expected}\n").to_stdout end 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/bundle/commands/cleanup_spec.rb
Library/Homebrew/test/bundle/commands/cleanup_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/commands/cleanup" RSpec.describe Homebrew::Bundle::Commands::Cleanup do describe "read Brewfile and current installation", :no_api do before do described_class.reset! # don't try to load gcc/glibc allow(DevelopmentTools).to receive_messages(needs_libc_formula?: false, needs_compiler_formula?: false) allow_any_instance_of(Pathname).to receive(:read).and_return <<~EOS tap 'x' tap 'y' cask '123' brew 'a' brew 'b' brew 'd2' brew 'homebrew/tap/f' brew 'homebrew/tap/g' brew 'homebrew/tap/h' brew 'homebrew/tap/i2' brew 'homebrew/tap/hasdependency' brew 'hasbuilddependency1' brew 'hasbuilddependency2' mas 'appstoreapp1', id: 1 vscode 'VsCodeExtension1' EOS %w[a b d2 homebrew/tap/f homebrew/tap/g homebrew/tap/h homebrew/tap/i2 homebrew/tap/hasdependency hasbuilddependency1 hasbuilddependency2].each do |full_name| tap_name, _, name = full_name.rpartition("/") tap = tap_name.present? ? Tap.fetch(tap_name) : nil f = formula(name, tap:) { url "#{name}-1.0" } stub_formula_loader f, full_name end end it "computes which casks to uninstall" do cask_123 = instance_double(Cask::Cask, to_s: "123", old_tokens: []) cask_456 = instance_double(Cask::Cask, to_s: "456", old_tokens: []) allow(Homebrew::Bundle::CaskDumper).to receive(:casks).and_return([cask_123, cask_456]) expect(described_class.casks_to_uninstall).to eql(%w[456]) end it "computes which formulae to uninstall" do dependencies_arrays_hash = { dependencies: [], build_dependencies: [] } formulae_hash = [ { name: "a2", full_name: "a2", aliases: ["a"], dependencies: ["d"] }, { name: "c", full_name: "c" }, { name: "d", full_name: "homebrew/tap/d", aliases: ["d2"] }, { name: "e", full_name: "homebrew/tap/e" }, { name: "f", full_name: "homebrew/tap/f" }, { name: "h", full_name: "other/tap/h" }, { name: "i", full_name: "homebrew/tap/i", aliases: ["i2"] }, { name: "hasdependency", full_name: "homebrew/tap/hasdependency", dependencies: ["isdependency"] }, { name: "isdependency", full_name: "homebrew/tap/isdependency" }, { name: "hasbuilddependency1", full_name: "hasbuilddependency1", poured_from_bottle?: true, build_dependencies: ["builddependency1"], }, { name: "hasbuilddependency2", full_name: "hasbuilddependency2", poured_from_bottle?: false, build_dependencies: ["builddependency2"], }, { name: "builddependency1", full_name: "builddependency1" }, { name: "builddependency2", full_name: "builddependency2" }, { name: "caskdependency", full_name: "homebrew/tap/caskdependency" }, ].map { |formula| dependencies_arrays_hash.merge(formula) } allow(Homebrew::Bundle::FormulaDumper).to receive(:formulae).and_return(formulae_hash) formulae_hash.each do |hash_formula| name = hash_formula[:name] full_name = hash_formula[:full_name] tap_name = full_name.rpartition("/").first.presence || "homebrew/core" tap = Tap.fetch(tap_name) f = formula(name, tap:) { url "#{name}-1.0" } stub_formula_loader f, full_name end allow(Homebrew::Bundle::CaskDumper).to receive(:formula_dependencies).and_return(%w[caskdependency]) expect(described_class.formulae_to_uninstall).to eql %w[ c homebrew/tap/e other/tap/h builddependency1 ] end it "computes which tap to untap" do allow(Homebrew::Bundle::TapDumper).to \ receive(:tap_names).and_return(%w[z homebrew/core homebrew/tap]) expect(described_class.taps_to_untap).to eql(%w[z]) end it "ignores unavailable formulae when computing which taps to keep" do allow(Formulary).to \ receive(:factory).and_raise(TapFormulaUnavailableError.new(Tap.fetch("homebrew/tap"), "foo")) allow(Homebrew::Bundle::TapDumper).to \ receive(:tap_names).and_return(%w[z homebrew/core homebrew/tap]) expect(described_class.taps_to_untap).to eql(%w[z homebrew/tap]) end it "ignores formulae with .keepme references when computing which formulae to uninstall" do name = full_name ="c" allow(Homebrew::Bundle::FormulaDumper).to receive(:formulae).and_return([{ name:, full_name: }]) f = formula(name) { url "#{name}-1.0" } stub_formula_loader f, name keg = instance_double(Keg) allow(keg).to receive(:keepme_refs).and_return(["/some/file"]) allow(f).to receive(:installed_kegs).and_return([keg]) expect(described_class.formulae_to_uninstall).to be_empty end it "computes which VSCode extensions to uninstall" do allow(Homebrew::Bundle::VscodeExtensionDumper).to receive(:extensions).and_return(%w[z]) expect(described_class.vscode_extensions_to_uninstall).to eql(%w[z]) end it "computes which VSCode extensions to uninstall irrespective of case of the extension name" do allow(Homebrew::Bundle::VscodeExtensionDumper).to receive(:extensions).and_return(%w[z vscodeextension1]) expect(described_class.vscode_extensions_to_uninstall).to eql(%w[z]) end it "computes which flatpaks to uninstall", :needs_linux do allow_any_instance_of(Pathname).to receive(:read).and_return <<~EOS flatpak 'org.gnome.Calculator' EOS allow(Homebrew::Bundle).to receive(:flatpak_installed?).and_return(true) allow(Homebrew::Bundle::FlatpakDumper).to receive(:packages).and_return(%w[org.gnome.Calculator org.mozilla.firefox]) expect(described_class.flatpaks_to_uninstall).to eql(%w[org.mozilla.firefox]) end end context "when there are no formulae to uninstall and no taps to untap" do before do described_class.reset! allow(described_class).to receive_messages(casks_to_uninstall: [], formulae_to_uninstall: [], taps_to_untap: [], vscode_extensions_to_uninstall: [], flatpaks_to_uninstall: []) end it "does nothing" do expect(Kernel).not_to receive(:system) expect(described_class).to receive(:system_output_no_stderr).and_return("") described_class.run(force: true) end end context "when there are casks to uninstall" do before do described_class.reset! allow(described_class).to receive_messages(casks_to_uninstall: %w[a b], formulae_to_uninstall: [], taps_to_untap: [], vscode_extensions_to_uninstall: [], flatpaks_to_uninstall: []) end it "uninstalls casks" do expect(Kernel).to receive(:system).with(HOMEBREW_BREW_FILE, "uninstall", "--cask", "--force", "a", "b") expect(described_class).to receive(:system_output_no_stderr).and_return("") expect { described_class.run(force: true) }.to output(/Uninstalled 2 casks/).to_stdout end it "does not uninstall casks if --formulae is disabled" do expect(Kernel).not_to receive(:system) expect(described_class).to receive(:system_output_no_stderr).and_return("") expect { described_class.run(force: true, casks: false) }.not_to output.to_stdout end end context "when there are casks to zap" do before do described_class.reset! allow(described_class).to receive_messages(casks_to_uninstall: %w[a b], formulae_to_uninstall: [], taps_to_untap: [], vscode_extensions_to_uninstall: [], flatpaks_to_uninstall: []) end it "uninstalls casks" do expect(Kernel).to receive(:system).with(HOMEBREW_BREW_FILE, "uninstall", "--cask", "--zap", "--force", "a", "b") expect(described_class).to receive(:system_output_no_stderr).and_return("") expect { described_class.run(force: true, zap: true) }.to output(/Uninstalled 2 casks/).to_stdout end it "does not uninstall casks if --casks is disabled" do expect(Kernel).not_to receive(:system) expect(described_class).to receive(:system_output_no_stderr).and_return("") expect { described_class.run(force: true, zap: true, casks: false) }.not_to output.to_stdout end end context "when there are formulae to uninstall" do before do described_class.reset! allow(described_class).to receive_messages(casks_to_uninstall: [], formulae_to_uninstall: %w[a b], taps_to_untap: [], vscode_extensions_to_uninstall: [], flatpaks_to_uninstall: []) allow(Homebrew::Bundle).to receive(:mark_as_installed_on_request!) allow_any_instance_of(Pathname).to receive(:read).and_return("") end it "uninstalls formulae" do expect(Kernel).to receive(:system).with(HOMEBREW_BREW_FILE, "uninstall", "--formula", "--force", "a", "b") expect(described_class).to receive(:system_output_no_stderr).and_return("") expect { described_class.run(force: true) }.to output(/Uninstalled 2 formulae/).to_stdout end it "does not uninstall formulae if --casks is disabled" do expect(Kernel).not_to receive(:system) expect(described_class).to receive(:system_output_no_stderr).and_return("") expect { described_class.run(force: true, formulae: false) }.not_to output.to_stdout end end context "when there are taps to untap" do before do described_class.reset! allow(described_class).to receive_messages(casks_to_uninstall: [], formulae_to_uninstall: [], taps_to_untap: %w[a b], vscode_extensions_to_uninstall: [], flatpaks_to_uninstall: []) end it "untaps taps" do expect(Kernel).to receive(:system).with(HOMEBREW_BREW_FILE, "untap", "a", "b") expect(described_class).to receive(:system_output_no_stderr).and_return("") described_class.run(force: true) end it "does not untap taps if --taps is disabled" do expect(Kernel).not_to receive(:system) expect(described_class).to receive(:system_output_no_stderr).and_return("") described_class.run(force: true, taps: false) end end context "when there are VSCode extensions to uninstall" do before do described_class.reset! allow(Homebrew::Bundle).to receive(:which_vscode).and_return(Pathname("code")) allow(described_class).to receive_messages(casks_to_uninstall: [], formulae_to_uninstall: [], taps_to_untap: [], vscode_extensions_to_uninstall: %w[GitHub.codespaces], flatpaks_to_uninstall: []) end it "uninstalls extensions" do expect(Kernel).to receive(:system).with("code", "--uninstall-extension", "GitHub.codespaces") expect(described_class).to receive(:system_output_no_stderr).and_return("") described_class.run(force: true) end it "does not uninstall extensions if --vscode is disabled" do expect(Kernel).not_to receive(:system) expect(described_class).to receive(:system_output_no_stderr).and_return("") described_class.run(force: true, vscode: false) end end context "when there are flatpaks to uninstall", :needs_linux do before do described_class.reset! allow(described_class).to receive_messages(casks_to_uninstall: [], formulae_to_uninstall: [], taps_to_untap: [], vscode_extensions_to_uninstall: [], flatpaks_to_uninstall: %w[org.gnome.Calculator]) end it "uninstalls flatpaks" do expect(Kernel).to receive(:system).with("flatpak", "uninstall", "-y", "--system", "org.gnome.Calculator") expect(described_class).to receive(:system_output_no_stderr).and_return("") expect { described_class.run(force: true) }.to output(/Uninstalled 1 flatpak/).to_stdout end it "does not uninstall flatpaks if --flatpak is disabled" do expect(Kernel).not_to receive(:system) expect(described_class).to receive(:system_output_no_stderr).and_return("") described_class.run(force: true, flatpak: false) end end context "when there are casks and formulae to uninstall and taps to untap but without passing `--force`" do before do described_class.reset! allow(described_class).to receive_messages(casks_to_uninstall: %w[a b], formulae_to_uninstall: %w[a b], taps_to_untap: %w[a b], vscode_extensions_to_uninstall: %w[a b], flatpaks_to_uninstall: %w[a b]) end it "lists casks, formulae and taps" do expect(Formatter).to receive(:columns).with(%w[a b]).exactly(5).times.and_return("a b") expect(Kernel).not_to receive(:system) expect(described_class).to receive(:system_output_no_stderr).and_return("") output_pattern = Regexp.new( "Would uninstall casks:.*Would uninstall formulae:.*Would untap:.*" \ "Would uninstall VSCode extensions:.*Would uninstall flatpaks:", Regexp::MULTILINE, ) expect do described_class.run end.to raise_error(SystemExit) .and output(output_pattern).to_stdout end end context "when there is brew cleanup output" do before do described_class.reset! allow(described_class).to receive_messages(casks_to_uninstall: [], formulae_to_uninstall: [], taps_to_untap: [], vscode_extensions_to_uninstall: [], flatpaks_to_uninstall: []) end define_method(:sane?) do expect(described_class).to receive(:system_output_no_stderr).and_return("cleaned") end context "with --force" do it "prints output" do sane? expect { described_class.run(force: true) }.to output(/cleaned/).to_stdout end end context "without --force" do it "prints output" do sane? expect { described_class.run }.to output(/cleaned/).to_stdout end end end describe "#system_output_no_stderr" do it "shells out" do expect(IO).to receive(:popen).and_return(StringIO.new("true")) described_class.system_output_no_stderr("true") end end context "when running with force" do before do described_class.reset! allow(described_class).to receive_messages( casks_to_uninstall: [], formulae_to_uninstall: %w[some_formula], taps_to_untap: [], vscode_extensions_to_uninstall: [], flatpaks_to_uninstall: [], ) allow(Kernel).to receive(:system) allow(described_class).to receive(:system_output_no_stderr).and_return("") allow_any_instance_of(Pathname).to receive(:read).and_return("") end it "marks Brewfile formulae as installed_on_request before uninstalling" do expect(Homebrew::Bundle).to receive(:mark_as_installed_on_request!) described_class.run(force: 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/bundle/commands/dump_spec.rb
Library/Homebrew/test/bundle/commands/dump_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/commands/dump" require "bundle/cask_dumper" require "bundle/formula_dumper" require "bundle/tap_dumper" require "bundle/vscode_extension_dumper" require "bundle/cargo_dumper" RSpec.describe Homebrew::Bundle::Commands::Dump do subject(:dump) do described_class.run(global:, file: nil, describe: false, force:, no_restart: false, taps: true, formulae: true, casks: true, mas: true, vscode: true, go: true, cargo: true, flatpak: false) end let(:force) { false } let(:global) { false } before do Homebrew::Bundle::CaskDumper.reset! Homebrew::Bundle::FormulaDumper.reset! Homebrew::Bundle::TapDumper.reset! Homebrew::Bundle::VscodeExtensionDumper.reset! allow(Homebrew::Bundle::CargoDumper).to receive(:dump).and_return("") allow(Formulary).to receive(:factory).and_call_original allow(Formulary).to receive(:factory).with("rust").and_return( instance_double(Formula, opt_bin: Pathname.new("/tmp/rust/bin")), ) end context "when files existed" do before do allow_any_instance_of(Pathname).to receive(:exist?).and_return(true) allow(Homebrew::Bundle).to receive(:cask_installed?).and_return(true) end it "raises error" do expect do dump end.to raise_error(RuntimeError) end it "exits before doing any work" do expect(Homebrew::Bundle::TapDumper).not_to receive(:dump) expect(Homebrew::Bundle::FormulaDumper).not_to receive(:dump) expect(Homebrew::Bundle::CaskDumper).not_to receive(:dump) expect do dump end.to raise_error(RuntimeError) end end context "when files existed and `--force` and `--global` are passed" do let(:force) { true } let(:global) { true } before do ENV["HOMEBREW_BUNDLE_FILE"] = "" allow_any_instance_of(Pathname).to receive(:exist?).and_return(true) allow(Homebrew::Bundle).to receive(:cask_installed?).and_return(true) allow(Cask::Caskroom).to receive(:casks).and_return([]) # don't try to load gcc/glibc allow(DevelopmentTools).to receive_messages(needs_libc_formula?: false, needs_compiler_formula?: false) stub_formula_loader formula("mas") { url "mas-1.0" } end it "doesn't raise error" do io = instance_double(File, write: true) expect_any_instance_of(Pathname).to receive(:open).with("w").and_yield(io) expect(io).to receive(:write) expect { dump }.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/bundle/commands/add_spec.rb
Library/Homebrew/test/bundle/commands/add_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/commands/add" require "cask/cask_loader" RSpec.describe Homebrew::Bundle::Commands::Add do subject(:add) do described_class.run(*args, type:, global:, file:) end before { FileUtils.touch file } after { FileUtils.rm_f file } let(:global) { false } context "when called with a valid formula" do let(:args) { ["hello"] } let(:type) { :brew } let(:file) { "/tmp/some_random_brewfile#{Random.rand(2 ** 16)}" } before do stub_formula_loader formula("hello") { url "hello-1.0" } end it "adds entries to the given Brewfile" do expect { add }.not_to raise_error expect(File.read(file)).to include("#{type} \"#{args.first}\"") end end context "when called with a valid cask" do let(:args) { ["alacritty"] } let(:type) { :cask } let(:file) { "/tmp/some_random_brewfile#{Random.rand(2 ** 16)}" } before do stub_cask_loader Cask::CaskLoader::FromContentLoader.new(+<<~RUBY).load(config: nil) cask "alacritty" do version "1.0" end RUBY end it "adds entries to the given Brewfile" do expect { add }.not_to raise_error expect(File.read(file)).to include("#{type} \"#{args.first}\"") 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/bundle/commands/exec_spec.rb
Library/Homebrew/test/bundle/commands/exec_spec.rb
# frozen_string_literal: true require "bundle" require "bundle/commands/exec" require "bundle/brewfile" require "bundle/brew_services" RSpec.describe Homebrew::Bundle::Commands::Exec do context "when a Brewfile is not found" do it "raises an error" do expect { described_class.run }.to raise_error(RuntimeError) end end context "when a Brewfile is found", :no_api do let(:brewfile_contents) { "brew 'openssl'" } before do allow_any_instance_of(Pathname).to receive(:read) .and_return(brewfile_contents) # don't try to load gcc/glibc allow(DevelopmentTools).to receive_messages(needs_libc_formula?: false, needs_compiler_formula?: false) stub_formula_loader formula("openssl") { url "openssl-1.0" } stub_formula_loader formula("pkgconf") { url "pkgconf-1.0" } ENV.extend(Superenv) allow(ENV).to receive(:setup_build_environment) end context "with valid command setup" do before do allow(described_class).to receive(:exec).and_return(nil) Homebrew::Bundle.reset! end it "does not raise an error" do expect { described_class.run("bundle", "install") }.not_to raise_error end it "does not raise an error when HOMEBREW_BUNDLE_EXEC_ALL_KEG_ONLY_DEPS is set" do ENV["HOMEBREW_BUNDLE_EXEC_ALL_KEG_ONLY_DEPS"] = "1" expect { described_class.run("bundle", "install") }.not_to raise_error end it "uses the formula version from the environment variable" do openssl_version = "1.1.1" ENV["PATH"] = "/opt/homebrew/opt/openssl/bin:/usr/bin:/bin" ENV["MANPATH"] = "/opt/homebrew/opt/openssl/man" ENV["HOMEBREW_BUNDLE_FORMULA_VERSION_OPENSSL"] = openssl_version allow(described_class).to receive(:which).and_return(Pathname("/usr/bin/bundle")) described_class.run("bundle", "install") expect(ENV.fetch("PATH")).to include("/Cellar/openssl/1.1.1/bin") end it "is able to run without bundle arguments" do allow(described_class).to receive(:exec).with("bundle", "install").and_return(nil) expect { described_class.run("bundle", "install") }.not_to raise_error end it "raises an exception if called without a command" do expect { described_class.run }.to raise_error(RuntimeError) end describe "--no-secrets" do around do |example| original_env = ENV.to_hash begin example.run ensure ENV.replace(original_env) end end it "removes sensitive environment variables when requested" do ENV["SECRET_TOKEN"] = "password" described_class.run("/usr/bin/true", subcommand: "exec", no_secrets: true) expect(ENV).not_to have_key("SECRET_TOKEN") end it "preserves non-sensitive environment variables when removing secrets" do ENV["NORMAL_VAR"] = "value" described_class.run("/usr/bin/true", subcommand: "exec", no_secrets: true) expect(ENV.fetch("NORMAL_VAR")).to eq("value") end end end context "with env command" do it "outputs the environment variables" do allow(OS).to receive(:linux?).and_return(true) expect { described_class.run("env", subcommand: "env") }.to \ output(/export PATH=".+:\${PATH:-}"/).to_stdout end end it "raises if called with a command that's not on the PATH" do allow(described_class).to receive_messages(exec: nil, which: nil) expect { described_class.run("bundle", "install") }.to raise_error(RuntimeError) end it "prepends the path of the requested command to PATH before running" do expect(described_class).to receive(:exec).with("bundle", "install").and_return(nil) expect(described_class).to receive(:which).twice.and_return(Pathname("/usr/local/bin/bundle")) allow(ENV).to receive(:prepend_path).with(any_args).and_call_original expect(ENV).to receive(:prepend_path).with("PATH", "/usr/local/bin").once.and_call_original described_class.run("bundle", "install") end describe "when running a command which exists but is not on the PATH" do let(:brewfile_contents) { "brew 'zlib'" } before do stub_formula_loader formula("zlib") { url "zlib-1.0" } end shared_examples "allows command execution" do |command| it "does not raise" do allow(described_class).to receive(:exec).with(command).and_return(nil) expect(described_class).not_to receive(:which) expect { described_class.run(command) }.not_to raise_error end end it_behaves_like "allows command execution", "./configure" it_behaves_like "allows command execution", "bin/install" it_behaves_like "allows command execution", "/Users/admin/Downloads/command" end describe "when the Brewfile contains rbenv" do let(:rbenv_root) { Pathname.new("/tmp/.rbenv") } let(:brewfile_contents) { "brew 'rbenv'" } before do stub_formula_loader formula("rbenv") { url "rbenv-1.0" } ENV["HOMEBREW_RBENV_ROOT"] = rbenv_root.to_s end it "prepends the path of the rbenv shims to PATH before running" do allow(described_class).to receive(:exec).with("/usr/bin/true").and_return(0) allow(ENV).to receive(:fetch).with(any_args).and_call_original allow(ENV).to receive(:prepend_path).with(any_args).once.and_call_original expect(ENV).to receive(:fetch).with("HOMEBREW_RBENV_ROOT", "#{Dir.home}/.rbenv").once.and_call_original expect(ENV).to receive(:prepend_path).with("PATH", rbenv_root/"shims").once.and_call_original described_class.run("/usr/bin/true") end end describe "--services" do let(:brewfile_contents) { "brew 'nginx'\nbrew 'redis'" } let(:nginx_formula) do instance_double( Formula, name: "nginx", any_version_installed?: true, any_installed_prefix: HOMEBREW_PREFIX/"opt/nginx", plist_name: "homebrew.mxcl.nginx", service_name: "nginx", versioned_formulae_names: [], conflicts: [instance_double(Formula::FormulaConflict, name: "httpd")], keg_only?: false, ) end let(:redis_formula) do instance_double( Formula, name: "redis", any_version_installed?: true, any_installed_prefix: HOMEBREW_PREFIX/"opt/redis", plist_name: "homebrew.mxcl.redis", service_name: "redis", versioned_formulae_names: ["redis@6.2"], conflicts: [], keg_only?: false, ) end let(:services_info_pre) do [ { "name" => "nginx", "running" => true, "loaded" => true }, { "name" => "httpd", "running" => true, "loaded" => true }, { "name" => "redis", "running" => false, "loaded" => false }, { "name" => "redis@6.2", "running" => true, "loaded" => true, "registered" => true }, ] end let(:services_info_post) do [ { "name" => "nginx", "running" => true, "loaded" => true }, { "name" => "httpd", "running" => false, "loaded" => false }, { "name" => "redis", "running" => true, "loaded" => true }, { "name" => "redis@6.2", "running" => false, "loaded" => false, "registered" => true }, ] end before do stub_formula_loader(nginx_formula, "nginx") stub_formula_loader(redis_formula, "redis") pkgconf = formula("pkgconf") { url "pkgconf-1.0" } stub_formula_loader(pkgconf) allow(pkgconf).to receive(:any_version_installed?).and_return(false) allow_any_instance_of(Pathname).to receive(:file?).and_return(true) allow_any_instance_of(Pathname).to receive(:realpath) { |path| path } allow(described_class).to receive(:exit!).and_return(nil) end shared_examples "handles service lifecycle correctly" do it "handles service lifecycle correctly" do # The order of operations is important. This unweildly looking test is so it tests that. # Return original service state expect(Utils).to receive(:safe_popen_read) .with(HOMEBREW_BREW_FILE, "services", "info", "--json", "nginx", "httpd", "redis", "redis@6.2") .and_return(services_info_pre.to_json) # Stop original nginx expect(Homebrew::Bundle::BrewServices).to receive(:stop) .with("nginx", keep: true).and_return(true).ordered # Stop nginx conflicts expect(Homebrew::Bundle::BrewServices).to receive(:stop) .with("httpd", keep: true).and_return(true).ordered # Start new nginx expect(Homebrew::Bundle::BrewServices).to receive(:run) .with("nginx", file: nginx_service_file).and_return(true).ordered # No need to stop original redis (not started) # Stop redis conflicts expect(Homebrew::Bundle::BrewServices).to receive(:stop) .with("redis@6.2", keep: true).and_return(true).ordered # Start new redis expect(Homebrew::Bundle::BrewServices).to receive(:run) .with("redis", file: redis_service_file).and_return(true).ordered # Run exec commands expect(Kernel).to receive(:system).with("/usr/bin/true").and_return(true).ordered # Return new service state expect(Utils).to receive(:safe_popen_read) .with(HOMEBREW_BREW_FILE, "services", "info", "--json", "nginx", "httpd", "redis", "redis@6.2") .and_return(services_info_post.to_json) # Stop new services expect(Homebrew::Bundle::BrewServices).to receive(:stop) .with("nginx", keep: true).and_return(true).ordered expect(Homebrew::Bundle::BrewServices).to receive(:stop) .with("redis", keep: true).and_return(true).ordered # Restart registered services we stopped due to conflicts (skip httpd as not registered) expect(Homebrew::Bundle::BrewServices).to receive(:run).with("redis@6.2").and_return(true).ordered described_class.run("/usr/bin/true", services: true) end end context "with launchctl" do before do allow(Homebrew::Services::System).to receive(:launchctl?).and_return(true) end let(:nginx_service_file) { nginx_formula.any_installed_prefix/"#{nginx_formula.plist_name}.plist" } let(:redis_service_file) { redis_formula.any_installed_prefix/"#{redis_formula.plist_name}.plist" } include_examples "handles service lifecycle correctly" end context "with systemd" do before do allow(Homebrew::Services::System).to receive(:launchctl?).and_return(false) end let(:nginx_service_file) { nginx_formula.any_installed_prefix/"#{nginx_formula.service_name}.service" } let(:redis_service_file) { redis_formula.any_installed_prefix/"#{redis_formula.service_name}.service" } include_examples "handles service lifecycle correctly" 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/rubocops/disable_comment_spec.rb
Library/Homebrew/test/rubocops/disable_comment_spec.rb
# frozen_string_literal: true require "rubocops/disable_comment" RSpec.describe RuboCop::Cop::DisableComment, :config do shared_examples "offense" do |source, correction, message| it "registers an offense and corrects" do expect_offense(<<~RUBY, source:, message:) #{source} ^{source} #{message} RUBY expect_correction(<<~RUBY) #{correction} RUBY end end it "registers an offense" do expect_offense(<<~RUBY) def something; end # rubocop:disable Naming/AccessorMethodName ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Add a clarifying comment to the RuboCop disable comment def get_decrypted_io; end RUBY end it "registers an offense if the comment is empty" do expect_offense(<<~RUBY) def something; end # # rubocop:disable Naming/AccessorMethodName ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Add a clarifying comment to the RuboCop disable comment def get_decrypted_io; end RUBY end it "doesn't register an offense" do expect_no_offenses(<<~RUBY) def something; end # This is a upstream name that we cannot change. # rubocop:disable Naming/AccessorMethodName def get_decrypted_io; end RUBY 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/rubocops/components_order_spec.rb
Library/Homebrew/test/rubocops/components_order_spec.rb
# frozen_string_literal: true require "rubocops/components_order" RSpec.describe RuboCop::Cop::FormulaAudit::ComponentsOrder do subject(:cop) { described_class.new } context "when auditing formula components order" do it "reports and corrects an offense when `uses_from_macos` precedes `depends_on`" do expect_offense(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" uses_from_macos "apple" depends_on "foo" ^^^^^^^^^^^^^^^^ FormulaAudit/ComponentsOrder: `depends_on` (line 6) should be put before `uses_from_macos` (line 5) end RUBY expect_correction(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" depends_on "foo" uses_from_macos "apple" end RUBY end it "reports and corrects an offense when `license` precedes `sha256`" do expect_offense(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" license "0BSD" sha256 "samplesha256" ^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ComponentsOrder: `sha256` (line 5) should be put before `license` (line 4) end RUBY expect_correction(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" sha256 "samplesha256" license "0BSD" end RUBY end it "reports and corrects an offense when `bottle` precedes `livecheck`" do expect_offense(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" bottle :unneeded livecheck do ^^^^^^^^^^^^ FormulaAudit/ComponentsOrder: `livecheck` (line 7) should be put before `bottle` (line 5) url "https://brew.sh/foo/versions/" regex(/href=.+?foo-(\d+(?:.\d+)+).t/) end end RUBY expect_correction(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" livecheck do url "https://brew.sh/foo/versions/" regex(/href=.+?foo-(\d+(?:.\d+)+).t/) end bottle :unneeded end RUBY end it "reports and corrects an offense when `url` precedes `homepage`" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" ^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ComponentsOrder: `homepage` (line 3) should be put before `url` (line 2) end RUBY expect_correction(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" end RUBY end it "reports and corrects an offense when `resource` precedes `depends_on`" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" resource "foo2" do url "https://brew.sh/foo-2.0.tgz" end depends_on "openssl" ^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ComponentsOrder: `depends_on` (line 8) should be put before `resource` (line 4) end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" depends_on "openssl" resource "foo2" do url "https://brew.sh/foo-2.0.tgz" end end RUBY end it "reports and corrects an offense when `test` precedes `plist`" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" test do expect(shell_output("./dogs")).to match("Dogs are terrific") end def plist ^^^^^^^^^ FormulaAudit/ComponentsOrder: `plist` (line 8) should be put before `test` (line 4) end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" def plist end test do expect(shell_output("./dogs")).to match("Dogs are terrific") end end RUBY end it "reports and corrects an offense when `install` precedes `depends_on`" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" def install end depends_on "openssl" ^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ComponentsOrder: `depends_on` (line 7) should be put before `install` (line 4) end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" depends_on "openssl" def install end end RUBY end it "reports and corrects an offense when `test` precedes `depends_on`" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" def install end def test end depends_on "openssl" ^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ComponentsOrder: `depends_on` (line 10) should be put before `install` (line 4) end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" depends_on "openssl" def install end def test end end RUBY end it "reports and corrects an offense when only one of many `depends_on` precedes `conflicts_with`" do expect_offense(<<~RUBY) class Foo < Formula depends_on "autoconf" => :build conflicts_with "visionmedia-watch" depends_on "automake" => :build ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ComponentsOrder: `depends_on` (line 4) should be put before `conflicts_with` (line 3) depends_on "libtool" => :build depends_on "pkgconf" => :build depends_on "gettext" end RUBY expect_correction(<<~RUBY) class Foo < Formula depends_on "autoconf" => :build depends_on "automake" => :build depends_on "libtool" => :build depends_on "pkgconf" => :build depends_on "gettext" conflicts_with "visionmedia-watch" end RUBY end it "reports and corrects an offense when the `on_macos` block precedes `uses_from_macos`" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" on_macos do depends_on "readline" end uses_from_macos "bar" ^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ComponentsOrder: `uses_from_macos` (line 6) should be put before `on_macos` (line 3) end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" uses_from_macos "bar" on_macos do depends_on "readline" end end RUBY end it "reports and corrects an offense when the `on_linux` block precedes `uses_from_macos`" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" on_linux do depends_on "readline" end uses_from_macos "bar" ^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ComponentsOrder: `uses_from_macos` (line 6) should be put before `on_linux` (line 3) end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" uses_from_macos "bar" on_linux do depends_on "readline" end end RUBY end it "reports and corrects an offense when the `on_linux` block precedes the `on_macos` block" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" on_linux do depends_on "vim" end on_macos do ^^^^^^^^^^^ FormulaAudit/ComponentsOrder: `on_macos` (line 6) should be put before `on_linux` (line 3) depends_on "readline" end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" on_macos do depends_on "readline" end on_linux do depends_on "vim" end end RUBY end end it "reports and corrects an offense when `depends_on` precedes `deprecate!`" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" depends_on "openssl" deprecate! because: "has been replaced by bar" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ComponentsOrder: `deprecate!` (line 6) should be put before `depends_on` (line 4) end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" deprecate! because: "has been replaced by bar" depends_on "openssl" end RUBY end context "when formula has no system-specific blocks" do it "reports no offenses" do expect_no_offenses(<<~RUBY) class Foo < Formula homepage "https://brew.sh" depends_on "pkgconf" => :build def install end end RUBY end end context "when formula has system-specific block(s)" do it "reports no offenses when `on_macos` and `on_linux` are used correctly" do expect_no_offenses(<<~RUBY) class Foo < Formula homepage "https://brew.sh" depends_on "pkgconf" => :build uses_from_macos "libxml2" on_macos do on_arm do depends_on "perl" end on_intel do depends_on "python" end resource "resource1" do url "https://brew.sh/resource1.tar.gz" sha256 "a2f5650770e1c87fb335af19a9b7eb73fc05ccf22144eb68db7d00cd2bcb0902" patch do url "https://raw.githubusercontent.com/Homebrew/formula-patches/0ae366e6/patch3.diff" sha256 "89fa3c95c329ec326e2e76493471a7a974c673792725059ef121e6f9efb05bf4" end end resource "resource2" do url "https://brew.sh/resource2.tar.gz" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end patch do url "https://raw.githubusercontent.com/Homebrew/formula-patches/0ae366e6/patch1.diff" sha256 "89fa3c95c329ec326e2e76493471a7a974c673792725059ef121e6f9efb05bf4" end patch do url "https://raw.githubusercontent.com/Homebrew/formula-patches/0ae366e6/patch2.diff" sha256 "89fa3c95c329ec326e2e76493471a7a974c673792725059ef121e6f9efb05bf4" end end on_linux do depends_on "readline" end def install end end RUBY end it "reports no offenses when `on_macos` is used correctly" do expect_no_offenses(<<~RUBY) class Foo < Formula homepage "https://brew.sh" on_macos do disable! because: :does_not_build depends_on "readline" end def install end end RUBY end it "reports no offenses when `on_linux` is used correctly" do expect_no_offenses(<<~RUBY) class Foo < Formula homepage "https://brew.sh" on_linux do deprecate! because: "it's deprecated" depends_on "readline" end def install end end RUBY end it "reports no offenses when `on_intel` is used correctly" do expect_no_offenses(<<~RUBY) class Foo < Formula homepage "https://brew.sh" on_intel do disable! because: :does_not_build depends_on "readline" end def install end end RUBY end it "reports no offenses when `on_arm` is used correctly" do expect_no_offenses(<<~RUBY) class Foo < Formula homepage "https://brew.sh" on_arm do deprecate! because: "it's deprecated" depends_on "readline" end def install end end RUBY end it "reports no offenses when `on_monterey` is used correctly" do expect_no_offenses(<<~RUBY) class Foo < Formula homepage "https://brew.sh" on_monterey do disable! because: :does_not_build depends_on "readline" end def install end end RUBY end it "reports no offenses when `on_monterey :or_older` is used correctly" do expect_no_offenses(<<~RUBY) class Foo < Formula homepage "https://brew.sh" on_monterey :or_older do deprecate! because: "it's deprecated" depends_on "readline" end def install end end RUBY end it "reports an offense when there are multiple `on_macos` blocks" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" on_macos do depends_on "readline" end on_macos do ^^^^^^^^^^^ FormulaAudit/ComponentsOrder: There can only be one `on_macos` block in a formula. depends_on "foo" end end RUBY end it "reports an offense when there are multiple `on_linux` blocks" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" on_linux do depends_on "readline" end on_linux do ^^^^^^^^^^^ FormulaAudit/ComponentsOrder: There can only be one `on_linux` block in a formula. depends_on "foo" end end RUBY end it "reports an offense when there are multiple `on_intel` blocks" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" on_intel do depends_on "readline" end on_intel do ^^^^^^^^^^^ FormulaAudit/ComponentsOrder: There can only be one `on_intel` block in a formula. depends_on "foo" end end RUBY end it "reports an offense when there are multiple `on_arm` blocks" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" on_arm do depends_on "readline" end on_arm do ^^^^^^^^^ FormulaAudit/ComponentsOrder: There can only be one `on_arm` block in a formula. depends_on "foo" end end RUBY end it "reports an offense when there are multiple `on_monterey` blocks" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" on_monterey do depends_on "readline" end on_monterey do ^^^^^^^^^^^^^^ FormulaAudit/ComponentsOrder: There can only be one `on_monterey` block in a formula. depends_on "foo" end end RUBY end it "reports an offense when there are multiple `on_monterey` blocks with parameters" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" on_monterey do depends_on "readline" end on_monterey :or_older do ^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ComponentsOrder: There can only be one `on_monterey` block in a formula. depends_on "foo" end end RUBY end it "reports an offense when the `on_macos` block contains nodes other than `depends_on`, `patch` or `resource`" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" on_macos do depends_on "readline" uses_from_macos "ncurses" ^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ComponentsOrder: `on_macos` cannot include `uses_from_macos`. [...] end end RUBY end it "reports an offense when the `on_linux` block contains nodes other than `depends_on`, `patch` or `resource`" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" on_linux do depends_on "readline" uses_from_macos "ncurses" ^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ComponentsOrder: `on_linux` cannot include `uses_from_macos`. [...] end end RUBY end it "reports an offense when the `on_intel` block contains nodes other than `depends_on`, `patch` or `resource`" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" on_intel do depends_on "readline" uses_from_macos "ncurses" ^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ComponentsOrder: `on_intel` cannot include `uses_from_macos`. [...] end end RUBY end it "reports an offense when the `on_arm` block contains nodes other than `depends_on`, `patch` or `resource`" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" on_arm do depends_on "readline" uses_from_macos "ncurses" ^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ComponentsOrder: `on_arm` cannot include `uses_from_macos`. [...] end end RUBY end it "reports an offense when the `on_monterey` block contains nodes other than " \ "`depends_on`, `patch` or `resource`" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" on_monterey do depends_on "readline" uses_from_macos "ncurses" ^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ComponentsOrder: `on_monterey` cannot include `uses_from_macos`. [...] end end RUBY end it "reports an offense when the `on_monterey :or_older` block contains nodes other than " \ "`depends_on`, `patch` or `resource`" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" on_monterey :or_older do depends_on "readline" uses_from_macos "ncurses" ^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ComponentsOrder: `on_monterey` cannot include `uses_from_macos`. [...] end end RUBY end it "reports an offense when a single `patch` block is inside the `on_arm` block" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" on_arm do ^^^^^^^^^ FormulaAudit/ComponentsOrder: Nest `on_arm` blocks inside `patch` blocks when there is only one inner block. patch do url "https://brew.sh/patch1.tar.gz" sha256 "2c39089f64d9d4c3e632f120894b36b68dcc8ae8c6f5130c0c2e6f5bb7aebf2f" end end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" patch do on_arm do url "https://brew.sh/patch1.tar.gz" sha256 "2c39089f64d9d4c3e632f120894b36b68dcc8ae8c6f5130c0c2e6f5bb7aebf2f" end end end RUBY end it "reports an offense when a single `resource` block is inside the `on_linux` block" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" on_linux do ^^^^^^^^^^^ FormulaAudit/ComponentsOrder: Nest `on_linux` blocks inside `resource` blocks when there is only one inner block. resource do url "https://brew.sh/resource1.tar.gz" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" resource do on_linux do url "https://brew.sh/resource1.tar.gz" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end end end RUBY end it "reports an offense when a single `patch` block is inside the `on_monterey :or_newer` block" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" on_monterey :or_newer do ^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ComponentsOrder: Nest `on_monterey` blocks inside `patch` blocks when there is only one inner block. patch do url "https://brew.sh/patch1.tar.gz" sha256 "2c39089f64d9d4c3e632f120894b36b68dcc8ae8c6f5130c0c2e6f5bb7aebf2f" end end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" patch do on_monterey :or_newer do url "https://brew.sh/patch1.tar.gz" sha256 "2c39089f64d9d4c3e632f120894b36b68dcc8ae8c6f5130c0c2e6f5bb7aebf2f" end end end RUBY end it "reports an offense when a single `resource` block is inside the `on_system` block" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" on_system :linux, macos: :monterey_or_older do ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ComponentsOrder: Nest `on_system` blocks inside `resource` blocks when there is only one inner block. resource do url "https://brew.sh/resource1.tar.gz" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" resource do on_system :linux, macos: :monterey_or_older do url "https://brew.sh/resource1.tar.gz" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end end end RUBY end it "reports no offenses when a single `on_arm` block is inside the `on_macos` block" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" on_macos do on_arm do resource do url "https://brew.sh/resource1.tar.gz" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end end end end RUBY end context "when in a head block" do it "reports an offense if stanzas inside `head` blocks are out of order" do expect_offense(<<~RUBY) class Foo < Formula homepage "https://brew.sh" head do depends_on "bar" url "https://github.com/foo/foo.git", branch: "main" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ComponentsOrder: `url` (line 6) should be put before `depends_on` (line 5) end end RUBY end end context "when in a resource block" do it "reports an offense if stanzas inside `resource` blocks are out of order" do expect_offense(<<~RUBY) class Foo < Formula homepage "https://brew.sh" resource do sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" url "https://brew.sh/resource1.tar.gz" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ComponentsOrder: `url` (line 6) should be put before `sha256` (line 5) end end RUBY end it "reports no offenses for a valid `on_macos` and `on_linux` block" do expect_no_offenses(<<~RUBY) class Foo < Formula homepage "https://brew.sh" resource do on_macos do url "https://brew.sh/resource1.tar.gz" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end on_linux do url "https://brew.sh/resource2.tar.gz" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end end end RUBY end it "reports no offenses for a valid `on_arm` and `on_intel` block (with `version`)" do expect_no_offenses(<<~RUBY) class Foo < Formula homepage "https://brew.sh" resource do on_arm do url "https://brew.sh/resource1.tar.gz" version "1.2.3" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end on_intel do url "https://brew.sh/resource2.tar.gz" version "1.2.3" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end end end RUBY end it "reports an offense if there are two `on_macos` blocks" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" resource do ^^^^^^^^^^^ FormulaAudit/ComponentsOrder: There can only be one `on_macos` block in a resource block. on_macos do url "https://brew.sh/resource1.tar.gz" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end on_macos do url "https://brew.sh/resource2.tar.gz" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end end end RUBY end it "reports an offense if there are two `on_linux` blocks" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" resource do ^^^^^^^^^^^ FormulaAudit/ComponentsOrder: There can only be one `on_linux` block in a resource block. on_linux do url "https://brew.sh/resource1.tar.gz" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end on_linux do url "https://brew.sh/resource2.tar.gz" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end end end RUBY end it "reports an offense if there are two `on_intel` blocks" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" resource do ^^^^^^^^^^^ FormulaAudit/ComponentsOrder: There can only be one `on_intel` block in a resource block. on_intel do url "https://brew.sh/resource1.tar.gz" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end on_intel do url "https://brew.sh/resource2.tar.gz" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end end end RUBY end it "reports an offense if there are two `on_arm` blocks" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" resource do ^^^^^^^^^^^ FormulaAudit/ComponentsOrder: There can only be one `on_arm` block in a resource block. on_arm do url "https://brew.sh/resource1.tar.gz" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end on_arm do url "https://brew.sh/resource2.tar.gz" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end end end RUBY end it "reports an offense if there are two `on_monterey` blocks" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" resource do ^^^^^^^^^^^ FormulaAudit/ComponentsOrder: There can only be one `on_monterey` block in a resource block. on_monterey do url "https://brew.sh/resource1.tar.gz" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end on_monterey :or_older do url "https://brew.sh/resource2.tar.gz" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end end end RUBY end it "reports no offenses if there is an `on_macos` block but no `on_linux` block" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" resource do on_macos do url "https://brew.sh/resource1.tar.gz" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end end end RUBY end it "reports no offenses if there is an `on_linux` block but no `on_macos` block" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" resource do on_linux do url "https://brew.sh/resource1.tar.gz" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end end end RUBY end it "reports no offenses if there is an `on_intel` block but no `on_arm` block" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" resource do on_intel do url "https://brew.sh/resource1.tar.gz" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end end end RUBY end it "reports no offenses if there is an `on_arm` block but no `on_intel` block" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" resource do on_arm do url "https://brew.sh/resource1.tar.gz" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end end end RUBY end it "reports an offense if the content of an `on_macos` block is improperly formatted" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" resource do on_macos do ^^^^^^^^^^^ FormulaAudit/ComponentsOrder: `on_macos` blocks within `resource` blocks must contain at least `url` and `sha256` and at most `url`, `mirror`, `version` and `sha256` (in order). sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" url "https://brew.sh/resource2.tar.gz" end on_linux do url "https://brew.sh/resource2.tar.gz" sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35" end end end RUBY end it "reports no offenses if the content of an `on_macos` block in a resource contains a mirror" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" resource do on_macos do
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
true
Homebrew/brew
https://github.com/Homebrew/brew/blob/fe0a384e3a04605192726c149570fbe33a8996b0/Library/Homebrew/test/rubocops/patches_spec.rb
Library/Homebrew/test/rubocops/patches_spec.rb
# frozen_string_literal: true require "rubocops/patches" RSpec.describe RuboCop::Cop::FormulaAudit::Patches do subject(:cop) { described_class.new } def expect_offense_hash(message:, severity:, line:, column:, source:) [{ message:, severity:, line:, column:, source: }] end context "when auditing legacy patches" do it "reports no offenses if there is no legacy patch" do expect_no_offenses(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' end RUBY end it "reports an offense if `def patches` is present" do expect_offense(<<~RUBY) class Foo < Formula homepage "ftp://brew.sh/foo" url "https://brew.sh/foo-1.0.tgz" def patches ^^^^^^^^^^^ FormulaAudit/Patches: Use the `patch` DSL instead of defining a `patches` method DATA end end RUBY end it "reports an offense for various patch URLs" do patch_urls = [ "https://raw.github.com/mogaal/sendemail", "https://mirrors.ustc.edu.cn/macports/trunk/", "https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch", "https://github.com/dlang/dub/commit/2c916b1a7999a050ac4970c3415ff8f91cd487aa.patch", "https://bitbucket.org/multicoreware/x265_git/commits/b354c009a60bcd6d7fc04014e200a1ee9c45c167/raw", ] patch_urls.each do |patch_url| source = <<~EOS class Foo < Formula homepage "ftp://brew.sh/foo" url "https://brew.sh/foo-1.0.tgz" def patches "#{patch_url}" end end EOS expected_offense = if patch_url.include?("/raw.github.com/") expect_offense_hash(message: <<~EOS.chomp, severity: :convention, line: 5, column: 4, source:) FormulaAudit/Patches: GitHub/Gist patches should specify a revision: #{patch_url} EOS elsif patch_url.include?("macports/trunk") expect_offense_hash(message: <<~EOS.chomp, severity: :convention, line: 5, column: 4, source:) FormulaAudit/Patches: MacPorts patches should specify a revision instead of trunk: #{patch_url} EOS # GitHub patch diff regexps can't be any shorter. # rubocop:disable Layout/LineLength elsif patch_url.match?(%r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)}) # rubocop:enable Layout/LineLength expect_offense_hash(message: <<~EOS.chomp, severity: :convention, line: 5, column: 4, source:) FormulaAudit/Patches: Use a commit hash URL rather than patch-diff: #{patch_url} EOS elsif patch_url.match?(%r{https?://github\.com/.+/.+/(?:commit|pull)/[a-fA-F0-9]*.(?:patch|diff)}) expect_offense_hash(message: <<~EOS.chomp, severity: :convention, line: 5, column: 4, source:) FormulaAudit/Patches: GitHub patches should use the full_index parameter: #{patch_url}?full_index=1 EOS elsif patch_url.start_with?("https://bitbucket.org/") commit = "b354c009a60bcd6d7fc04014e200a1ee9c45c167" fixed_url = "https://api.bitbucket.org/2.0/repositories/multicoreware/x265_git/diff/#{commit}" expect_offense_hash(message: <<~EOS.chomp, severity: :convention, line: 5, column: 4, source:) FormulaAudit/Patches: Bitbucket patches should use the API URL: #{fixed_url} EOS end expected_offense.zip([inspect_source(source).last]).each do |expected, actual| expect(actual.message).to eq(expected[:message]) expect(actual.severity).to eq(expected[:severity]) expect(actual.line).to eq(expected[:line]) expect(actual.column).to eq(expected[:column]) end end end it "reports an offense with nested `def patches`" do source = <<~RUBY class Foo < Formula homepage "ftp://brew.sh/foo" url "https://brew.sh/foo-1.0.tgz" def patches files = %w[patch-domain_resolver.c patch-colormask.c patch-trafshow.c patch-trafshow.1 patch-configure] { :p0 => files.collect{|p| "http://trac.macports.org/export/68507/trunk/dports/net/trafshow/files/\#{p}"} } end end RUBY expected_offenses = [ { message: "FormulaAudit/Patches: Use the `patch` DSL instead of defining a `patches` method", severity: :convention, line: 4, column: 2, source:, }, { message: "FormulaAudit/Patches: Patches from MacPorts Trac should be https://, not http: " \ "http://trac.macports.org/export/68507/trunk/dports/net/trafshow/files/", severity: :convention, line: 8, column: 25, source:, } ] expected_offenses.zip(inspect_source(source)).each do |expected, actual| expect(actual.message).to eq(expected[:message]) expect(actual.severity).to eq(expected[:severity]) expect(actual.line).to eq(expected[:line]) expect(actual.column).to eq(expected[:column]) end end end context "when auditing inline patches" do it "reports no offenses for valid inline patches" do expect_no_offenses(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' patch :DATA end __END__ patch content here RUBY end it "reports no offenses for valid nested inline patches" do expect_no_offenses(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' stable do patch :DATA end end __END__ patch content here RUBY end it "reports an offense when DATA is found with no __END__" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' patch :DATA ^^^^^^^^^^^ FormulaAudit/Patches: Patch is missing `__END__` end RUBY end it "reports an offense when __END__ is found with no DATA" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' end __END__ ^^^^^^^ FormulaAudit/Patches: Patch is missing `patch :DATA` patch content here RUBY end end context "when auditing external patches" do it "reports an offense for various patch URLs" do patch_urls = [ "https://raw.github.com/mogaal/sendemail", "https://mirrors.ustc.edu.cn/macports/trunk/", "https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch", "https://github.com/uber/h3/pull/362.patch?full_index=1", "https://gitlab.gnome.org/GNOME/gitg/-/merge_requests/142.diff", ] patch_urls.each do |patch_url| source = <<~RUBY class Foo < Formula homepage "ftp://brew.sh/foo" url "https://brew.sh/foo-1.0.tgz" patch do url "#{patch_url}" sha256 "63376b8fdd6613a91976106d9376069274191860cd58f039b29ff16de1925621" end end RUBY expected_offense = if patch_url.include?("/raw.github.com/") expect_offense_hash(message: <<~EOS.chomp, severity: :convention, line: 5, column: 8, source:) FormulaAudit/Patches: GitHub/Gist patches should specify a revision: #{patch_url} EOS elsif patch_url.include?("macports/trunk") expect_offense_hash(message: <<~EOS.chomp, severity: :convention, line: 5, column: 8, source:) FormulaAudit/Patches: MacPorts patches should specify a revision instead of trunk: #{patch_url} EOS elsif patch_url.match?(%r{https://github.com/[^/]*/[^/]*/pull}) expect_offense_hash(message: <<~EOS.chomp, severity: :convention, line: 5, column: 8, source:) FormulaAudit/Patches: Use a commit hash URL rather than an unstable pull request URL: #{patch_url} EOS elsif patch_url.match?(%r{.*gitlab.*/merge_request.*}) expect_offense_hash(message: <<~EOS.chomp, severity: :convention, line: 5, column: 8, source:) FormulaAudit/Patches: Use a commit hash URL rather than an unstable merge request URL: #{patch_url} EOS # GitHub patch diff regexps can't be any shorter. # rubocop:disable Layout/LineLength elsif patch_url.match?(%r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)}) # rubocop:enable Layout/LineLength expect_offense_hash(message: <<~EOS.chomp, severity: :convention, line: 5, column: 8, source:) FormulaAudit/Patches: Use a commit hash URL rather than patch-diff: #{patch_url} EOS end expected_offense.zip([inspect_source(source).last]).each do |expected, actual| expect(actual.message).to eq(expected[:message]) expect(actual.severity).to eq(expected[:severity]) expect(actual.line).to eq(expected[:line]) expect(actual.column).to eq(expected[:column]) end end end end context "when auditing external patches with corrector" do it "corrects Bitbucket patch URLs to use API format" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" patch do url "https://bitbucket.org/multicoreware/x265_git/commits/b354c009a60bcd6d7fc04014e200a1ee9c45c167/raw" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Patches: Bitbucket patches should use the API URL: https://api.bitbucket.org/2.0/repositories/multicoreware/x265_git/diff/b354c009a60bcd6d7fc04014e200a1ee9c45c167 sha256 "63376b8fdd6613a91976106d9376069274191860cd58f039b29ff16de1925621" end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" patch do url "https://api.bitbucket.org/2.0/repositories/multicoreware/x265_git/diff/b354c009a60bcd6d7fc04014e200a1ee9c45c167" sha256 "" end end RUBY end it "corrects HTTP MacPorts Trac URLs to HTTPS" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" patch do url "http://trac.macports.org/export/102865/trunk/dports/mail/uudeview/files/inews.c.patch" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Patches: Patches from MacPorts Trac should be https://, not http: http://trac.macports.org/export/102865/trunk/dports/mail/uudeview/files/inews.c.patch sha256 "63376b8fdd6613a91976106d9376069274191860cd58f039b29ff16de1925621" end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" patch do url "https://trac.macports.org/export/102865/trunk/dports/mail/uudeview/files/inews.c.patch" sha256 "63376b8fdd6613a91976106d9376069274191860cd58f039b29ff16de1925621" end end RUBY end it "corrects HTTP Debian bug URLs to HTTPS" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" patch do url "http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=patch-libunac1.txt;att=1;bug=623340" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Patches: Patches from Debian should be https://, not http: http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=patch-libunac1.txt;att=1;bug=623340 sha256 "63376b8fdd6613a91976106d9376069274191860cd58f039b29ff16de1925621" end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" patch do url "https://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=patch-libunac1.txt;att=1;bug=623340" sha256 "63376b8fdd6613a91976106d9376069274191860cd58f039b29ff16de1925621" end end RUBY end it "corrects GitHub commit URLs from .diff to .patch" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" patch do url "https://github.com/michaeldv/pit/commit/f64978d.diff" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Patches: GitHub patches should end with .patch, not .diff: https://github.com/michaeldv/pit/commit/f64978d.diff sha256 "63376b8fdd6613a91976106d9376069274191860cd58f039b29ff16de1925621" end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" patch do url "https://github.com/michaeldv/pit/commit/f64978d.patch?full_index=1" sha256 "" end end RUBY end it "corrects GitLab commit URLs from .patch to .diff" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" patch do url "https://gitlab.com/inkscape/lib2geom/-/commit/0b8b4c26b4a.patch" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Patches: GitLab patches should end with .diff, not .patch: https://gitlab.com/inkscape/lib2geom/-/commit/0b8b4c26b4a.patch sha256 "63376b8fdd6613a91976106d9376069274191860cd58f039b29ff16de1925621" end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" patch do url "https://gitlab.com/inkscape/lib2geom/-/commit/0b8b4c26b4a.diff" sha256 "" end end RUBY end it "corrects GitHub patch URLs to add full_index parameter" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" patch do url "https://github.com/foo/bar/commit/abc123.patch" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Patches: GitHub patches should use the full_index parameter: https://github.com/foo/bar/commit/abc123.patch?full_index=1 sha256 "63376b8fdd6613a91976106d9376069274191860cd58f039b29ff16de1925621" end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" patch do url "https://github.com/foo/bar/commit/abc123.patch?full_index=1" sha256 "" end end RUBY end it "corrects GitHub URLs with 'diff' in the path" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" patch do url "https://github.com/diff-tool/diff-utils/commit/abc123.diff" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Patches: GitHub patches should end with .patch, not .diff: https://github.com/diff-tool/diff-utils/commit/abc123.diff sha256 "63376b8fdd6613a91976106d9376069274191860cd58f039b29ff16de1925621" end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" patch do url "https://github.com/diff-tool/diff-utils/commit/abc123.patch?full_index=1" sha256 "" end end RUBY end it "corrects GitLab URLs with 'patch' in the path" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" patch do url "https://gitlab.com/patch-tool/patch-utils/-/commit/abc123.patch" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Patches: GitLab patches should end with .diff, not .patch: https://gitlab.com/patch-tool/patch-utils/-/commit/abc123.patch sha256 "63376b8fdd6613a91976106d9376069274191860cd58f039b29ff16de1925621" end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" patch do url "https://gitlab.com/patch-tool/patch-utils/-/commit/abc123.diff" sha256 "" end end RUBY end it "corrects GitHub URLs without sha256 field (e.g. with on_linux block)" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" patch :p2 do on_linux do url "https://github.com/foo/bar/commit/abc123.diff" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Patches: GitHub patches should end with .patch, not .diff: https://github.com/foo/bar/commit/abc123.diff directory "gl" end end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" patch :p2 do on_linux do url "https://github.com/foo/bar/commit/abc123.patch?full_index=1" directory "gl" end end end RUBY 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/rubocops/version_spec.rb
Library/Homebrew/test/rubocops/version_spec.rb
# frozen_string_literal: true require "rubocops/version" RSpec.describe RuboCop::Cop::FormulaAudit::Version do subject(:cop) { described_class.new } context "when auditing version" do it "reports an offense if `version` is an empty string" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' version "" ^^^^^^^^^^ FormulaAudit/Version: Version is set to an empty string end RUBY end it "reports an offense if `version` has a leading 'v'" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' version "v1.0" ^^^^^^^^^^^^^^ FormulaAudit/Version: Version v1.0 should not have a leading 'v' end RUBY end it "reports an offense if `version` ends with an underline and a number" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' version "1_0" ^^^^^^^^^^^^^ FormulaAudit/Version: Version 1_0 should not end with an underline and a number end RUBY 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/rubocops/desc_spec.rb
Library/Homebrew/test/rubocops/desc_spec.rb
# frozen_string_literal: true require "rubocops/desc" RSpec.describe RuboCop::Cop::FormulaAudit::Desc do subject(:cop) { described_class.new } context "when auditing formula `desc` methods" do it "reports an offense when there is no `desc`" do expect_offense(<<~RUBY) class Foo < Formula ^^^^^^^^^^^^^^^^^^^ FormulaAudit/Desc: Formula should have a `desc` (description). url 'https://brew.sh/foo-1.0.tgz' end RUBY end it "reports an offense when `desc` is an empty string" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' desc '' ^^^^^^^ FormulaAudit/Desc: The `desc` (description) should not be an empty string. end RUBY end it "reports an offense when `desc` is too long" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' desc 'Bar#{"bar" * 29}' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Desc: Description is too long. It should be less than 80 characters. The current length is 90. end RUBY end it "reports an offense when `desc` is a multiline string" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' desc 'Bar#{"bar" * 9}'\ '#{"foo" * 21}' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Desc: Description is too long. It should be less than 80 characters. The current length is 93. end RUBY end end context "when auditing formula description texts" do it "reports an offense when the description starts with a leading space" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' desc ' Description with a leading space' ^ FormulaAudit/Desc: Description shouldn't have leading spaces. end RUBY end it "reports an offense when the description ends with a trailing space" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' desc 'Description with a trailing space ' ^ FormulaAudit/Desc: Description shouldn't have trailing spaces. end RUBY end it "reports an offense when \"command-line\" is incorrectly spelled in the description" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' desc 'command line' ^ FormulaAudit/Desc: Description should start with a capital letter. ^^^^^^^^^^^^ FormulaAudit/Desc: Description should use "command-line" instead of "command line". end RUBY end it "reports an offense when an article is used in the description" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' desc 'An aardvark' ^^ FormulaAudit/Desc: Description shouldn't start with an article. end RUBY expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' desc 'The aardvark' ^^^ FormulaAudit/Desc: Description shouldn't start with an article. end RUBY end it "reports an offense when the description starts with a lowercase letter" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' desc 'bar' ^ FormulaAudit/Desc: Description should start with a capital letter. end RUBY end it "reports an offense when the description starts with the formula name" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' desc 'Foo is a foobar' ^^^ FormulaAudit/Desc: Description shouldn't start with the formula name. end RUBY end it "report and corrects an offense when the description ends with a full stop" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' desc 'Description with a full stop at the end.' ^ FormulaAudit/Desc: Description shouldn't end with a full stop. end RUBY expect_correction(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' desc 'Description with a full stop at the end' end RUBY end it "reports and corrects an offense when the description contains Unicode So characters" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' desc 'Description with a 🍺 symbol' ^ FormulaAudit/Desc: Description shouldn't contain Unicode emojis or symbols. end RUBY expect_correction(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' desc 'Description with a symbol' end RUBY end it "does not report an offense when the description ends with 'etc.'" do expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' desc 'Description of a thing and some more things and some more etc.' end RUBY end it "reports and corrects all rules for description text" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' desc ' an bar: commandline foo ' ^ FormulaAudit/Desc: Description shouldn't have trailing spaces. ^^^^^^^^^^^ FormulaAudit/Desc: Description should use "command-line" instead of "commandline". ^ FormulaAudit/Desc: Description shouldn't have leading spaces. end RUBY expect_correction(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' desc 'Bar: command-line' end RUBY 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/rubocops/urls_spec.rb
Library/Homebrew/test/rubocops/urls_spec.rb
# frozen_string_literal: true require "rubocops/urls" RSpec.describe RuboCop::Cop::FormulaAudit::Urls do subject(:cop) { described_class.new } let(:offense_list) do [{ "url" => "https://ftp.gnu.org/lightning/lightning-2.1.0.tar.gz", "msg" => "https://ftp.gnu.org/lightning/lightning-2.1.0.tar.gz should be: " \ "https://ftpmirror.gnu.org/gnu/lightning/lightning-2.1.0.tar.gz", "col" => 2, }, { "url" => "https://fossies.org/linux/privat/monit-5.23.0.tar.gz", "msg" => "Please don't use \"fossies.org\" in the `url` (using as a mirror is fine)", "col" => 2, }, { "url" => "http://tools.ietf.org/tools/rfcmarkup/rfcmarkup-1.119.tgz", "msg" => "Please use https:// for http://tools.ietf.org/tools/rfcmarkup/rfcmarkup-1.119.tgz", "col" => 2, }, { "url" => "https://apache.org/dyn/closer.cgi?path=/apr/apr-1.7.0.tar.bz2", "msg" => "https://apache.org/dyn/closer.cgi?path=/apr/apr-1.7.0.tar.bz2 should be: " \ "https://www.apache.org/dyn/closer.lua?path=apr/apr-1.7.0.tar.bz2", "col" => 2, }, { "url" => "http://search.mcpan.org/CPAN/authors/id/Z/ZE/ZEFRAM/Perl4-CoreLibs-0.003.tar.gz", "msg" => "http://search.mcpan.org/CPAN/authors/id/Z/ZE/ZEFRAM/Perl4-CoreLibs-0.003.tar.gz should be: " \ "https://cpan.metacpan.org/authors/id/Z/ZE/ZEFRAM/Perl4-CoreLibs-0.003.tar.gz", "col" => 2, }, { "url" => "http://ftp.gnome.org/pub/GNOME/binaries/mac/banshee/banshee-2.macosx.intel.dmg", "msg" => "http://ftp.gnome.org/pub/GNOME/binaries/mac/banshee/banshee-2.macosx.intel.dmg should be: " \ "https://download.gnome.org/binaries/mac/banshee/banshee-2.macosx.intel.dmg", "col" => 2, }, { "url" => "git://anonscm.debian.org/users/foo/foostrap.git", "msg" => "git://anonscm.debian.org/users/foo/foostrap.git should be: " \ "https://anonscm.debian.org/git/users/foo/foostrap.git", "col" => 2, }, { "url" => "ftp://ftp.mirrorservice.org/foo-1.tar.gz", "msg" => "Please use https:// for ftp://ftp.mirrorservice.org/foo-1.tar.gz", "col" => 2, }, { "url" => "ftp://ftp.cpan.org/pub/CPAN/foo-1.tar.gz", "msg" => "ftp://ftp.cpan.org/pub/CPAN/foo-1.tar.gz should be: http://search.cpan.org/CPAN/foo-1.tar.gz", "col" => 2, }, { "url" => "http://sourceforge.net/projects/something/files/Something-1.2.3.dmg", "msg" => "Use \"https://downloads.sourceforge.net\" to get geolocation (`url` is " \ "http://sourceforge.net/projects/something/files/Something-1.2.3.dmg).", "col" => 2, }, { "url" => "https://downloads.sourceforge.net/project/foo/download", "msg" => "Don't use \"/download\" in SourceForge URLs (`url` is " \ "https://downloads.sourceforge.net/project/foo/download).", "col" => 2, }, { "url" => "https://sourceforge.net/project/foo", "msg" => "Use \"https://downloads.sourceforge.net\" to get geolocation (`url` is " \ "https://sourceforge.net/project/foo).", "col" => 2, }, { "url" => "http://prdownloads.sourceforge.net/foo/foo-1.tar.gz", "msg" => "Don't use \"prdownloads\" in SourceForge URLs (`url` is " \ "http://prdownloads.sourceforge.net/foo/foo-1.tar.gz).", "col" => 2, }, { "url" => "http://foo.dl.sourceforge.net/sourceforge/foozip/foozip_1.0.tar.bz2", "msg" => "Don't use specific \"dl\" mirrors in SourceForge URLs (`url` is " \ "http://foo.dl.sourceforge.net/sourceforge/foozip/foozip_1.0.tar.bz2).", "col" => 2, }, { "url" => "http://downloads.sourceforge.net/project/foo/foo/2/foo-2.zip", "msg" => "Please use https:// for http://downloads.sourceforge.net/project/foo/foo/2/foo-2.zip", "col" => 2, }, { "url" => "http://http.debian.net/debian/dists/foo/", "msg" => <<~EOS, Please use a secure mirror for Debian URLs. We recommend: https://deb.debian.org/debian/dists/foo/ EOS "col" => 2, }, { "url" => "https://mirrors.kernel.org/debian/pool/main/n/nc6/foo.tar.gz", "msg" => "Please use " \ "https://deb.debian.org/debian/ for " \ "https://mirrors.kernel.org/debian/pool/main/n/nc6/foo.tar.gz", "col" => 2, }, { "url" => "https://mirrors.ocf.berkeley.edu/debian/pool/main/m/mkcue/foo.tar.gz", "msg" => "Please use " \ "https://deb.debian.org/debian/ for " \ "https://mirrors.ocf.berkeley.edu/debian/pool/main/m/mkcue/foo.tar.gz", "col" => 2, }, { "url" => "https://mirrorservice.org/sites/ftp.debian.org/debian/pool/main/n/netris/foo.tar.gz", "msg" => "Please use " \ "https://deb.debian.org/debian/ for " \ "https://mirrorservice.org/sites/ftp.debian.org/debian/pool/main/n/netris/foo.tar.gz", "col" => 2, }, { "url" => "https://www.mirrorservice.org/sites/ftp.debian.org/debian/pool/main/n/netris/foo.tar.gz", "msg" => "Please use " \ "https://deb.debian.org/debian/ for " \ "https://www.mirrorservice.org/sites/ftp.debian.org/debian/pool/main/n/netris/foo.tar.gz", "col" => 2, }, { "url" => "http://foo.googlecode.com/files/foo-1.0.zip", "msg" => "Please use https:// for http://foo.googlecode.com/files/foo-1.0.zip", "col" => 2, }, { "url" => "git://github.com/foo.git", "msg" => "Please use https:// for git://github.com/foo.git", "col" => 2, }, { "url" => "git://gitorious.org/foo/foo5", "msg" => "Please use https:// for git://gitorious.org/foo/foo5", "col" => 2, }, { "url" => "http://github.com/foo/foo5.git", "msg" => "Please use https:// for http://github.com/foo/foo5.git", "col" => 2, }, { "url" => "https://github.com/foo/foobar/archive/main.zip", "msg" => "Use versioned rather than branch tarballs for stable checksums.", "col" => 2, }, { "url" => "https://github.com/foo/bar/tarball/v1.2.3", "msg" => "Use /archive/ URLs for GitHub tarballs (`url` is https://github.com/foo/bar/tarball/v1.2.3).", "col" => 2, }, { "url" => "https://codeload.github.com/foo/bar/tar.gz/v0.1.1", "msg" => <<~EOS, Use GitHub archive URLs: https://github.com/foo/bar/archive/v0.1.1.tar.gz Rather than codeload: https://codeload.github.com/foo/bar/tar.gz/v0.1.1 EOS "col" => 2, }, { "url" => "https://central.maven.org/maven2/com/bar/foo/1.1/foo-1.1.jar", "msg" => "https://central.maven.org/maven2/com/bar/foo/1.1/foo-1.1.jar should be: " \ "https://search.maven.org/remotecontent?filepath=com/bar/foo/1.1/foo-1.1.jar", "col" => 2, }, { "url" => "https://brew.sh/example-darwin.x86_64.tar.gz", "msg" => "https://brew.sh/example-darwin.x86_64.tar.gz looks like a binary package, " \ "not a source archive; homebrew/core is source-only.", "col" => 2, "formula_tap" => "homebrew-core", }, { "url" => "https://brew.sh/example-darwin.amd64.tar.gz", "msg" => "https://brew.sh/example-darwin.amd64.tar.gz looks like a binary package, " \ "not a source archive; homebrew/core is source-only.", "col" => 2, "formula_tap" => "homebrew-core", }, { "url" => "cvs://brew.sh/foo/bar", "msg" => "Use of the \"cvs://\" scheme is deprecated, pass `using: :cvs` instead", "col" => 2, }, { "url" => "bzr://brew.sh/foo/bar", "msg" => "Use of the \"bzr://\" scheme is deprecated, pass `using: :bzr` instead", "col" => 2, }, { "url" => "hg://brew.sh/foo/bar", "msg" => "Use of the \"hg://\" scheme is deprecated, pass `using: :hg` instead", "col" => 2, }, { "url" => "fossil://brew.sh/foo/bar", "msg" => "Use of the \"fossil://\" scheme is deprecated, pass `using: :fossil` instead", "col" => 2, }, { "url" => "svn+http://brew.sh/foo/bar", "msg" => "Use of the \"svn+http://\" scheme is deprecated, pass `using: :svn` instead", "col" => 2, }, { "url" => "https://🫠.sh/foo/bar", "msg" => "Please use the ASCII (Punycode-encoded host, URL-encoded path and query) version of https://🫠.sh/foo/bar.", "col" => 2, }, { "url" => "https://ßrew.sh/foo/bar", "msg" => "Please use the ASCII (Punycode-encoded host, URL-encoded path and query) version of https://ßrew.sh/foo/bar.", "col" => 2, }] end context "when auditing URLs" do it "reports all offenses in `offense_list`" do offense_list.each do |offense_info| allow_any_instance_of(RuboCop::Cop::FormulaCop).to receive(:formula_tap) .and_return(offense_info["formula_tap"]) source = <<~RUBY class Foo < Formula desc "foo" url "#{offense_info["url"]}" end RUBY expected_offenses = [{ message: "FormulaAudit/Urls: #{offense_info["msg"]}", severity: :convention, line: 3, column: offense_info["col"], source: }] offenses = inspect_source(source) expected_offenses.zip(offenses.reverse).each do |expected, actual| expect(actual).not_to be_nil expect(actual.message).to eq(expected[:message]) expect(actual.severity).to eq(expected[:severity]) expect(actual.line).to eq(expected[:line]) expect(actual.column).to eq(expected[:column]) end end end it "reports an offense for GitHub repositories with git:// prefix" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url "https://foo.com" stable do url "git://github.com/foo.git", ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Urls: Please use https:// for git://github.com/foo.git :tag => "v1.0.1", :revision => "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" version "1.0.1" end end RUBY end it "reports an offense if `url` is the same as `mirror`" do expect_offense(<<~RUBY) class Foo < Formula desc "foo" url "https://ftpmirror.fnu.org/foo/foo-1.0.tar.gz" mirror "https://ftpmirror.fnu.org/foo/foo-1.0.tar.gz" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Urls: URL should not be duplicated as a mirror: https://ftpmirror.fnu.org/foo/foo-1.0.tar.gz end RUBY 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/rubocops/text_spec.rb
Library/Homebrew/test/rubocops/text_spec.rb
# frozen_string_literal: true require "rubocops/text" RSpec.describe RuboCop::Cop::FormulaAudit::Text do subject(:cop) { described_class.new } context "when auditing formula text" do it 'reports an offense if `require "formula"` is present' do expect_offense(<<~RUBY) require "formula" ^^^^^^^^^^^^^^^^^ FormulaAudit/Text: `require "formula"` is now unnecessary class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" end RUBY end it "reports an offense if 'revision 0' is present" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" revision 0 ^^^^^^^^^^ FormulaAudit/Text: `revision 0` is unnecessary end RUBY end it "reports an offense if both openssl and libressl are dependencies" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" depends_on "openssl" depends_on "libressl" => :optional ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Text: Formulae should not depend on both OpenSSL and LibreSSL (even optionally). end RUBY expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" depends_on "openssl" depends_on "libressl" ^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Text: Formulae should not depend on both OpenSSL and LibreSSL (even optionally). end RUBY end it "reports an offense if veclibfort is used instead of OpenBLAS (in homebrew/core)" do expect_offense(<<~RUBY, "/homebrew-core/") class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" depends_on "veclibfort" ^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Text: Formulae in homebrew/core should use OpenBLAS as the default serial linear algebra library. end RUBY end it "reports an offense if lapack is used instead of OpenBLAS (in homebrew/core)" do expect_offense(<<~RUBY, "/homebrew-core/") class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" depends_on "lapack" ^^^^^^^^^^^^^^^^^^^ FormulaAudit/Text: Formulae in homebrew/core should use OpenBLAS as the default serial linear algebra library. end RUBY end it "reports an offense if `go get` is executed" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" def install system "go", "get", "bar" ^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Text: Do not use `go get`. Please ask upstream to implement Go vendoring end end RUBY end it "reports an offense if `xcodebuild` is executed" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" def install system "xcodebuild", "foo", "bar" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Text: Use `xcodebuild *args` instead of `system 'xcodebuild', *args` end end RUBY end it "reports an offense if `def plist` is used" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" def install system "xcodebuild", "foo", "bar" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Text: Use `xcodebuild *args` instead of `system 'xcodebuild', *args` end def plist ^^^^^^^^^ FormulaAudit/Text: `def plist` is deprecated. Please use services instead: https://docs.brew.sh/Formula-Cookbook#service-files <<~XML <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>org.nrpe.agent</string> </dict> </plist> XML end end RUBY end it 'reports an offense if `require "language/go"` is present' do expect_offense(<<~RUBY) require "language/go" ^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Text: `require "language/go"` is no longer necessary or correct class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" def install system "go", "get", "bar" ^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Text: Do not use `go get`. Please ask upstream to implement Go vendoring end end RUBY end it "reports an offense if `Formula.factory(name)` is present" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" def install Formula.factory(name) ^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Text: `Formula.factory(name)` is deprecated in favour of `Formula[name]` end end RUBY end it "reports an offense if `dep ensure` is used without `-vendor-only`" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" def install system "dep", "ensure" ^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Text: Use `"dep", "ensure", "-vendor-only"` end end RUBY end it "reports an offense if `cargo build` is executed" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" def install system "cargo", "build" ^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Text: Use `"cargo", "install", *std_cargo_args` end end RUBY end it "doesn't reports an offense if `cargo build` is executed with --lib" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" def install system "cargo", "build", "--lib" end end RUBY end it "reports an offense if `make` calls are not separated" do expect_offense(<<~RUBY) class Foo < Formula def install system "make && make install" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Text: Use separate `make` calls end end RUBY end it "reports an offense if paths are concatenated in string interpolation" do expect_offense(<<~'RUBY') class Foo < Formula def install ohai "foo #{bar + "baz"}" ^^^^^^^^^^^^^^ FormulaAudit/Text: Do not concatenate paths in string interpolation end end RUBY end it 'reports offenses if eg `lib+"thing"` is present' do expect_offense(<<~RUBY) class Foo < Formula def install (lib+"foo").install ^^^^^^^^^ FormulaAudit/Text: Use `lib/"foo"` instead of `lib+"foo"` (bin+"foobar").install ^^^^^^^^^^^^ FormulaAudit/Text: Use `bin/"foobar"` instead of `bin+"foobar"` end end RUBY end it 'reports an offense if `prefix + "bin"` is present' do expect_offense(<<~RUBY) class Foo < Formula def install ohai prefix + "bin" ^^^^^^^^^^^^^^ FormulaAudit/Text: Use `bin` instead of `prefix + "bin"` end end RUBY expect_offense(<<~RUBY) class Foo < Formula def install ohai prefix + "bin/foo" ^^^^^^^^^^^^^^^^^^ FormulaAudit/Text: Use `bin` instead of `prefix + "bin"` end end RUBY 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/rubocops/compact_blank_spec.rb
Library/Homebrew/test/rubocops/compact_blank_spec.rb
# frozen_string_literal: true require "rubocops/compact_blank" RSpec.describe RuboCop::Cop::Homebrew::CompactBlank, :config do it "registers and corrects an offense when using `reject { |e| e.blank? }`" do expect_offense(<<~RUBY) collection.reject { |e| e.blank? } ^^^^^^^^^^^^^^^^^^^^^^^ Use `compact_blank` instead. RUBY expect_correction(<<~RUBY) collection.compact_blank RUBY end it "registers and corrects an offense when using `reject(&:blank?)`" do expect_offense(<<~RUBY) collection.reject(&:blank?) ^^^^^^^^^^^^^^^^ Use `compact_blank` instead. RUBY expect_correction(<<~RUBY) collection.compact_blank RUBY end it "registers and corrects an offense when using `delete_if { |e| e.blank? }`" do expect_offense(<<~RUBY) collection.delete_if { |e| e.blank? } ^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `compact_blank!` instead. RUBY expect_correction(<<~RUBY) collection.compact_blank! RUBY end it "registers and corrects an offense when using `delete_if(&:blank?)`" do expect_offense(<<~RUBY) collection.delete_if(&:blank?) ^^^^^^^^^^^^^^^^^^^ Use `compact_blank!` instead. RUBY expect_correction(<<~RUBY) collection.compact_blank! RUBY end it "registers and corrects an offense when using `reject! { |e| e.blank? }`" do expect_offense(<<~RUBY) collection.reject! { |e| e.blank? } ^^^^^^^^^^^^^^^^^^^^^^^^ Use `compact_blank!` instead. RUBY expect_correction(<<~RUBY) collection.compact_blank! RUBY end it "registers and corrects an offense when using `reject!(&:blank?)`" do expect_offense(<<~RUBY) collection.reject!(&:blank?) ^^^^^^^^^^^^^^^^^ Use `compact_blank!` instead. RUBY expect_correction(<<~RUBY) collection.compact_blank! RUBY end it "registers and corrects an offense when using `reject(&:blank?)` in block" do expect_offense(<<~RUBY) hash.transform_values { |value| value.reject(&:blank?) } ^^^^^^^^^^^^^^^^ Use `compact_blank` instead. RUBY expect_correction(<<~RUBY) hash.transform_values { |value| value.compact_blank } RUBY end it "does not register an offense when using `compact_blank`" do expect_no_offenses(<<~RUBY) collection.compact_blank RUBY end it "does not register an offense when using `compact_blank!`" do expect_no_offenses(<<~RUBY) collection.compact_blank! RUBY end it "does not register an offense when using `reject { |k, v| k.blank? }`" do expect_no_offenses(<<~RUBY) collection.reject { |k, v| k.blank? } RUBY end it "does not register an offense when using the receiver of `blank?` is not a block variable" do expect_no_offenses(<<~RUBY) def foo(arg) collection.reject { |_| arg.blank? } end RUBY end it "does not register an offense when using `reject { |e| e.empty? }`" do expect_no_offenses(<<~RUBY) collection.reject { |e| e.empty? } RUBY 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/rubocops/caveats_spec.rb
Library/Homebrew/test/rubocops/caveats_spec.rb
# frozen_string_literal: true require "rubocops/caveats" RSpec.describe RuboCop::Cop::FormulaAudit::Caveats do subject(:cop) { described_class.new } context "when auditing `caveats`" do it "reports an offense if `setuid` is mentioned" do expect_offense(<<~RUBY) class Foo < Formula homepage "https://brew.sh/foo" url "https://brew.sh/foo-1.0.tgz" def caveats "setuid" ^^^^^^^^ FormulaAudit/Caveats: Instead of recommending `setuid` in the caveats, suggest `sudo`. end end RUBY end it "reports an offense if an escape character is present" do expect_offense(<<~RUBY) class Foo < Formula homepage "https://brew.sh/foo" url "https://brew.sh/foo-1.0.tgz" def caveats "\\x1B" ^^^^^^ FormulaAudit/Caveats: Don't use ANSI escape codes in the caveats. end end RUBY expect_offense(<<~RUBY) class Foo < Formula homepage "https://brew.sh/foo" url "https://brew.sh/foo-1.0.tgz" def caveats "\\u001b" ^^^^^^^^ FormulaAudit/Caveats: Don't use ANSI escape codes in the caveats. end end RUBY end it "reports an offense if dynamic logic (if/else/unless) is used in caveats" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula homepage "https://brew.sh/foo" url "https://brew.sh/foo-1.0.tgz" def caveats if true ^^^^^^^ FormulaAudit/Caveats: Don't use dynamic logic (if/else/unless) in caveats. "foo" else "bar" end end end RUBY expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula homepage "https://brew.sh/foo" url "https://brew.sh/foo-1.0.tgz" def caveats unless false ^^^^^^^^^^^^ FormulaAudit/Caveats: Don't use dynamic logic (if/else/unless) in caveats. "foo" end end end RUBY 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/rubocops/uses_from_macos_spec.rb
Library/Homebrew/test/rubocops/uses_from_macos_spec.rb
# frozen_string_literal: true require "rubocops/uses_from_macos" RSpec.describe RuboCop::Cop::FormulaAudit::UsesFromMacos do subject(:cop) { described_class.new } context "when auditing `uses_from_macos` dependencies" do it "reports an offense when used on non-macOS dependency" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" uses_from_macos "postgresql" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/UsesFromMacos: `uses_from_macos` should only be used for macOS dependencies, not 'postgresql'. end RUBY end it "reports offenses for multiple non-macOS dependencies and none for valid macOS dependencies" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" uses_from_macos "boost" ^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/UsesFromMacos: `uses_from_macos` should only be used for macOS dependencies, not 'boost'. uses_from_macos "bzip2" uses_from_macos "postgresql" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/UsesFromMacos: `uses_from_macos` should only be used for macOS dependencies, not 'postgresql'. uses_from_macos "zlib" end RUBY end it "reports an offense when used in `depends_on :linux` formula" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" depends_on :linux uses_from_macos "zlib" ^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/UsesFromMacos: `uses_from_macos` should not be used when Linux is required. end RUBY end end include_examples "formulae exist", described_class::ALLOWED_USES_FROM_MACOS_DEPS 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/rubocops/keg_only_spec.rb
Library/Homebrew/test/rubocops/keg_only_spec.rb
# frozen_string_literal: true require "rubocops/keg_only" RSpec.describe RuboCop::Cop::FormulaAudit::KegOnly do subject(:cop) { described_class.new } it "reports and corrects an offense when the `keg_only` reason is capitalized" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" keg_only "Because why not" ^^^^^^^^^^^^^^^^^ FormulaAudit/KegOnly: 'Because' from the `keg_only` reason should be 'because'. end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" keg_only "because why not" end RUBY end it "reports and corrects an offense when the `keg_only` reason ends with a period" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" keg_only "ending with a period." ^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/KegOnly: `keg_only` reason should not end with a period. end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" keg_only "ending with a period" end RUBY end it "reports no offenses when a `keg_only` reason is a block" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" keg_only <<~EOF this line starts with a lowercase word. This line does not but that shouldn't be a problem EOF end RUBY end it "reports no offenses if a capitalized `keg-only` reason is an exempt proper noun" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" keg_only "Apple ships foo in the CLT package" end RUBY end it "reports no offenses if a capitalized `keg_only` reason is the formula's name" do expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula url "https://brew.sh/foo-1.0.tgz" keg_only "Foo is the formula name hence downcasing is not required" end RUBY 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/rubocops/blank_spec.rb
Library/Homebrew/test/rubocops/blank_spec.rb
# frozen_string_literal: true require "rubocops/blank" RSpec.describe RuboCop::Cop::Homebrew::Blank, :config do shared_examples "offense" do |source, correction, message| it "registers an offense and corrects" do expect_offense(<<~RUBY, source:, message:) #{source} ^{source} #{message} RUBY expect_correction(<<~RUBY) #{correction} RUBY end end it "accepts checking nil?" do expect_no_offenses("foo.nil?") end it "accepts checking empty?" do expect_no_offenses("foo.empty?") end it "accepts checking nil? || empty? on different objects" do expect_no_offenses("foo.nil? || bar.empty?") end # Bug: https://github.com/rubocop/rubocop/issues/4171 it "does not break when RHS of `or` is a naked falsiness check" do expect_no_offenses("foo.empty? || bar") end it "does not break when LHS of `or` is a naked falsiness check" do expect_no_offenses("bar || foo.empty?") end # Bug: https://github.com/rubocop/rubocop/issues/4814 it "does not break when LHS of `or` is a send node with an argument" do expect_no_offenses("x(1) || something") end context "when nil or empty" do it_behaves_like "offense", "foo.nil? || foo.empty?", "foo.blank?", "Use `foo.blank?` instead of `foo.nil? || foo.empty?`." it_behaves_like "offense", "nil? || empty?", "blank?", "Use `blank?` instead of `nil? || empty?`." it_behaves_like "offense", "foo == nil || foo.empty?", "foo.blank?", "Use `foo.blank?` instead of `foo == nil || foo.empty?`." it_behaves_like "offense", "nil == foo || foo.empty?", "foo.blank?", "Use `foo.blank?` instead of `nil == foo || foo.empty?`." it_behaves_like "offense", "!foo || foo.empty?", "foo.blank?", "Use `foo.blank?` instead of `!foo || foo.empty?`." it_behaves_like "offense", "foo.nil? || !!foo.empty?", "foo.blank?", "Use `foo.blank?` instead of `foo.nil? || !!foo.empty?`." it_behaves_like "offense", "foo == nil || !!foo.empty?", "foo.blank?", "Use `foo.blank?` instead of " \ "`foo == nil || !!foo.empty?`." it_behaves_like "offense", "nil == foo || !!foo.empty?", "foo.blank?", "Use `foo.blank?` instead of " \ "`nil == foo || !!foo.empty?`." end context "when checking all variable types" do it_behaves_like "offense", "foo.bar.nil? || foo.bar.empty?", "foo.bar.blank?", "Use `foo.bar.blank?` instead of " \ "`foo.bar.nil? || foo.bar.empty?`." it_behaves_like "offense", "FOO.nil? || FOO.empty?", "FOO.blank?", "Use `FOO.blank?` instead of `FOO.nil? || FOO.empty?`." it_behaves_like "offense", "Foo.nil? || Foo.empty?", "Foo.blank?", "Use `Foo.blank?` instead of `Foo.nil? || Foo.empty?`." it_behaves_like "offense", "Foo::Bar.nil? || Foo::Bar.empty?", "Foo::Bar.blank?", "Use `Foo::Bar.blank?` instead of " \ "`Foo::Bar.nil? || Foo::Bar.empty?`." it_behaves_like "offense", "@foo.nil? || @foo.empty?", "@foo.blank?", "Use `@foo.blank?` instead of `@foo.nil? || @foo.empty?`." it_behaves_like "offense", "$foo.nil? || $foo.empty?", "$foo.blank?", "Use `$foo.blank?` instead of `$foo.nil? || $foo.empty?`." it_behaves_like "offense", "@@foo.nil? || @@foo.empty?", "@@foo.blank?", "Use `@@foo.blank?` instead of " \ "`@@foo.nil? || @@foo.empty?`." it_behaves_like "offense", "foo[bar].nil? || foo[bar].empty?", "foo[bar].blank?", "Use `foo[bar].blank?` instead of " \ "`foo[bar].nil? || foo[bar].empty?`." it_behaves_like "offense", "foo(bar).nil? || foo(bar).empty?", "foo(bar).blank?", "Use `foo(bar).blank?` instead of " \ "`foo(bar).nil? || foo(bar).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/rubocops/move_to_extend_os_spec.rb
Library/Homebrew/test/rubocops/move_to_extend_os_spec.rb
# frozen_string_literal: true require "rubocops/move_to_extend_os" RSpec.describe RuboCop::Cop::Homebrew::MoveToExtendOS do subject(:cop) { described_class.new } it "registers an offense when using `OS.linux?`" do expect_offense(<<~RUBY) OS.linux? ^^^^^^^^^ Homebrew/MoveToExtendOS: Move `OS.linux?` and `OS.mac?` calls to `extend/os`. RUBY end it "registers an offense when using `OS.mac?`" do expect_offense(<<~RUBY) OS.mac? ^^^^^^^ Homebrew/MoveToExtendOS: Move `OS.linux?` and `OS.mac?` calls to `extend/os`. RUBY 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/rubocops/negate_include_spec.rb
Library/Homebrew/test/rubocops/negate_include_spec.rb
# frozen_string_literal: true require "rubocops/negate_include" RSpec.describe RuboCop::Cop::Homebrew::NegateInclude, :config do it "registers an offense and corrects when using `!include?`" do expect_offense(<<~RUBY) !array.include?(2) ^^^^^^^^^^^^^^^^^^ Use `.exclude?` and remove the negation part. RUBY expect_correction(<<~RUBY) array.exclude?(2) RUBY end it "does not register an offense when using `!include?` without receiver" do expect_no_offenses(<<~RUBY) !include?(2) RUBY end it "does not register an offense when using `include?` or `exclude?`" do expect_no_offenses(<<~RUBY) array.include?(2) array.exclude?(2) RUBY 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/rubocops/present_spec.rb
Library/Homebrew/test/rubocops/present_spec.rb
# frozen_string_literal: true require "rubocops/present" RSpec.describe RuboCop::Cop::Homebrew::Present, :config do shared_examples "offense" do |source, correction, message| it "registers an offense and corrects" do expect_offense(<<~RUBY, source:, message:) #{source} ^{source} #{message} RUBY expect_correction(<<~RUBY) #{correction} RUBY end end it "accepts checking nil?" do expect_no_offenses("foo.nil?") end it "accepts checking empty?" do expect_no_offenses("foo.empty?") end it "accepts checking nil? || empty? on different objects" do expect_no_offenses("foo.nil? || bar.empty?") end it "accepts checking existence && not empty? on different objects" do expect_no_offenses("foo && !bar.empty?") end it_behaves_like "offense", "foo && !foo.empty?", "foo.present?", "Use `foo.present?` instead of `foo && !foo.empty?`." it_behaves_like "offense", "!foo.nil? && !foo.empty?", "foo.present?", "Use `foo.present?` instead of `!foo.nil? && !foo.empty?`." it_behaves_like "offense", "!nil? && !empty?", "present?", "Use `present?` instead of `!nil? && !empty?`." it_behaves_like "offense", "foo != nil && !foo.empty?", "foo.present?", "Use `foo.present?` instead of `foo != nil && !foo.empty?`." it_behaves_like "offense", "!!foo && !foo.empty?", "foo.present?", "Use `foo.present?` instead of `!!foo && !foo.empty?`." context "when checking all variable types" do it_behaves_like "offense", "!foo.nil? && !foo.empty?", "foo.present?", "Use `foo.present?` instead of " \ "`!foo.nil? && !foo.empty?`." it_behaves_like "offense", "!foo.bar.nil? && !foo.bar.empty?", "foo.bar.present?", "Use `foo.bar.present?` instead of " \ "`!foo.bar.nil? && !foo.bar.empty?`." it_behaves_like "offense", "!FOO.nil? && !FOO.empty?", "FOO.present?", "Use `FOO.present?` instead of " \ "`!FOO.nil? && !FOO.empty?`." it_behaves_like "offense", "!Foo.nil? && !Foo.empty?", "Foo.present?", "Use `Foo.present?` instead of " \ "`!Foo.nil? && !Foo.empty?`." it_behaves_like "offense", "!@foo.nil? && !@foo.empty?", "@foo.present?", "Use `@foo.present?` instead of " \ "`!@foo.nil? && !@foo.empty?`." it_behaves_like "offense", "!$foo.nil? && !$foo.empty?", "$foo.present?", "Use `$foo.present?` instead of " \ "`!$foo.nil? && !$foo.empty?`." it_behaves_like "offense", "!@@foo.nil? && !@@foo.empty?", "@@foo.present?", "Use `@@foo.present?` instead of " \ "`!@@foo.nil? && !@@foo.empty?`." it_behaves_like "offense", "!foo[bar].nil? && !foo[bar].empty?", "foo[bar].present?", "Use `foo[bar].present?` instead of " \ "`!foo[bar].nil? && !foo[bar].empty?`." it_behaves_like "offense", "!Foo::Bar.nil? && !Foo::Bar.empty?", "Foo::Bar.present?", "Use `Foo::Bar.present?` instead of " \ "`!Foo::Bar.nil? && !Foo::Bar.empty?`." it_behaves_like "offense", "!foo(bar).nil? && !foo(bar).empty?", "foo(bar).present?", "Use `foo(bar).present?` instead of " \ "`!foo(bar).nil? && !foo(bar).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/rubocops/safe_navigation_with_blank_spec.rb
Library/Homebrew/test/rubocops/safe_navigation_with_blank_spec.rb
# frozen_string_literal: true require "rubocops/safe_navigation_with_blank" RSpec.describe RuboCop::Cop::Homebrew::SafeNavigationWithBlank, :config do context "when in a conditional" do it "registers an offense on a single conditional" do expect_offense(<<~RUBY) do_something unless foo&.blank? ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid calling `blank?` with the safe navigation operator in conditionals. RUBY expect_correction(<<~RUBY) do_something unless foo.blank? RUBY end it "registers an offense on chained conditionals" do expect_offense(<<~RUBY) do_something unless foo&.bar&.blank? ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid calling `blank?` with the safe navigation operator in conditionals. RUBY expect_correction(<<~RUBY) do_something unless foo&.bar.blank? RUBY end it "does not register an offense on `.blank?`" do expect_no_offenses(<<~RUBY) return if foo.blank? RUBY end end context "when outside a conditional" do it "registers no offense" do expect_no_offenses(<<~RUBY) bar = foo&.blank? RUBY 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/rubocops/zero_zero_zero_zero_spec.rb
Library/Homebrew/test/rubocops/zero_zero_zero_zero_spec.rb
# frozen_string_literal: true require "rubocops/zero_zero_zero_zero" RSpec.describe RuboCop::Cop::FormulaAudit::ZeroZeroZeroZero do subject(:cop) { described_class.new } it "reports no offenses when 0.0.0.0 is used inside test do blocks" do expect_no_offenses(<<~RUBY, "/homebrew-core/") class Foo < Formula url "https://brew.sh/foo-1.0.tgz" desc "A test formula" test do system "echo", "0.0.0.0" end end RUBY end it "reports no offenses for valid IP ranges like 10.0.0.0" do expect_no_offenses(<<~RUBY, "/homebrew-core/") class Foo < Formula url "https://brew.sh/foo-1.0.tgz" desc "A test formula" def install system "echo", "10.0.0.0" end end RUBY end it "reports no offenses for IP range notation like 0.0.0.0-255.255.255.255" do expect_no_offenses(<<~RUBY, "/homebrew-core/") class Foo < Formula url "https://brew.sh/foo-1.0.tgz" desc "A test formula" def install system "echo", "0.0.0.0-255.255.255.255" end end RUBY end it "reports no offenses for private IP ranges" do expect_no_offenses(<<~RUBY, "/homebrew-core/") class Foo < Formula url "https://brew.sh/foo-1.0.tgz" desc "A test formula" def install system "echo", "192.168.1.1" system "echo", "172.16.0.1" system "echo", "10.0.0.1" end end RUBY end it "reports no offenses when outside of homebrew-core" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" desc "A test formula" service do run [bin/"foo", "--host", "0.0.0.0"] end end RUBY end it "reports offenses when 0.0.0.0 is used in service blocks" do expect_offense(<<~RUBY, "/homebrew-core/") class Foo < Formula url "https://brew.sh/foo-1.0.tgz" desc "A test formula" service do run [bin/"foo", "--host", "0.0.0.0"] ^^^^^^^^^ FormulaAudit/ZeroZeroZeroZero: Do not use 0.0.0.0 as it can be a security risk. end end RUBY end it "reports offenses when 0.0.0.0 is used outside of test do blocks" do expect_offense(<<~RUBY, "/homebrew-core/") class Foo < Formula url "https://brew.sh/foo-1.0.tgz" desc "A test formula" def install system "echo", "0.0.0.0" ^^^^^^^^^ FormulaAudit/ZeroZeroZeroZero: Do not use 0.0.0.0 as it can be a security risk. end end RUBY end it "reports offenses for 0.0.0.0 in method definitions outside test blocks" do expect_offense(<<~RUBY, "/homebrew-core/") class Foo < Formula url "https://brew.sh/foo-1.0.tgz" desc "A test formula" def configure system "./configure", "--bind-address=0.0.0.0" ^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ZeroZeroZeroZero: Do not use 0.0.0.0 as it can be a security risk. end end RUBY end it "reports multiple offenses when 0.0.0.0 is used in multiple places" do expect_offense(<<~RUBY, "/homebrew-core/") class Foo < Formula url "https://brew.sh/foo-1.0.tgz" desc "A test formula" def install system "echo", "0.0.0.0" ^^^^^^^^^ FormulaAudit/ZeroZeroZeroZero: Do not use 0.0.0.0 as it can be a security risk. end def post_install system "echo", "0.0.0.0" ^^^^^^^^^ FormulaAudit/ZeroZeroZeroZero: Do not use 0.0.0.0 as it can be a security risk. end end RUBY 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/rubocops/presence_spec.rb
Library/Homebrew/test/rubocops/presence_spec.rb
# frozen_string_literal: true require "rubocops/presence" RSpec.describe RuboCop::Cop::Homebrew::Presence, :config do it "registers an offense and corrects when `a.present? ? a : nil`" do expect_offense(<<~RUBY) a.present? ? a : nil ^^^^^^^^^^^^^^^^^^^^ Use `a.presence` instead of `a.present? ? a : nil`. RUBY expect_correction(<<~RUBY) a.presence RUBY end it "registers an offense and corrects when `!a.present? ? nil: a`" do expect_offense(<<~RUBY) !a.present? ? nil: a ^^^^^^^^^^^^^^^^^^^^ Use `a.presence` instead of `!a.present? ? nil: a`. RUBY expect_correction(<<~RUBY) a.presence RUBY end it "registers an offense and corrects when `a.blank? ? nil : a`" do expect_offense(<<~RUBY) a.blank? ? nil : a ^^^^^^^^^^^^^^^^^^ Use `a.presence` instead of `a.blank? ? nil : a`. RUBY expect_correction(<<~RUBY) a.presence RUBY end it "registers an offense and corrects when `!a.blank? ? a : nil`" do expect_offense(<<~RUBY) !a.blank? ? a : nil ^^^^^^^^^^^^^^^^^^^ Use `a.presence` instead of `!a.blank? ? a : nil`. RUBY expect_correction(<<~RUBY) a.presence RUBY end it "registers an offense and corrects when `a.present? ? a : b`" do expect_offense(<<~RUBY) a.present? ? a : b ^^^^^^^^^^^^^^^^^^ Use `a.presence || b` instead of `a.present? ? a : b`. RUBY expect_correction(<<~RUBY) a.presence || b RUBY end it "registers an offense and corrects when `!a.present? ? b : a`" do expect_offense(<<~RUBY) !a.present? ? b : a ^^^^^^^^^^^^^^^^^^^ Use `a.presence || b` instead of `!a.present? ? b : a`. RUBY expect_correction(<<~RUBY) a.presence || b RUBY end it "registers an offense and corrects when `a.blank? ? b : a`" do expect_offense(<<~RUBY) a.blank? ? b : a ^^^^^^^^^^^^^^^^ Use `a.presence || b` instead of `a.blank? ? b : a`. RUBY expect_correction(<<~RUBY) a.presence || b RUBY end it "registers an offense and corrects when `!a.blank? ? a : b`" do expect_offense(<<~RUBY) !a.blank? ? a : b ^^^^^^^^^^^^^^^^^ Use `a.presence || b` instead of `!a.blank? ? a : b`. RUBY expect_correction(<<~RUBY) a.presence || b RUBY end it "registers an offense and corrects when `a.present? ? a : 1`" do expect_offense(<<~RUBY) a.present? ? a : 1 ^^^^^^^^^^^^^^^^^^ Use `a.presence || 1` instead of `a.present? ? a : 1`. RUBY expect_correction(<<~RUBY) a.presence || 1 RUBY end it "registers an offense and corrects when `a.blank? ? 1 : a`" do expect_offense(<<~RUBY) a.blank? ? 1 : a ^^^^^^^^^^^^^^^^ Use `a.presence || 1` instead of `a.blank? ? 1 : a`. RUBY expect_correction(<<~RUBY) a.presence || 1 RUBY end it "registers an offense and corrects when `a(:bar).map(&:baz).present? ? a(:bar).map(&:baz) : nil`" do expect_offense(<<~RUBY) a(:bar).map(&:baz).present? ? a(:bar).map(&:baz) : nil ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `a(:bar).map(&:baz).presence` instead of `a(:bar).map(&:baz).present? ? a(:bar).map(&:baz) : nil`. RUBY expect_correction(<<~RUBY) a(:bar).map(&:baz).presence RUBY end it "registers an offense and corrects when `a.present? ? a : b[:c]`" do expect_offense(<<~RUBY) a.present? ? a : b[:c] ^^^^^^^^^^^^^^^^^^^^^^ Use `a.presence || b[:c]` instead of `a.present? ? a : b[:c]`. RUBY expect_correction(<<~RUBY) a.presence || b[:c] RUBY end it "registers an offense and corrects when multi-line if node" do expect_offense(<<~RUBY) if a.present? ^^^^^^^^^^^^^ Use `a.presence` instead of `if a.present? ... end`. a else nil end RUBY expect_correction(<<~RUBY) a.presence RUBY end it "registers an offense and corrects when multi-line unless node" do expect_offense(<<~RUBY) unless a.present? ^^^^^^^^^^^^^^^^^ Use `a.presence` instead of `unless a.present? ... end`. nil else a end RUBY expect_correction(<<~RUBY) a.presence RUBY end it "registers an offense and corrects when multi-line if node with `+` operators in the else branch" do expect_offense(<<~RUBY) if a.present? ^^^^^^^^^^^^^ Use `a.presence || b.to_f + 12.0` instead of `if a.present? ... end`. a else b.to_f + 12.0 end RUBY expect_correction(<<~RUBY) a.presence || b.to_f + 12.0 RUBY end it "registers an offense and corrects when multi-line if `*` operators in the else branch" do expect_offense(<<~RUBY) if a.present? ^^^^^^^^^^^^^ Use `a.presence || b.to_f * 12.0` instead of `if a.present? ... end`. a else b.to_f * 12.0 end RUBY expect_correction(<<~RUBY) a.presence || b.to_f * 12.0 RUBY end it "registers an offense and corrects when `a if a.present?`" do expect_offense(<<~RUBY) a if a.present? ^^^^^^^^^^^^^^^ Use `a.presence` instead of `a if a.present?`. RUBY expect_correction(<<~RUBY) a.presence RUBY end it "registers an offense and corrects when `a unless a.blank?`" do expect_offense(<<~RUBY) a unless a.blank? ^^^^^^^^^^^^^^^^^ Use `a.presence` instead of `a unless a.blank?`. RUBY expect_correction(<<~RUBY) a.presence RUBY end it "registers an offense and corrects when `.present?` with method chain" do expect_offense(<<~RUBY) if [1, 2, 3].map { |num| num + 1 } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `[1, 2, 3].map { |num| num + 1 }.map { |num| num + 2 }.presence || b` instead of `if [1, 2, 3].map { |num| num + 1 }.map { |num| num + 2 }.present? ... end`. .map { |num| num + 2 } .present? [1, 2, 3].map { |num| num + 1 }.map { |num| num + 2 } else b end RUBY expect_correction(<<~RUBY) [1, 2, 3].map { |num| num + 1 } .map { |num| num + 2 }.presence || b RUBY end context "when multiline ternary can be replaced" do it "registers an offense and corrects" do expect_offense(<<~RUBY) a.present? ? ^^^^^^^^^^^^ Use `a.presence` instead of `a.present? ? a : nil`. a : nil RUBY expect_correction(<<~RUBY) a.presence RUBY end end context "when a method argument of `else` branch is enclosed in parentheses" do it "registers an offense and corrects" do expect_offense(<<~RUBY) if value.present? ^^^^^^^^^^^^^^^^^ Use `value.presence || do_something(value)` instead of `if value.present? ... end`. value else do_something(value) end RUBY expect_correction(<<~RUBY) value.presence || do_something(value) RUBY end end context "when a method argument of `else` branch is not enclosed in parentheses" do it "registers an offense and corrects" do expect_offense(<<~RUBY) if value.present? ^^^^^^^^^^^^^^^^^ Use `value.presence || do_something(value)` instead of `if value.present? ... end`. value else do_something value end RUBY expect_correction(<<~RUBY) value.presence || do_something(value) RUBY end end context "when multiple method arguments of `else` branch is not enclosed in parentheses" do it "registers an offense and corrects" do expect_offense(<<~RUBY) if value.present? ^^^^^^^^^^^^^^^^^ Use `value.presence || do_something(arg1, arg2)` instead of `if value.present? ... end`. value else do_something arg1, arg2 end RUBY expect_correction(<<~RUBY) value.presence || do_something(arg1, arg2) RUBY end end context "when a method argument with a receiver of `else` branch is not enclosed in parentheses" do it "registers an offense and corrects" do expect_offense(<<~RUBY) if value.present? ^^^^^^^^^^^^^^^^^ Use `value.presence || foo.do_something(value)` instead of `if value.present? ... end`. value else foo.do_something value end RUBY expect_correction(<<~RUBY) value.presence || foo.do_something(value) RUBY end end context "when a right-hand side of the relational operator" do %w[< > <= >= == !=].each do |operator| it "registers an offense and corrects when `#{operator}`" do expect_offense(<<~RUBY, operator:) a #{operator} if b.present? _{operator} ^^^^^^^^^^^^^ Use `(b.presence || c)` instead of `if b.present? ... end`. b else c end RUBY expect_correction(<<~RUBY) a #{operator} (b.presence || c) RUBY end end end it "does not register an offense when using `#presence`" do expect_no_offenses(<<~RUBY) a.presence RUBY end it "does not register an offense when the expression does not return the receiver of `#present?`" do expect_no_offenses(<<~RUBY) a.present? ? b : nil RUBY expect_no_offenses(<<~RUBY) puts foo if present? puts foo if !present? RUBY end it "does not register an offense when the expression does not return the receiver of `#blank?`" do expect_no_offenses(<<~RUBY) a.blank? ? nil : b RUBY expect_no_offenses(<<~RUBY) puts foo if blank? puts foo if !blank? RUBY end it "does not register an offense when if or unless modifier is used" do [ "a if a.blank?", "a unless a.present?", ].each { |source| expect_no_offenses(source) } end it "does not register an offense when the else block is multiline" do expect_no_offenses(<<~RUBY) if a.present? a else something something something end RUBY end it "does not register an offense when the else block has multiple statements" do expect_no_offenses(<<~RUBY) if a.present? a else something; something; something end RUBY end it "does not register an offense when including the elsif block" do expect_no_offenses(<<~RUBY) if a.present? a elsif b b end RUBY end it "does not register an offense when the else block has `if` node" do expect_no_offenses(<<~RUBY) if a.present? a else b if c end RUBY end it "does not register an offense when the else block has `rescue` node" do expect_no_offenses(<<~RUBY) if something_method.present? something_method else invalid_method rescue StandardError end RUBY end it "does not register an offense when the else block has `while` node" do expect_no_offenses(<<~RUBY) if a.present? a else fetch_state while waiting? end RUBY end it "does not register an offense when using #present? with elsif block" do expect_no_offenses(<<~RUBY) if something? a elsif b.present? b end RUBY 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/rubocops/exec_shell_metacharacters_spec.rb
Library/Homebrew/test/rubocops/exec_shell_metacharacters_spec.rb
# frozen_string_literal: true require "rubocops/shell_commands" RSpec.describe RuboCop::Cop::Homebrew::ExecShellMetacharacters do subject(:cop) { described_class.new } context "when auditing exec calls" do it "reports aan offense when output piping is used" do expect_offense(<<~RUBY) fork do exec "foo bar > output" ^^^^^^^^^^^^^^^^^^ Homebrew/ExecShellMetacharacters: Don't use shell metacharacters in `exec`. Implement the logic in Ruby instead, using methods like `$stdout.reopen`. end RUBY end it "reports no offenses when no metacharacters are used" do expect_no_offenses(<<~RUBY) fork do exec "foo bar" end RUBY 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/rubocops/install_bundler_gems_spec.rb
Library/Homebrew/test/rubocops/install_bundler_gems_spec.rb
# frozen_string_literal: true require "rubocops/install_bundler_gems" RSpec.describe RuboCop::Cop::Homebrew::InstallBundlerGems, :config do it "registers an offense and corrects when using `Homebrew.install_bundler_gems!`" do expect_offense(<<~RUBY) Homebrew.install_bundler_gems! ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Only use `Homebrew.install_bundler_gems!` in dev-cmd. RUBY 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/rubocops/files_spec.rb
Library/Homebrew/test/rubocops/files_spec.rb
# frozen_string_literal: true require "rubocops/files" RSpec.describe RuboCop::Cop::FormulaAudit::Files do subject(:cop) { described_class.new } context "when auditing files" do it "reports an offense when the permissions are invalid" do filename = Formulary.core_path("test_formula") File.open(filename, "w") do |file| FileUtils.chmod "-rwx", filename expect_offense(<<~RUBY, file) class Foo < Formula ^^^^^^^^^^^^^^^^^^^ FormulaAudit/Files: Incorrect file permissions (000): chmod a+r #{filename} url "https://brew.sh/foo-1.0.tgz" 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/rubocops/service_spec.rb
Library/Homebrew/test/rubocops/service_spec.rb
# frozen_string_literal: true require "rubocops/service" RSpec.describe RuboCop::Cop::FormulaAudit::Service do subject(:cop) { described_class.new } it "reports offenses when a service block is missing a required command" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" service do ^^^^^^^^^^ FormulaAudit/Service: Service blocks require `run` or `name` to be defined. run_type :cron working_dir "/tmp/example" end end RUBY end it "reports no offenses when a service block includes custom names and requires root" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" service do name macos: "custom.mcxl.foo", linux: "custom.foo" require_root true end end RUBY end it "reports offenses when a service block includes more than custom names and no run command" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" service do ^^^^^^^^^^ FormulaAudit/Service: `run` must be defined to use methods other than `name` like [:working_dir]. name macos: "custom.mcxl.foo", linux: "custom.foo" working_dir "/tmp/example" end end RUBY end it "reports offenses when a formula's service block uses cellar paths" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" service do run [bin/"foo", "run", "-config", etc/"foo/config.json"] ^^^ FormulaAudit/Service: Use `opt_bin` instead of `bin` in service blocks. working_dir libexec ^^^^^^^ FormulaAudit/Service: Use `opt_libexec` instead of `libexec` in service blocks. end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" service do run [opt_bin/"foo", "run", "-config", etc/"foo/config.json"] working_dir opt_libexec end end RUBY end it "reports no offenses when a service block only uses opt paths" do expect_no_offenses(<<~RUBY) class Bin < Formula url "https://brew.sh/foo-1.0.tgz" service do run [opt_bin/"bin", "run", "-config", etc/"bin/config.json"] working_dir opt_libexec end end RUBY 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/rubocops/components_redundancy_spec.rb
Library/Homebrew/test/rubocops/components_redundancy_spec.rb
# frozen_string_literal: true require "rubocops/components_redundancy" RSpec.describe RuboCop::Cop::FormulaAudit::ComponentsRedundancy do subject(:cop) { described_class.new } context "when auditing formula components" do it "reports an offense if `url` is outside `stable` block" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ComponentsRedundancy: `url` should be put inside `stable` block stable do # stuff end head do # stuff end end RUBY end it "reports an offense if both `head` and `head do` are present" do expect_offense(<<~RUBY) class Foo < Formula head "https://brew.sh/foo.git", branch: "develop" head do ^^^^^^^ FormulaAudit/ComponentsRedundancy: `head` and `head do` should not be simultaneously present # stuff end end RUBY end it "reports an offense if both `bottle :modifier` and `bottle do` are present" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do ^^^^^^^^^ FormulaAudit/ComponentsRedundancy: `bottle :modifier` and `bottle do` should not be simultaneously present # bottles go here end bottle :unneeded end RUBY end it "reports no offenses if `stable do` is present with a `head` method" do expect_no_offenses(<<~RUBY) class Foo < Formula head "https://brew.sh/foo.git", branch: "develop" stable do # stuff end end RUBY end it "reports no offenses if `stable do` is present with a `head do` block" do expect_no_offenses(<<~RUBY) class Foo < Formula stable do # stuff end head do # stuff end end RUBY end it "reports an offense if `stable do` or `head do` is present with only `url`" do expect_offense(<<~RUBY) class Foo < Formula stable do ^^^^^^^^^ FormulaAudit/ComponentsRedundancy: `stable do` should not be present with only url/sha256/mirror/version url "https://brew.sh/foo-1.0.tgz" end head do ^^^^^^^ FormulaAudit/ComponentsRedundancy: `head do` should not be present with only url/branch url "https://brew.sh/foo.git" end end RUBY end it "reports an offense if `head do` is present with only `url` and `branch`" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" head do ^^^^^^^ FormulaAudit/ComponentsRedundancy: `head do` should not be present with only url/branch url "https://brew.sh/foo.git", branch: "develop" end end RUBY end it "reports no offenses if `stable do` is present with `url` and `depends_on`" do expect_no_offenses(<<~RUBY) class Foo < Formula head "https://brew.sh/foo.git", branch: "trunk" stable do url "https://brew.sh/foo-1.0.tgz" depends_on "bar" end end RUBY end it "reports no offenses if `head do` is present with `url` and `depends_on`" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" head do url "https://brew.sh/foo.git" branch "develop" depends_on "bar" end end RUBY 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/rubocops/io_read_spec.rb
Library/Homebrew/test/rubocops/io_read_spec.rb
# frozen_string_literal: true require "rubocops/io_read" RSpec.describe RuboCop::Cop::Homebrew::IORead do subject(:cop) { described_class.new } it "reports an offense when `IO.read` is used with a pipe character" do expect_offense(<<~RUBY) IO.read("|echo test") ^^^^^^^^^^^^^^^^^^^^^ Homebrew/IORead: The use of `IO.read` is a security risk. RUBY end it "does not report an offense when `IO.read` is used without a pipe character" do expect_no_offenses(<<~RUBY) IO.read("file.txt") RUBY end it "reports an offense when `IO.read` is used with untrustworthy input" do expect_offense(<<~RUBY) input = "input value from an unknown source" IO.read(input) ^^^^^^^^^^^^^^ Homebrew/IORead: The use of `IO.read` is a security risk. RUBY end it "reports an offense when `IO.read` is used with a dynamic string starting with a pipe character" do expect_offense(<<~'RUBY') input = "test" IO.read("|echo #{input}") ^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/IORead: The use of `IO.read` is a security risk. RUBY end it "reports an offense when `IO.read` is used with a dynamic string at the start" do expect_offense(<<~'RUBY') input = "|echo test" IO.read("#{input}.txt") ^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/IORead: The use of `IO.read` is a security risk. RUBY end it "does not report an offense when `IO.read` is used with a dynamic string safely" do expect_no_offenses(<<~'RUBY') input = "test" IO.read("somefile#{input}.txt") RUBY end it "reports an offense when `IO.read` is used with a concatenated string starting with a pipe character" do expect_offense(<<~RUBY) input = "|echo test" IO.read("|echo " + input) ^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/IORead: The use of `IO.read` is a security risk. RUBY end it "reports an offense when `IO.read` is used with a concatenated string starting with untrustworthy input" do expect_offense(<<~RUBY) input = "|echo test" IO.read(input + ".txt") ^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/IORead: The use of `IO.read` is a security risk. RUBY end it "does not report an offense when `IO.read` is used with a concatenated string safely" do expect_no_offenses(<<~RUBY) input = "test" IO.read("somefile" + input + ".txt") RUBY 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/rubocops/provided_by_macos_spec.rb
Library/Homebrew/test/rubocops/provided_by_macos_spec.rb
# frozen_string_literal: true require "rubocops/uses_from_macos" RSpec.describe RuboCop::Cop::FormulaAudit::ProvidedByMacos do subject(:cop) { described_class.new } it "fails for formulae not in PROVIDED_BY_MACOS_FORMULAE list" do expect_offense(<<~RUBY) class Baz < Formula url "https://brew.sh/baz-1.0.tgz" homepage "https://brew.sh" keg_only :provided_by_macos ^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/ProvidedByMacos: Formulae that are `keg_only :provided_by_macos` should be added to the `PROVIDED_BY_MACOS_FORMULAE` list (in the Homebrew/brew repository) end RUBY end it "succeeds for formulae in PROVIDED_BY_MACOS_FORMULAE list" do expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/apr.rb") class Apr < Formula url "https://brew.sh/apr-1.0.tgz" homepage "https://brew.sh" keg_only :provided_by_macos end RUBY end it "succeeds for formulae that are keg_only for a different reason" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" keg_only :versioned_formula end RUBY end include_examples "formulae exist", described_class::PROVIDED_BY_MACOS_FORMULAE 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/rubocops/resource_requires_dependencies_spec.rb
Library/Homebrew/test/rubocops/resource_requires_dependencies_spec.rb
# frozen_string_literal: true require "rubocops/resource_requires_dependencies" RSpec.describe RuboCop::Cop::FormulaAudit::ResourceRequiresDependencies do subject(:cop) { described_class.new } context "when a formula does not have any resources" do it "does not report offenses" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" uses_from_macos "libxml2" end RUBY end end context "when a formula does not have the lxml resource" do it "does not report offenses" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" uses_from_macos "libxml2" resource "not-lxml" do url "blah" sha256 "blah" end end RUBY end end context "when a formula has the lxml resource" do it "does not report offenses if the dependencies are present" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" uses_from_macos "libxml2" uses_from_macos "libxslt" resource "lxml" do url "blah" sha256 "blah" end end RUBY end it "reports offenses if missing a dependency" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" uses_from_macos "libsomethingelse" uses_from_macos "not_libxml2" resource "lxml" do ^^^^^^^^^^^^^^^ FormulaAudit/ResourceRequiresDependencies: Add `uses_from_macos` lines above for `"libxml2"` and `"libxslt"`. url "blah" sha256 "blah" end end RUBY end end context "when a formula does not have the pyyaml resource" do it "does not report offenses" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" uses_from_macos "libxml2" resource "not-pyyaml" do url "blah" sha256 "blah" end end RUBY end end context "when a formula has the pyyaml resource" do it "does not report offenses if the dependencies are present" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" depends_on "libyaml" resource "pyyaml" do url "blah" sha256 "blah" end end RUBY end it "reports offenses if missing a dependency" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" depends_on "not_libyaml" resource "pyyaml" do ^^^^^^^^^^^^^^^^^ FormulaAudit/ResourceRequiresDependencies: Add `depends_on` lines above for `"libyaml"`. url "blah" sha256 "blah" end end RUBY end end context "when a formula has multiple resources" do it "reports offenses for each resource that is missing a dependency" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh" uses_from_macos "one" uses_from_macos "two" depends_on "three" resource "lxml" do ^^^^^^^^^^^^^^^ FormulaAudit/ResourceRequiresDependencies: Add `uses_from_macos` lines above for `"libxml2"` and `"libxslt"`. url "blah" sha256 "blah" end resource "pyyaml" do ^^^^^^^^^^^^^^^^^ FormulaAudit/ResourceRequiresDependencies: Add `depends_on` lines above for `"libyaml"`. url "blah" sha256 "blah" end end RUBY 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/rubocops/lines_spec.rb
Library/Homebrew/test/rubocops/lines_spec.rb
# frozen_string_literal: true require "rubocops/lines" RSpec.describe RuboCop::Cop::FormulaAudit::Lines do subject(:cop) { described_class.new } context "when auditing deprecated special dependencies" do it "reports an offense when using depends_on :automake" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' depends_on :automake ^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Lines: :automake is deprecated. Usage should be "automake". end RUBY end it "reports an offense when using depends_on :autoconf" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' depends_on :autoconf ^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Lines: :autoconf is deprecated. Usage should be "autoconf". end RUBY end it "reports an offense when using depends_on :libtool" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' depends_on :libtool ^^^^^^^^^^^^^^^^^^^ FormulaAudit/Lines: :libtool is deprecated. Usage should be "libtool". end RUBY end it "reports an offense when using depends_on :apr" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' depends_on :apr ^^^^^^^^^^^^^^^ FormulaAudit/Lines: :apr is deprecated. Usage should be "apr-util". end RUBY end it "reports an offense when using depends_on :tex" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' depends_on :tex ^^^^^^^^^^^^^^^ FormulaAudit/Lines: :tex is deprecated. end RUBY 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/rubocops/no_fileutils_rmrf_spec.rb
Library/Homebrew/test/rubocops/no_fileutils_rmrf_spec.rb
# frozen_string_literal: true require "rubocops/no_fileutils_rmrf" RSpec.describe RuboCop::Cop::Homebrew::NoFileutilsRmrf do subject(:cop) { described_class.new } describe "rm_rf" do it "registers an offense" do expect_offense(<<~RUBY) rm_rf("path/to/directory") ^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG} FileUtils.rm_rf("path/to/directory") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG} RUBY end it "autocorrects" do corrected = autocorrect_source(<<~RUBY) rm_rf("path/to/directory") FileUtils.rm_rf("path/to/other/directory") RUBY expect(corrected).to eq(<<~RUBY) rm_r("path/to/directory") FileUtils.rm_r("path/to/other/directory") RUBY end end describe "rm_f" do it "registers an offense" do expect_offense(<<~RUBY) rm_f("path/to/directory") ^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG} FileUtils.rm_f("path/to/other/directory") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG} RUBY end it "autocorrects" do corrected = autocorrect_source(<<~RUBY) rm_f("path/to/directory") FileUtils.rm_f("path/to/other/directory") RUBY expect(corrected).to eq(<<~RUBY) rm("path/to/directory") FileUtils.rm("path/to/other/directory") RUBY end end describe "rmtree" do it "registers an offense" do expect_offense(<<~RUBY) rmtree("path/to/directory") ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG} other_dir = Pathname("path/to/other/directory") other_dir.rmtree ^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG} def buildpath Pathname("path/to/yet/another/directory") end buildpath.rmtree ^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG} (path/"here").rmtree ^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG} RUBY end it "autocorrects" do corrected = autocorrect_source(<<~RUBY) rmtree("path/to/directory") other_dir = Pathname("path/to/other/directory") other_dir.rmtree def buildpath Pathname("path/to/yet/another/directory") end buildpath.rmtree (path/"here").rmtree RUBY expect(corrected).to eq(<<~RUBY) rm_r("path/to/directory") other_dir = Pathname("path/to/other/directory") FileUtils.rm_r(other_dir) def buildpath Pathname("path/to/yet/another/directory") end FileUtils.rm_r(buildpath) FileUtils.rm_r(path/"here") RUBY 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/rubocops/dependency_order_spec.rb
Library/Homebrew/test/rubocops/dependency_order_spec.rb
# frozen_string_literal: true require "rubocops/dependency_order" RSpec.describe RuboCop::Cop::FormulaAudit::DependencyOrder do subject(:cop) { described_class.new } context "when auditing `uses_from_macos`" do it "reports and corrects incorrectly ordered conditional dependencies" do expect_offense(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" uses_from_macos "apple" if build.with? "foo" uses_from_macos "foo" => :optional ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: `dependency "foo"` (line 5) should be put before `dependency "apple"` (line 4) end RUBY expect_correction(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" uses_from_macos "foo" => :optional uses_from_macos "apple" if build.with? "foo" end RUBY end it "reports and corrects incorrectly ordered alphabetical dependencies" do expect_offense(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" uses_from_macos "foo" uses_from_macos "bar" ^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: `dependency "bar"` (line 5) should be put before `dependency "foo"` (line 4) end RUBY expect_correction(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" uses_from_macos "bar" uses_from_macos "foo" end RUBY end it "reports and corrects incorrectly ordered dependencies that are Requirements" do expect_offense(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" uses_from_macos FooRequirement uses_from_macos "bar" ^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: `dependency "bar"` (line 5) should be put before `dependency "FooRequirement"` (line 4) end RUBY expect_correction(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" uses_from_macos "bar" uses_from_macos FooRequirement end RUBY end it "reports and corrects wrong conditional order within a spec block" do expect_offense(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" head do uses_from_macos "apple" if build.with? "foo" uses_from_macos "bar" ^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: `dependency "bar"` (line 6) should be put before `dependency "apple"` (line 5) uses_from_macos "foo" => :optional ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: `dependency "foo"` (line 7) should be put before `dependency "apple"` (line 5) end uses_from_macos "apple" if build.with? "foo" uses_from_macos "foo" => :optional ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: `dependency "foo"` (line 10) should be put before `dependency "apple"` (line 9) end RUBY expect_correction(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" head do uses_from_macos "bar" uses_from_macos "foo" => :optional uses_from_macos "apple" if build.with? "foo" end uses_from_macos "foo" => :optional uses_from_macos "apple" if build.with? "foo" end RUBY end it "reports no offenses if correct order for multiple tags" do expect_no_offenses(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" uses_from_macos "bar" => [:build, :test] uses_from_macos "foo" => :build uses_from_macos "apple" end RUBY end it "reports and corrects wrong conditional order within a system block" do expect_offense(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" on_arm do uses_from_macos "apple" if build.with? "foo" uses_from_macos "bar" ^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: `dependency "bar"` (line 6) should be put before `dependency "apple"` (line 5) uses_from_macos "foo" => :optional ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: `dependency "foo"` (line 7) should be put before `dependency "apple"` (line 5) end end RUBY expect_correction(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" on_arm do uses_from_macos "bar" uses_from_macos "foo" => :optional uses_from_macos "apple" if build.with? "foo" end end RUBY end end context "when auditing `depends_on`" do it "reports and corrects incorrectly ordered conditional dependencies" do expect_offense(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" depends_on "apple" if build.with? "foo" depends_on "foo" => :optional ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: `dependency "foo"` (line 5) should be put before `dependency "apple"` (line 4) end RUBY expect_correction(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" depends_on "foo" => :optional depends_on "apple" if build.with? "foo" end RUBY end it "reports and corrects incorrectly ordered alphabetical dependencies" do expect_offense(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" depends_on "foo" depends_on "bar" ^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: `dependency "bar"` (line 5) should be put before `dependency "foo"` (line 4) end RUBY expect_correction(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" depends_on "bar" depends_on "foo" end RUBY end it "reports and corrects incorrectly ordered dependencies that are Requirements" do expect_offense(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" depends_on FooRequirement depends_on "bar" ^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: `dependency "bar"` (line 5) should be put before `dependency "FooRequirement"` (line 4) end RUBY expect_correction(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" depends_on "bar" depends_on FooRequirement end RUBY end it "reports and corrects wrong conditional order within a spec block" do expect_offense(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" head do depends_on "apple" if build.with? "foo" depends_on "bar" ^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: `dependency "bar"` (line 6) should be put before `dependency "apple"` (line 5) depends_on "foo" => :optional ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: `dependency "foo"` (line 7) should be put before `dependency "apple"` (line 5) end depends_on "apple" if build.with? "foo" depends_on "foo" => :optional ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: `dependency "foo"` (line 10) should be put before `dependency "apple"` (line 9) end RUBY expect_correction(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" head do depends_on "bar" depends_on "foo" => :optional depends_on "apple" if build.with? "foo" end depends_on "foo" => :optional depends_on "apple" if build.with? "foo" end RUBY end it "reports no offenses if correct order for multiple tags" do expect_no_offenses(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" depends_on "bar" => [:build, :test] depends_on "foo" => :build depends_on "apple" end RUBY end it "reports and corrects wrong conditional order within a system block" do expect_offense(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" on_linux do depends_on "apple" if build.with? "foo" depends_on "bar" ^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: `dependency "bar"` (line 6) should be put before `dependency "apple"` (line 5) depends_on "foo" => :optional ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: `dependency "foo"` (line 7) should be put before `dependency "apple"` (line 5) end end RUBY expect_correction(<<~RUBY) class Foo < Formula homepage "https://brew.sh" url "https://brew.sh/foo-1.0.tgz" on_linux do depends_on "bar" depends_on "foo" => :optional depends_on "apple" if build.with? "foo" end end RUBY 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/rubocops/shell_commands_spec.rb
Library/Homebrew/test/rubocops/shell_commands_spec.rb
# frozen_string_literal: true require "rubocops/shell_commands" RSpec.describe RuboCop::Cop::Homebrew::ShellCommands do subject(:cop) { described_class.new } context "when auditing shell commands" do it "reports and corrects an offense when `system` arguments should be separated" do expect_offense(<<~RUBY) class Foo < Formula def install system "foo bar" ^^^^^^^^^ Homebrew/ShellCommands: Separate `system` commands into `"foo", "bar"` end end RUBY expect_correction(<<~RUBY) class Foo < Formula def install system "foo", "bar" end end RUBY end it "reports and corrects an offense when `system` arguments involving interpolation should be separated" do expect_offense(<<~'RUBY') class Foo < Formula def install system "#{bin}/foo bar" ^^^^^^^^^^^^^^^^ Homebrew/ShellCommands: Separate `system` commands into `"#{bin}/foo", "bar"` end end RUBY expect_correction(<<~'RUBY') class Foo < Formula def install system "#{bin}/foo", "bar" end end RUBY end it "reports no offenses when `system` with metacharacter arguments are called" do expect_no_offenses(<<~RUBY) class Foo < Formula def install system "foo bar > baz" end end RUBY end it "reports no offenses when trailing arguments to `system` are unseparated" do expect_no_offenses(<<~RUBY) class Foo < Formula def install system "foo", "bar baz" end end RUBY end it "reports no offenses when `Utils.popen` arguments are unseparated" do expect_no_offenses(<<~RUBY) class Foo < Formula def install Utils.popen("foo bar") end end RUBY end it "reports and corrects an offense when `Utils.popen_read` arguments are unseparated" do expect_offense(<<~RUBY) class Foo < Formula def install Utils.popen_read("foo bar") ^^^^^^^^^ Homebrew/ShellCommands: Separate `Utils.popen_read` commands into `"foo", "bar"` end end RUBY expect_correction(<<~RUBY) class Foo < Formula def install Utils.popen_read("foo", "bar") end end RUBY end it "reports and corrects an offense when `Utils.safe_popen_read` arguments are unseparated" do expect_offense(<<~RUBY) class Foo < Formula def install Utils.safe_popen_read("foo bar") ^^^^^^^^^ Homebrew/ShellCommands: Separate `Utils.safe_popen_read` commands into `"foo", "bar"` end end RUBY expect_correction(<<~RUBY) class Foo < Formula def install Utils.safe_popen_read("foo", "bar") end end RUBY end it "reports and corrects an offense when `Utils.popen_write` arguments are unseparated" do expect_offense(<<~RUBY) class Foo < Formula def install Utils.popen_write("foo bar") ^^^^^^^^^ Homebrew/ShellCommands: Separate `Utils.popen_write` commands into `"foo", "bar"` end end RUBY expect_correction(<<~RUBY) class Foo < Formula def install Utils.popen_write("foo", "bar") end end RUBY end it "reports and corrects an offense when `Utils.safe_popen_write` arguments are unseparated" do expect_offense(<<~RUBY) class Foo < Formula def install Utils.safe_popen_write("foo bar") ^^^^^^^^^ Homebrew/ShellCommands: Separate `Utils.safe_popen_write` commands into `"foo", "bar"` end end RUBY expect_correction(<<~RUBY) class Foo < Formula def install Utils.safe_popen_write("foo", "bar") end end RUBY end it "reports and corrects an offense when `Utils.popen_read` arguments with interpolation are unseparated" do expect_offense(<<~'RUBY') class Foo < Formula def install Utils.popen_read("#{bin}/foo bar") ^^^^^^^^^^^^^^^^ Homebrew/ShellCommands: Separate `Utils.popen_read` commands into `"#{bin}/foo", "bar"` end end RUBY expect_correction(<<~'RUBY') class Foo < Formula def install Utils.popen_read("#{bin}/foo", "bar") end end RUBY end it "reports no offenses when `Utils.popen_read` arguments with metacharacters are unseparated" do expect_no_offenses(<<~RUBY) class Foo < Formula def install Utils.popen_read("foo bar > baz") end end RUBY end it "reports no offenses when trailing arguments to `Utils.popen_read` are unseparated" do expect_no_offenses(<<~RUBY) class Foo < Formula def install Utils.popen_read("foo", "bar baz") end end RUBY end it "reports and corrects an offense when `Utils.popen_read` arguments are unseparated after a shell env" do expect_offense(<<~RUBY) class Foo < Formula def install Utils.popen_read({ "SHELL" => "bash"}, "foo bar") ^^^^^^^^^ Homebrew/ShellCommands: Separate `Utils.popen_read` commands into `"foo", "bar"` end end RUBY expect_correction(<<~RUBY) class Foo < Formula def install Utils.popen_read({ "SHELL" => "bash"}, "foo", "bar") end end RUBY 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/rubocops/no_autobump.rb
Library/Homebrew/test/rubocops/no_autobump.rb
# frozen_string_literal: true require "rubocops/no_autobump" RSpec.describe RuboCop::Cop::FormulaAudit::NoAutobump do subject(:cop) { described_class.new } it "reports no offenses if `reason` is acceptable" do expect_no_offenses(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' no_autobump! because: "some reason" end RUBY end it "reports no offenses if `reason` is acceptable as a symbol" do expect_no_offenses(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' no_autobump! because: :bumped_by_upstream end RUBY end it "reports an offense if `reason` is absent" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' no_autobump! ^^^^^^^^^^^^ FormulaAudit/NoAutobumpReason: Add a reason for exclusion from autobump: `no_autobump! because: "..."` end RUBY end it "reports an offense is `reason` should not be set manually" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' no_autobump! because: :extract_plist ^^^^^^^^^^^^^^ FormulaAudit/NoAutobumpReason: `:extract_plist` reason should not be used directly end RUBY end it "reports and corrects an offense if `reason` starts with 'it'" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' no_autobump! because: "it does something" ^^^^^^^^^^^^^^^^^^^ FormulaAudit/NoAutobumpReason: Do not start the reason with `it` end RUBY expect_correction(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' no_autobump! because: "does something" end RUBY end it "reports and corrects an offense if `reason` ends with a period" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' no_autobump! because: "does something." ^^^^^^^^^^^^^^^^^ FormulaAudit/NoAutobumpReason: Do not end the reason with a punctuation mark end RUBY expect_correction(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' no_autobump! because: "does something" end RUBY end it "reports and corrects an offense if `reason` ends with an exclamation point" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' no_autobump! because: "does something!" ^^^^^^^^^^^^^^^^^ FormulaAudit/NoAutobumpReason: Do not end the reason with a punctuation mark end RUBY expect_correction(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' no_autobump! because: "does something" end RUBY end it "reports and corrects an offense if `reason` ends with a question mark" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' no_autobump! because: "does something?" ^^^^^^^^^^^^^^^^^ FormulaAudit/NoAutobumpReason: Do not end the reason with a punctuation mark end RUBY expect_correction(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' no_autobump! because: "does something" end RUBY 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/rubocops/conflicts_spec.rb
Library/Homebrew/test/rubocops/conflicts_spec.rb
# frozen_string_literal: true require "rubocops/conflicts" RSpec.describe RuboCop::Cop::FormulaAudit::Conflicts do subject(:cop) { described_class.new } context "when auditing `conflicts_with`" do it "reports and corrects an offense if reason is capitalized" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") class Foo < Formula url "https://brew.sh/foo-1.0.tgz" conflicts_with "bar", :because => "Reason" ^^^^^^^^ FormulaAudit/Conflicts: 'Reason' from the `conflicts_with` reason should be 'reason'. conflicts_with "baz", :because => "Foo is the formula name which does not require downcasing" end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" conflicts_with "bar", :because => "reason" conflicts_with "baz", :because => "Foo is the formula name which does not require downcasing" end RUBY end it "reports and corrects an offense if reason ends with a period" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" conflicts_with "bar", "baz", :because => "reason." ^^^^^^^^^ FormulaAudit/Conflicts: `conflicts_with` reason should not end with a period. end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" conflicts_with "bar", "baz", :because => "reason" end RUBY end it "reports an offense if it is present in a versioned formula" do expect_offense(<<~RUBY, "/homebrew-core/Formula/foo@2.0.rb") class FooAT20 < Formula url 'https://brew.sh/foo-2.0.tgz' conflicts_with "mysql", "mariadb" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Conflicts: Versioned formulae should not use `conflicts_with`. Use `keg_only :versioned_formula` instead. end RUBY end it "reports no offenses if it is not present" do expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/foo@2.0.rb") class FooAT20 < Formula url 'https://brew.sh/foo-2.0.tgz' homepage "https://brew.sh" end RUBY 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/rubocops/homepage_spec.rb
Library/Homebrew/test/rubocops/homepage_spec.rb
# frozen_string_literal: true require "rubocops/homepage" RSpec.describe RuboCop::Cop::FormulaAudit::Homepage do subject(:cop) { described_class.new } context "when auditing homepage" do it "reports an offense when there is no homepage" do expect_offense(<<~RUBY) class Foo < Formula ^^^^^^^^^^^^^^^^^^^ FormulaAudit/Homepage: Formula should have a homepage. url 'https://brew.sh/foo-1.0.tgz' end RUBY end it "reports an offense when the homepage is not HTTP or HTTPS" do expect_offense(<<~RUBY) class Foo < Formula homepage "ftp://brew.sh/foo" ^^^^^^^^^^^^^^^^^^^ FormulaAudit/Homepage: The `homepage` should start with http or https. url "https://brew.sh/foo-1.0.tgz" end RUBY end it "reports an offense for freedesktop.org wiki pages" do expect_offense(<<~RUBY) class Foo < Formula homepage "http://www.freedesktop.org/wiki/bar" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Homepage: Freedesktop homepages should be styled: https://wiki.freedesktop.org/project_name url "https://brew.sh/foo-1.0.tgz" end RUBY end it "reports an offense for freedesktop.org software wiki pages" do expect_offense(<<~RUBY) class Foo < Formula homepage "http://www.freedesktop.org/wiki/Software/baz" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Homepage: Freedesktop homepages should be styled: https://wiki.freedesktop.org/www/Software/project_name url "https://brew.sh/foo-1.0.tgz" end RUBY end it "reports and corrects Google Code homepages" do expect_offense(<<~RUBY) class Foo < Formula homepage "https://code.google.com/p/qux" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Homepage: Google Code homepages should end with a slash url "https://brew.sh/foo-1.0.tgz" end RUBY expect_correction(<<~RUBY) class Foo < Formula homepage "https://code.google.com/p/qux/" url "https://brew.sh/foo-1.0.tgz" end RUBY end it "reports and corrects GitHub homepages" do expect_offense(<<~RUBY) class Foo < Formula homepage "https://github.com/foo/bar.git" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Homepage: GitHub homepages should not end with .git url "https://brew.sh/foo-1.0.tgz" end RUBY expect_correction(<<~RUBY) class Foo < Formula homepage "https://github.com/foo/bar" url "https://brew.sh/foo-1.0.tgz" end RUBY end describe "for SourceForge" do let(:correct_formula) do <<~RUBY class Foo < Formula homepage "https://foo.sourceforge.io/" url "https://brew.sh/foo-1.0.tgz" end RUBY end it "reports and corrects [1]" do expect_offense(<<~RUBY) class Foo < Formula homepage "http://foo.sourceforge.net/" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Homepage: SourceForge homepages should be: https://foo.sourceforge.io/ url "https://brew.sh/foo-1.0.tgz" end RUBY expect_correction(correct_formula) end it "reports and corrects [2]" do expect_offense(<<~RUBY) class Foo < Formula homepage "http://foo.sourceforge.net" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Homepage: SourceForge homepages should be: https://foo.sourceforge.io/ url "https://brew.sh/foo-1.0.tgz" end RUBY expect_correction(correct_formula) end it "reports and corrects [3]" do expect_offense(<<~RUBY) class Foo < Formula homepage "http://foo.sf.net/" ^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Homepage: SourceForge homepages should be: https://foo.sourceforge.io/ url "https://brew.sh/foo-1.0.tgz" end RUBY expect_correction(correct_formula) end end it "reports and corrects readthedocs.org pages" do expect_offense(<<~RUBY) class Foo < Formula homepage "https://foo.readthedocs.org" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Homepage: Readthedocs homepages should be: https://foo.readthedocs.io url "https://brew.sh/foo-1.0.tgz" end RUBY expect_correction(<<~RUBY) class Foo < Formula homepage "https://foo.readthedocs.io" url "https://brew.sh/foo-1.0.tgz" end RUBY end it "reports an offense for HTTP homepages" do formula_homepages = { "sf" => "http://foo.sourceforge.io/", "corge" => "http://savannah.nongnu.org/corge", "grault" => "http://grault.github.io/", "garply" => "http://www.gnome.org/garply", "waldo" => "http://www.gnu.org/waldo", "dotgit" => "http://github.com/quux", } formula_homepages.each do |name, homepage| source = <<~RUBY class #{name.capitalize} < Formula homepage "#{homepage}" url "https://brew.sh/#{name}-1.0.tgz" end RUBY expected_offenses = [{ message: "FormulaAudit/Homepage: Please use https:// for #{homepage}", severity: :convention, line: 2, column: 11, source:, }] expected_offenses.zip([inspect_source(source).last]).each do |expected, actual| expect(actual.message).to eq(expected[:message]) expect(actual.severity).to eq(expected[:severity]) expect(actual.line).to eq(expected[:line]) expect(actual.column).to eq(expected[:column]) end end end 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/rubocops/options_spec.rb
Library/Homebrew/test/rubocops/options_spec.rb
# frozen_string_literal: true require "rubocops/options" RSpec.describe RuboCop::Cop::FormulaAudit::Options do subject(:cop) { described_class.new } context "when auditing options" do it "reports an offense when using bad option names" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' option "examples", "with-examples" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Options: Options should begin with `with` or `without`. Migrate '--examples' with `deprecated_option`. end RUBY end it "reports an offense when using `without-check` option names" do expect_offense(<<~RUBY) class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' option "without-check" ^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Options: Use '--without-test' instead of '--without-check'. Migrate '--without-check' with `deprecated_option`. end RUBY end it "reports an offense when using `deprecated_option` in homebrew/core" do expect_offense(<<~RUBY, "/homebrew-core/") class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' deprecated_option "examples" => "with-examples" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Options: Formulae in homebrew/core should not use `deprecated_option`. end RUBY end it "reports an offense when using `option` in homebrew/core" do expect_offense(<<~RUBY, "/homebrew-core/") class Foo < Formula url 'https://brew.sh/foo-1.0.tgz' option "with-examples" ^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/Options: Formulae in homebrew/core should not use `option`. end RUBY 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/rubocops/bottle/bottle_order_spec.rb
Library/Homebrew/test/rubocops/bottle/bottle_order_spec.rb
# frozen_string_literal: true require "rubocops/bottle" RSpec.describe RuboCop::Cop::FormulaAudit::BottleOrder do subject(:cop) { described_class.new } it "reports no offenses for `bottle :unneeded`" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle :unneeded end RUBY end it "reports no offenses for a properly ordered bottle block" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do rebuild 4 sha256 arm64_something_else: "aaaaaaaa" sha256 arm64_big_sur: "aaaaaaaa" sha256 big_sur: "faceb00c" sha256 catalina: "deadbeef" end end RUBY expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do rebuild 4 sha256 cellar: :any, arm64_something_else: "aaaaaaaa" sha256 cellar: :any_skip_relocation, arm64_big_sur: "aaaaaaaa" sha256 cellar: "/usr/local/Cellar", big_sur: "faceb00c" sha256 catalina: "deadbeef" end end RUBY end it "reports no offenses for a properly ordered bottle block with a single bottle" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do sha256 big_sur: "faceb00c" end end RUBY expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do sha256 cellar: :any, big_sur: "faceb00c" end end RUBY end it "reports no offenses for a properly ordered bottle block with only arm/intel bottles" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do rebuild 4 sha256 arm64_catalina: "aaaaaaaa" sha256 arm64_big_sur: "aaaaaaaa" end end RUBY expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do rebuild 4 sha256 arm64_big_sur: "aaaaaaaa" end end RUBY expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do rebuild 4 sha256 big_sur: "faceb00c" sha256 catalina: "deadbeef" end end RUBY expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do rebuild 4 sha256 big_sur: "faceb00c" end end RUBY end it "reports and corrects arm bottles below intel bottles" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do ^^^^^^^^^ FormulaAudit/BottleOrder: ARM bottles should be listed before Intel bottles rebuild 4 sha256 big_sur: "faceb00c" sha256 catalina: "deadbeef" sha256 arm64_big_sur: "aaaaaaaa" end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do rebuild 4 sha256 arm64_big_sur: "aaaaaaaa" sha256 big_sur: "faceb00c" sha256 catalina: "deadbeef" end end RUBY end it "reports and corrects multiple arm bottles below intel bottles" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do ^^^^^^^^^ FormulaAudit/BottleOrder: ARM bottles should be listed before Intel bottles rebuild 4 sha256 big_sur: "faceb00c" sha256 arm64_catalina: "aaaaaaaa" sha256 catalina: "deadbeef" sha256 arm64_big_sur: "aaaaaaaa" end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do rebuild 4 sha256 arm64_catalina: "aaaaaaaa" sha256 arm64_big_sur: "aaaaaaaa" sha256 big_sur: "faceb00c" sha256 catalina: "deadbeef" end end RUBY end it "reports and corrects arm bottles with cellars below intel bottles" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do ^^^^^^^^^ FormulaAudit/BottleOrder: ARM bottles should be listed before Intel bottles rebuild 4 sha256 cellar: "/usr/local/Cellar", big_sur: "faceb00c" sha256 catalina: "deadbeef" sha256 cellar: :any, arm64_big_sur: "aaaaaaaa" sha256 cellar: :any_skip_relocation, arm64_catalina: "aaaaaaaa" end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do rebuild 4 sha256 cellar: :any, arm64_big_sur: "aaaaaaaa" sha256 cellar: :any_skip_relocation, arm64_catalina: "aaaaaaaa" sha256 cellar: "/usr/local/Cellar", big_sur: "faceb00c" sha256 catalina: "deadbeef" end end RUBY end it "reports and corrects arm bottles below intel bottles with old bottle syntax" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do ^^^^^^^^^ FormulaAudit/BottleOrder: ARM bottles should be listed before Intel bottles cellar :any sha256 "faceb00c" => :big_sur sha256 "aaaaaaaa" => :arm64_big_sur sha256 "aaaaaaaa" => :arm64_catalina sha256 "deadbeef" => :catalina end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do cellar :any sha256 "aaaaaaaa" => :arm64_big_sur sha256 "aaaaaaaa" => :arm64_catalina sha256 "faceb00c" => :big_sur sha256 "deadbeef" => :catalina end end RUBY 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/rubocops/bottle/bottle_format_spec.rb
Library/Homebrew/test/rubocops/bottle/bottle_format_spec.rb
# frozen_string_literal: true require "rubocops/bottle" RSpec.describe RuboCop::Cop::FormulaAudit::BottleFormat do subject(:cop) { described_class.new } it "reports no offenses for `bottle :unneeded`" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle :unneeded end RUBY end it "reports and corrects old `sha256` syntax in `bottle` block without cellars" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do sha256 "faceb00c" => :big_sur ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/BottleFormat: `sha256` should use new syntax end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do sha256 big_sur: "faceb00c" end end RUBY expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do rebuild 4 sha256 "faceb00c" => :big_sur ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/BottleFormat: `sha256` should use new syntax sha256 "deadbeef" => :catalina ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/BottleFormat: `sha256` should use new syntax end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do rebuild 4 sha256 big_sur: "faceb00c" sha256 catalina: "deadbeef" end end RUBY end it "reports and corrects old `sha256` syntax in `bottle` block with cellars" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do cellar :any ^^^^^^^^^^^ FormulaAudit/BottleFormat: `cellar` should be a parameter to `sha256` rebuild 4 sha256 "faceb00c" => :big_sur ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/BottleFormat: `sha256` should use new syntax sha256 "deadbeef" => :catalina ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/BottleFormat: `sha256` should use new syntax end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do rebuild 4 sha256 cellar: :any, big_sur: "faceb00c" sha256 cellar: :any, catalina: "deadbeef" end end RUBY expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do cellar :any ^^^^^^^^^^^ FormulaAudit/BottleFormat: `cellar` should be a parameter to `sha256` sha256 "faceb00c" => :big_sur ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/BottleFormat: `sha256` should use new syntax end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do sha256 cellar: :any, big_sur: "faceb00c" end end RUBY expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do cellar "/usr/local/Cellar" ^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/BottleFormat: `cellar` should be a parameter to `sha256` rebuild 4 sha256 "faceb00c" => :big_sur ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/BottleFormat: `sha256` should use new syntax sha256 "deadbeef" => :catalina ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/BottleFormat: `sha256` should use new syntax end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do rebuild 4 sha256 cellar: "/usr/local/Cellar", big_sur: "faceb00c" sha256 cellar: "/usr/local/Cellar", catalina: "deadbeef" end end RUBY 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/rubocops/bottle/bottle_tag_indentation_spec.rb
Library/Homebrew/test/rubocops/bottle/bottle_tag_indentation_spec.rb
# frozen_string_literal: true require "rubocops/bottle" RSpec.describe RuboCop::Cop::FormulaAudit::BottleTagIndentation do subject(:cop) { described_class.new } it "reports no offenses for `bottle :unneeded`" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle :unneeded end RUBY end it "reports no offenses for `bottle` blocks without cellars" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do rebuild 4 sha256 arm64_big_sur: "aaaaaaaa" sha256 big_sur: "faceb00c" sha256 catalina: "deadbeef" end end RUBY expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do sha256 big_sur: "faceb00c" end end RUBY end it "reports no offenses for properly aligned tags in `bottle` blocks with cellars" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do rebuild 4 sha256 cellar: :any, arm64_big_sur: "aaaaaaaa" sha256 cellar: "/usr/local/Cellar", big_sur: "faceb00c" sha256 catalina: "deadbeef" end end RUBY expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do sha256 cellar: :any, arm64_big_sur: "aaaaaaaa" end end RUBY end it "reports and corrects misaligned tags in `bottle` block with cellars" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do rebuild 4 sha256 cellar: :any, arm64_big_sur: "aaaaaaaa" ^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/BottleTagIndentation: Align bottle tags sha256 cellar: "/usr/local/Cellar", big_sur: "faceb00c" sha256 catalina: "deadbeef" ^^^^^^^^^^^^^^^^^^^^ FormulaAudit/BottleTagIndentation: Align bottle tags end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do rebuild 4 sha256 cellar: :any, arm64_big_sur: "aaaaaaaa" sha256 cellar: "/usr/local/Cellar", big_sur: "faceb00c" sha256 catalina: "deadbeef" end end RUBY 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/rubocops/bottle/bottle_digest_indentation_spec.rb
Library/Homebrew/test/rubocops/bottle/bottle_digest_indentation_spec.rb
# frozen_string_literal: true require "rubocops/bottle" RSpec.describe RuboCop::Cop::FormulaAudit::BottleDigestIndentation do subject(:cop) { described_class.new } it "reports no offenses for `bottle :unneeded`" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle :unneeded end RUBY end it "reports no offenses for properly aligned digests in `bottle` blocks without cellars" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do rebuild 4 sha256 arm64_big_sur: "aaaaaaaa" sha256 big_sur: "faceb00c" sha256 catalina: "deadbeef" end end RUBY expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do sha256 arm64_big_sur: "aaaaaaaa" end end RUBY end it "reports no offenses for properly aligned tags in `bottle` blocks with cellars" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do rebuild 4 sha256 cellar: :any, arm64_big_sur: "aaaaaaaa" sha256 cellar: "/usr/local/Cellar", big_sur: "faceb00c" sha256 catalina: "deadbeef" end end RUBY expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do sha256 cellar: :any, arm64_big_sur: "aaaaaaaa" end end RUBY end it "reports and corrects misaligned digests in `bottle` block" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do rebuild 4 sha256 arm64_big_sur: "aaaaaaaa" sha256 big_sur: "faceb00c" ^^^^^^^^^^ FormulaAudit/BottleDigestIndentation: Align bottle digests sha256 catalina: "deadbeef" ^^^^^^^^^^ FormulaAudit/BottleDigestIndentation: Align bottle digests end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do rebuild 4 sha256 arm64_big_sur: "aaaaaaaa" sha256 big_sur: "faceb00c" sha256 catalina: "deadbeef" end end RUBY end it "reports and corrects misaligned digests in `bottle` block with cellars" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do rebuild 4 sha256 cellar: :any, arm64_big_sur: "aaaaaaaa" sha256 cellar: "/usr/local/Cellar", big_sur: "faceb00c" ^^^^^^^^^^ FormulaAudit/BottleDigestIndentation: Align bottle digests sha256 catalina: "deadbeef" ^^^^^^^^^^ FormulaAudit/BottleDigestIndentation: Align bottle digests end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" bottle do rebuild 4 sha256 cellar: :any, arm64_big_sur: "aaaaaaaa" sha256 cellar: "/usr/local/Cellar", big_sur: "faceb00c" sha256 catalina: "deadbeef" end end RUBY 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/rubocops/livecheck/url_provided_spec.rb
Library/Homebrew/test/rubocops/livecheck/url_provided_spec.rb
# frozen_string_literal: true require "rubocops/livecheck" RSpec.describe RuboCop::Cop::FormulaAudit::LivecheckUrlProvided do subject(:cop) { described_class.new } it "reports an offense when a `url` is not specified in a `livecheck` block" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" livecheck do ^^^^^^^^^^^^ FormulaAudit/LivecheckUrlProvided: A `url` should be provided when `regex` or `strategy` are used. regex(%r{href=.*?/formula[._-]v?(\\d+(?:\\.\\d+)+)\\.t}i) end end RUBY expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" livecheck do ^^^^^^^^^^^^ FormulaAudit/LivecheckUrlProvided: A `url` should be provided when `regex` or `strategy` are used. strategy :page_match end end RUBY end it "reports no offenses when a `url` and `regex` are specified in the `livecheck` block" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" livecheck do url :stable regex(%r{href=.*?/formula[._-]v?(\\d+(?:\\.\\d+)+)\\.t}i) end end RUBY end it "reports no offenses when a `url` and `strategy` are specified in the `livecheck` block" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" livecheck do url :stable strategy :page_match end end RUBY 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/rubocops/livecheck/skip_spec.rb
Library/Homebrew/test/rubocops/livecheck/skip_spec.rb
# frozen_string_literal: true require "rubocops/livecheck" RSpec.describe RuboCop::Cop::FormulaAudit::LivecheckSkip do subject(:cop) { described_class.new } it "reports an offense when a skipped formula's `livecheck` block contains other information" do expect_offense(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" livecheck do ^^^^^^^^^^^^ FormulaAudit/LivecheckSkip: Skipped formulae must not contain other livecheck information. skip "Not maintained" url :stable end end RUBY expect_correction(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" livecheck do skip "Not maintained" end end RUBY end it "reports no offenses when a skipped formula's `livecheck` block contains no other information" do expect_no_offenses(<<~RUBY) class Foo < Formula url "https://brew.sh/foo-1.0.tgz" livecheck do skip "Not maintained" end end RUBY end end
ruby
BSD-2-Clause
fe0a384e3a04605192726c149570fbe33a8996b0
2026-01-04T15:37:27.366412Z
false