aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test
diff options
context:
space:
mode:
authorGautham Goli2017-07-30 12:57:57 +0530
committerGautham Goli2017-07-30 12:59:37 +0530
commitc575f34d5fe802962bfb2749a00053ad3561da55 (patch)
treea92805f4a9ddf1496eef92d15e33b9987ba85fc4 /Library/Homebrew/test
parent627b1dae707b4b5ea5e299ff12dd8ac1abbfa056 (diff)
downloadbrew-c575f34d5fe802962bfb2749a00053ad3561da55.tar.bz2
audit: Port audit_urls strict rules to rubocop, add tests and autocorrect
Diffstat (limited to 'Library/Homebrew/test')
-rw-r--r--Library/Homebrew/test/rubocops/urls_cop_spec.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/Library/Homebrew/test/rubocops/urls_cop_spec.rb b/Library/Homebrew/test/rubocops/urls_cop_spec.rb
index 733732bd0..280da6314 100644
--- a/Library/Homebrew/test/rubocops/urls_cop_spec.rb
+++ b/Library/Homebrew/test/rubocops/urls_cop_spec.rb
@@ -182,3 +182,46 @@ describe RuboCop::Cop::FormulaAudit::Urls do
end
end
end
+
+describe RuboCop::Cop::FormulaAuditStrict::PyPiUrls do
+ subject(:cop) { described_class.new }
+
+ context "When auditing urls" do
+ it "with pypi offenses" do
+ formulas = [{
+ "url" => "https://pypi.python.org/packages/source/foo/foo-0.1.tar.gz",
+ "msg" => "https://pypi.python.org/packages/source/foo/foo-0.1.tar.gz should be `https://files.pythonhosted.org/packages/source/foo/foo-0.1.tar.gz`",
+ "col" => 2,
+ "corrected_url" =>"https://files.pythonhosted.org/packages/source/foo/foo-0.1.tar.gz",
+ }]
+ formulas.each do |formula|
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url "#{formula["url"]}"
+ end
+ EOS
+ corrected_source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url "#{formula["corrected_url"]}"
+ end
+ EOS
+ expected_offenses = [{ message: formula["msg"],
+ severity: :convention,
+ line: 3,
+ column: formula["col"],
+ source: source }]
+
+ inspect_source(cop, source)
+ # Check for expected offenses
+ expected_offenses.zip(cop.offenses.reverse).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ # Check for expected auto corrected source
+ new_source = autocorrect_source(cop, source)
+ expect(new_source).to eq(corrected_source)
+ end
+ end
+ end
+end