Add tests

This commit is contained in:
fn ⌃ ⌥ 2022-08-02 23:04:28 -07:00
parent d5f949e60b
commit b5a6f90cd8

View File

@ -114,6 +114,34 @@ describe RuboCop::Cop::FormulaAudit::DependencyOrder do
end end
RUBY RUBY
end 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"
^^^^^^^^^^^^^^^^^^^^^ dependency "bar" (line 6) should be put before dependency "apple" (line 5)
uses_from_macos "foo" => :optional
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 end
context "when auditing `depends_on`" do context "when auditing `depends_on`" do
@ -224,5 +252,33 @@ describe RuboCop::Cop::FormulaAudit::DependencyOrder do
end end
RUBY RUBY
end 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"
^^^^^^^^^^^^^^^^ dependency "bar" (line 6) should be put before dependency "apple" (line 5)
depends_on "foo" => :optional
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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
end end