brew/Library/Homebrew/test/rubocops/conflicts_spec.rb

89 lines
2.7 KiB
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: false
# frozen_string_literal: true
require "rubocops/conflicts"
describe RuboCop::Cop::FormulaAudit::Conflicts do
subject(:cop) { described_class.new }
context "When auditing conflicts_with" do
it "conflicts_with 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"
^^^^^^^^ '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
end
it "conflicts_with 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."
^^^^^^^^^ `conflicts_with` reason should not end with a period.
end
RUBY
end
it "conflicts_with in a versioned formula" do
2017-10-21 03:12:50 +02:00
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"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Versioned formulae should not use `conflicts_with`. Use `keg_only :versioned_formula` instead.
end
2017-10-21 03:12:50 +02:00
RUBY
end
it "no conflicts_with" do
2017-10-21 03:12:50 +02:00
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
it "auto-corrects capitalized reason" do
source = <<~RUBY
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
conflicts_with "bar", :because => "Reason"
end
2017-10-21 03:12:50 +02:00
RUBY
corrected_source = <<~RUBY
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
conflicts_with "bar", :because => "reason"
end
RUBY
new_source = autocorrect_source(source)
expect(new_source).to eq(corrected_source)
end
it "auto-corrects trailing period" do
source = <<~RUBY
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
conflicts_with "bar", :because => "reason."
end
RUBY
corrected_source = <<~RUBY
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
conflicts_with "bar", :because => "reason"
end
RUBY
new_source = autocorrect_source(source)
expect(new_source).to eq(corrected_source)
end
end
end