From 0c41d374c900fa7b495bf2e38e376286b6bb6dc9 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Mon, 30 Nov 2020 18:11:17 -0500 Subject: [PATCH] style: add tests for provided_by_macos and style_exceptions --- .../test/rubocops/provided_by_macos_spec.rb | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Library/Homebrew/test/rubocops/provided_by_macos_spec.rb diff --git a/Library/Homebrew/test/rubocops/provided_by_macos_spec.rb b/Library/Homebrew/test/rubocops/provided_by_macos_spec.rb new file mode 100644 index 0000000000..e2c331cc87 --- /dev/null +++ b/Library/Homebrew/test/rubocops/provided_by_macos_spec.rb @@ -0,0 +1,61 @@ +# typed: false +# frozen_string_literal: true + +require "rubocops/uses_from_macos" + +describe RuboCop::Cop::FormulaAudit::ProvidedByMacos do + subject(:cop) { described_class.new } + + let(:path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" } + + before do + path.mkpath + (path/"style_exceptions").mkpath + end + + def setup_style_exceptions + (path/"style_exceptions/provided_by_macos_formulae.json").write <<~JSON + [ "foo", "bar" ] + JSON + end + + it "fails for formulae not in provided_by_macos_formulae list" do + setup_style_exceptions + + expect_offense(<<~RUBY, "#{path}/Formula/baz.rb") + class Baz < Formula + url "https://brew.sh/baz-1.0.tgz" + homepage "https://brew.sh" + + keg_only :provided_by_macos + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Formulae that are `keg_only :provided_by_macos` should be added to `style_exceptions/provided_by_macos_formulae.json` + end + RUBY + end + + it "succeeds for formulae in provided_by_macos_formulae list" do + setup_style_exceptions + + expect_no_offenses(<<~RUBY, "#{path}/Formula/foo.rb") + class Foo < Formula + url "https://brew.sh/foo-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 + setup_style_exceptions + + expect_no_offenses(<<~RUBY, "#{path}/Formula/foo.rb") + class Baz < Formula + url "https://brew.sh/foo-1.0.tgz" + homepage "https://brew.sh" + + keg_only :versioned_formula + end + RUBY + end +end