aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/rubocops/class_cop_spec.rb
blob: 59252587c03b21c084312569453b8a572d05180e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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(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(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(source)

      expected_offenses.zip(cop.offenses).each do |expected, actual|
        expect_offense(expected, actual)
      end
    end
  end
end