diff options
| author | Gautham Goli | 2017-09-04 13:47:05 +0530 |
|---|---|---|
| committer | Gautham Goli | 2017-09-04 23:43:42 +0530 |
| commit | 4ec26aea4025d19e70cdf59da6dfd7be3a389e44 (patch) | |
| tree | 93e8e09c078c364c5ab513df59d86924e0ac1d8c /Library/Homebrew/test/rubocops | |
| parent | e77701075606cbcf3075d7fcc123556b63977bcf (diff) | |
| download | brew-4ec26aea4025d19e70cdf59da6dfd7be3a389e44.tar.bz2 | |
audit: Port audit_class to rubocop, add tests and autocorrect
Diffstat (limited to 'Library/Homebrew/test/rubocops')
| -rw-r--r-- | Library/Homebrew/test/rubocops/class_cop_spec.rb | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/Library/Homebrew/test/rubocops/class_cop_spec.rb b/Library/Homebrew/test/rubocops/class_cop_spec.rb new file mode 100644 index 000000000..676dd4f6e --- /dev/null +++ b/Library/Homebrew/test/rubocops/class_cop_spec.rb @@ -0,0 +1,81 @@ +require "rubocop" +require "rubocop/rspec/support" +require_relative "../../extend/string" +require_relative "../../rubocops/class_cop" + +describe RuboCop::Cop::FormulaAudit::ClassName do + subject(:cop) { described_class.new } + + context "When auditing formula" do + it "with deprecated inheritance" do + formulas = [{ + "class" => "GithubGistFormula", + }, { + "class" => "ScriptFileFormula", + }, { + "class" => "AmazonWebServicesFormula", + }] + + formulas.each do |formula| + source = <<-EOS.undent + class Foo < #{formula["class"]} + url 'http://example.com/foo-1.0.tgz' + end + EOS + + expected_offenses = [{ message: "#{formula["class"]} is deprecated, use Formula instead", + severity: :convention, + line: 1, + column: 12, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses.reverse).each do |expected, actual| + expect_offense(expected, actual) + end + end + end + + it "with deprecated inheritance and autocorrect" do + source = <<-EOS.undent + class Foo < AmazonWebServicesFormula + url 'http://example.com/foo-1.0.tgz' + end + EOS + corrected_source = <<-EOS.undent + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + end + EOS + + new_source = autocorrect_source(cop, source) + expect(new_source).to eq(corrected_source) + end + end +end + +describe RuboCop::Cop::FormulaAuditStrict::Test do + subject(:cop) { described_class.new } + + context "When auditing formula" do + it "without a test block" do + source = <<-EOS.undent + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + end + EOS + expected_offenses = [{ message: described_class::MSG, + 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 + end +end |
