brew/Library/Homebrew/test/rubocops/components_order_spec.rb
Claudia 5be80a78f6
Use Homebrew-controlled domain for Cask dummy URLs
In a number of Cask specs, the value of the `homepage` stanza is currently set
to https://example.com. As of 2018-11-28, the TLS certificate served by
example.com seems to be expired, possibly due to an oversight on ICANN’s side.

While the certificate is certainly going to be renewed soon, it would be
desirable for Homebrew’s test result to be less dependent on ICANN’s actions.
This commit changes the homepages of all test Casks to http://brew.sh, whose
domain and TLS certificate are both controlled by Homebrew.
2018-11-28 20:51:55 +01:00

113 lines
2.9 KiB
Ruby

require "rubocops/components_order"
describe RuboCop::Cop::FormulaAudit::ComponentsOrder do
subject(:cop) { described_class.new }
context "When auditing formula components order" do
it "When url precedes homepage" do
expect_offense(<<~RUBY)
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
homepage "https://brew.sh"
^^^^^^^^^^^^^^^^^^^^^^^^^^ `homepage` (line 3) should be put before `url` (line 2)
end
RUBY
end
it "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"
^^^^^^^^^^^^^^^^^^^^ `depends_on` (line 8) should be put before `resource` (line 4)
end
RUBY
end
it "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
^^^^^^^^^ `plist` (line 8) should be put before `test` (line 4)
end
end
RUBY
end
it "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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `depends_on` (line 4) should be put before `conflicts_with` (line 3)
depends_on "libtool" => :build
depends_on "pkg-config" => :build
depends_on "gettext"
end
RUBY
end
end
context "When auditing formula components order with autocorrect" do
it "When url precedes homepage" do
source = <<~RUBY
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
homepage "https://brew.sh"
end
RUBY
correct_source = <<~RUBY
class Foo < Formula
homepage "https://brew.sh"
url "https://brew.sh/foo-1.0.tgz"
end
RUBY
corrected_source = autocorrect_source(source)
expect(corrected_source).to eq(correct_source)
end
it "When `resource` precedes `depends_on`" do
source = <<~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"
end
RUBY
correct_source = <<~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
corrected_source = autocorrect_source(source)
expect(corrected_source).to eq(correct_source)
end
end
end