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

143 lines
3.5 KiB
Ruby

require "rubocops/class"
describe RuboCop::Cop::FormulaAudit::ClassName do
subject(:cop) { described_class.new }
it "reports an offense when using ScriptFileFormula" do
expect_offense(<<~RUBY)
class Foo < ScriptFileFormula
^^^^^^^^^^^^^^^^^ ScriptFileFormula is deprecated, use Formula instead
url 'https://brew.sh/foo-1.0.tgz'
end
RUBY
end
it "reports an offense when using GithubGistFormula" do
expect_offense(<<~RUBY)
class Foo < GithubGistFormula
^^^^^^^^^^^^^^^^^ GithubGistFormula is deprecated, use Formula instead
url 'https://brew.sh/foo-1.0.tgz'
end
RUBY
end
it "reports an offense when using AmazonWebServicesFormula" do
expect_offense(<<~RUBY)
class Foo < AmazonWebServicesFormula
^^^^^^^^^^^^^^^^^^^^^^^^ AmazonWebServicesFormula is deprecated, use Formula instead
url 'https://brew.sh/foo-1.0.tgz'
end
RUBY
end
it "supports auto-correcting deprecated parent classes" do
source = <<~RUBY
class Foo < AmazonWebServicesFormula
url 'https://brew.sh/foo-1.0.tgz'
end
RUBY
corrected_source = <<~RUBY
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
end
RUBY
new_source = autocorrect_source(source)
expect(new_source).to eq(corrected_source)
end
end
describe RuboCop::Cop::FormulaAudit::TestCalls do
subject(:cop) { described_class.new }
it "reports an offense when /usr/local/bin is found in test calls" do
expect_offense(<<~RUBY)
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
test do
system "/usr/local/bin/test"
^^^^^^^^^^^^^^^^^^^^^ use \#{bin} instead of /usr/local/bin in system
end
end
RUBY
end
it "reports an offense when passing 0 as the second parameter to shell_output" do
expect_offense(<<~RUBY)
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
test do
shell_output("\#{bin}/test", 0)
^ Passing 0 to shell_output() is redundant
end
end
RUBY
end
it "supports auto-correcting test calls" do
source = <<~RUBY
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
test do
shell_output("/usr/local/sbin/test", 0)
end
end
RUBY
corrected_source = <<~RUBY
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
test do
shell_output("\#{sbin}/test")
end
end
RUBY
new_source = autocorrect_source(source)
expect(new_source).to eq(corrected_source)
end
end
describe RuboCop::Cop::FormulaAuditStrict::Test do
subject(:cop) { described_class.new }
it "reports an offense when there is no test block" do
expect_offense(<<~RUBY)
class Foo < Formula
^^^^^^^^^^^^^^^^^^^ A `test do` test block should be added
url 'https://brew.sh/foo-1.0.tgz'
end
RUBY
end
it "reports an offense when there is an empty test block" do
expect_offense(<<~RUBY)
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
test do
^^^^^^^ `test do` should not be empty
end
end
RUBY
end
it "reports an offense when test is falsely true" do
expect_offense(<<~RUBY)
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
test do
^^^^^^^ `test do` should contain a real test
true
end
end
RUBY
end
end