aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test
diff options
context:
space:
mode:
authorJCount2017-08-23 16:16:07 -0400
committerGitHub2017-08-23 16:16:07 -0400
commit6023e408dadc483e2c29dd537f535b8f630f905a (patch)
treecf57343883d91dbb4a592ca392e643a5d26b6851 /Library/Homebrew/test
parentce5e1e20845a9a0e9035684e92ca874571f14634 (diff)
parent781da49df87f9f2ddbb3f812e3d53963500cc423 (diff)
downloadbrew-6023e408dadc483e2c29dd537f535b8f630f905a.tar.bz2
Merge pull request #2995 from GauthamGoli/audit_line_rubocop_part_2
audit: Port line_problems to rubocop and add tests part 2
Diffstat (limited to 'Library/Homebrew/test')
-rw-r--r--Library/Homebrew/test/dev-cmd/audit_spec.rb22
-rw-r--r--Library/Homebrew/test/rubocops/lines_cop_spec.rb151
2 files changed, 151 insertions, 22 deletions
diff --git a/Library/Homebrew/test/dev-cmd/audit_spec.rb b/Library/Homebrew/test/dev-cmd/audit_spec.rb
index f2d8a8e7c..037865fdf 100644
--- a/Library/Homebrew/test/dev-cmd/audit_spec.rb
+++ b/Library/Homebrew/test/dev-cmd/audit_spec.rb
@@ -263,28 +263,6 @@ describe FormulaAuditor do
expect(fa.problems.shift)
.to eq('Use pkgshare instead of (share/"foolibc++")')
end
-
- specify "no space in class inheritance" do
- fa = formula_auditor "foo", <<-EOS.undent
- class Foo<Formula
- url '/foo-1.0.tgz'
- end
- EOS
-
- fa.line_problems "class Foo<Formula", 1
- expect(fa.problems.shift)
- .to eq("Use a space in class inheritance: class Foo < Formula")
- end
-
- specify "default template" do
- fa = formula_auditor "foo", "class Foo < Formula; url '/foo-1.0.tgz'; end"
-
- fa.line_problems '# system "cmake", ".", *std_cmake_args', 3
- expect(fa.problems.shift).to eq("Commented cmake call found")
-
- fa.line_problems "# PLEASE REMOVE", 3
- expect(fa.problems.shift).to eq("Please remove default template comments")
- end
end
describe "#audit_github_repository" do
diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb
index c865e1480..b0ed8f4d1 100644
--- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb
+++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb
@@ -51,3 +51,154 @@ describe RuboCop::Cop::FormulaAudit::Lines do
end
end
end
+
+describe RuboCop::Cop::FormulaAudit::ClassInheritance do
+ subject(:cop) { described_class.new }
+
+ context "When auditing lines" do
+ it "with no space in class inheritance" do
+ source = <<-EOS.undent
+ class Foo<Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ end
+ EOS
+
+ expected_offenses = [{ message: "Use a space in class inheritance: class Foo < Formula",
+ severity: :convention,
+ line: 1,
+ column: 10,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+ end
+end
+
+describe RuboCop::Cop::FormulaAudit::Comments do
+ subject(:cop) { described_class.new }
+
+ context "When auditing formula" do
+ it "with commented cmake call" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ # system "cmake", ".", *std_cmake_args
+ end
+ EOS
+
+ expected_offenses = [{ message: "Please remove default template comments",
+ severity: :convention,
+ line: 4,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "with default template comments" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ # PLEASE REMOVE
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ end
+ EOS
+
+ expected_offenses = [{ message: "Please remove default template comments",
+ severity: :convention,
+ line: 2,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "with commented out depends_on" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ # depends_on "foo"
+ end
+ EOS
+
+ expected_offenses = [{ message: 'Commented-out dependency "foo"',
+ severity: :convention,
+ line: 4,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+ end
+end
+
+describe RuboCop::Cop::FormulaAudit::Miscellaneous do
+ subject(:cop) { described_class.new }
+
+ context "When auditing formula" do
+ it "with FileUtils" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ FileUtils.mv "hello"
+ end
+ EOS
+
+ expected_offenses = [{ message: "Don't need 'FileUtils.' before mv",
+ severity: :convention,
+ line: 4,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "with long inreplace block vars" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ inreplace "foo" do |longvar|
+ somerandomCall(longvar)
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "\"inreplace <filenames> do |s|\" is preferred over \"|longvar|\".",
+ severity: :convention,
+ line: 4,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+ end
+end