From 51f2338dd57eed5a7f18e147ccd4f4b9da19fb52 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Wed, 24 May 2017 00:08:31 +0530 Subject: audit: Port audit_text method to rubocop and add tests --- Library/Homebrew/test/dev-cmd/audit_spec.rb | 51 ----- Library/Homebrew/test/rubocops/text_cop_spec.rb | 261 ++++++++++++++++++++++++ 2 files changed, 261 insertions(+), 51 deletions(-) create mode 100644 Library/Homebrew/test/rubocops/text_cop_spec.rb (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/dev-cmd/audit_spec.rb b/Library/Homebrew/test/dev-cmd/audit_spec.rb index 97cc0f152..b90a21b55 100644 --- a/Library/Homebrew/test/dev-cmd/audit_spec.rb +++ b/Library/Homebrew/test/dev-cmd/audit_spec.rb @@ -385,57 +385,6 @@ describe FormulaAuditor do end end - describe "#audit_text" do - specify "xcodebuild suggests symroot" do - fa = formula_auditor "foo", <<-EOS.undent - class Foo < Formula - url "http://example.com/foo-1.0.tgz" - homepage "http://example.com" - - def install - xcodebuild "-project", "meow.xcodeproject" - end - end - EOS - - fa.audit_text - expect(fa.problems.first) - .to match('xcodebuild should be passed an explicit "SYMROOT"') - end - - specify "bare xcodebuild also suggests symroot" do - fa = formula_auditor "foo", <<-EOS.undent - class Foo < Formula - url "http://example.com/foo-1.0.tgz" - homepage "http://example.com" - - def install - xcodebuild - end - end - EOS - - fa.audit_text - expect(fa.problems.first) - .to match('xcodebuild should be passed an explicit "SYMROOT"') - end - - specify "disallow go get usage" do - fa = formula_auditor "foo", <<-EOS.undent - class Foo + + + + Label + org.nrpe.agent + + + \EOS + end + end + EOS + + expected_offenses = [{ message: "Please set plist_options when using a formula-defined plist.", + severity: :convention, + line: 9, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "When language/go is require'd" do + source = <<-EOS.undent + require "language/go" + + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + homepage "http://example.com" + + def install + system "go", "get", "bar" + end + end + EOS + + expected_offenses = [{ message: "require \"language/go\" is unnecessary unless using `go_resource`s", + severity: :convention, + line: 1, + column: 0, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "When formula uses virtualenv and also `setuptools` resource" do + source = <<-EOS.undent + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + homepage "http://example.com" + + resource "setuptools" do + url "https://foo.com/foo.tar.gz" + sha256 "db0904a28253cfe53e7dedc765c71596f3c53bb8a866ae50123320ec1a7b73fd" + end + + def install + virtualenv_create(libexec) + end + end + EOS + + expected_offenses = [{ message: "Formulae using virtualenvs do not need a `setuptools` resource.", + severity: :convention, + line: 5, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "When Formula.factory(name) is used" do + source = <<-EOS.undent + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + homepage "http://example.com" + + def install + Formula.factory(name) + end + end + EOS + + expected_offenses = [{ message: "\"Formula.factory(name)\" is deprecated in favor of \"Formula[name]\"", + severity: :convention, + line: 6, + column: 4, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + def expect_offense(expected, actual) + expect(actual.message).to eq(expected[:message]) + expect(actual.severity).to eq(expected[:severity]) + expect(actual.line).to eq(expected[:line]) + expect(actual.column).to eq(expected[:column]) + end + end +end -- cgit v1.2.3