aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test
diff options
context:
space:
mode:
authorMike McQuaid2017-08-01 11:39:01 +0100
committerGitHub2017-08-01 11:39:01 +0100
commitf4983ab16b01776f57cc8665df1bc3421c0c4683 (patch)
tree38ec5e272d3b9dc2d32b7ab4d73438b719c759b0 /Library/Homebrew/test
parent43d68b6dda55c89a2f8cced5f874e866df7981c3 (diff)
parentc575f34d5fe802962bfb2749a00053ad3561da55 (diff)
downloadbrew-f4983ab16b01776f57cc8665df1bc3421c0c4683.tar.bz2
Merge pull request #2975 from GauthamGoli/audit_urls_rubocop_strict
audit: Port audit_urls strict rules to rubocop, add tests, 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