diff options
| author | Mike McQuaid | 2017-09-05 18:07:25 +0100 |
|---|---|---|
| committer | GitHub | 2017-09-05 18:07:25 +0100 |
| commit | 4cc8d4737b1c87cdc2d2c9e90d80b3b372bb924c (patch) | |
| tree | 10f2bf1d7f5f198247553d28e90259e3ffcf6b10 /Library/Homebrew/test/rubocops | |
| parent | c6d5f8cc99981310ea9f2763d9e53eac4eaeef8a (diff) | |
| parent | d45ff9c0fdfa834c55c01f9c95fe18064fabd76a (diff) | |
| download | brew-4cc8d4737b1c87cdc2d2c9e90d80b3b372bb924c.tar.bz2 | |
Merge pull request #2982 from GauthamGoli/audit_class_rubocop_port
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 |
