style: add tests for provided_by_macos and style_exceptions

This commit is contained in:
Rylan Polster 2020-11-30 18:11:17 -05:00
parent f8ff0f465f
commit 0c41d374c9

View File

@ -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