blob: aacb52ebb4ece3e41a0d9e4c091224d3fa3c41ff (
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
 | require_relative "../../rubocops/formula_desc_cop"
describe RuboCop::Cop::FormulaAuditStrict::DescLength do
  subject(:cop) { described_class.new }
  context "When auditing formula desc" do
    it "When there is no desc" do
      expect_offense(<<~RUBY)
        class Foo < Formula
        ^^^^^^^^^^^^^^^^^^^ Formula should have a desc (Description).
          url 'http://example.com/foo-1.0.tgz'
        end
      RUBY
    end
    it "reports an offense when desc is an empty string" do
      expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
        class Foo < Formula
          url 'http://example.com/foo-1.0.tgz'
          desc ''
          ^^^^^^^ The desc (description) should not be an empty string.
        end
      RUBY
    end
    it "When desc is too long" do
      expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
        class Foo < Formula
          url 'http://example.com/foo-1.0.tgz'
          desc 'Bar#{"bar" * 29}'
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Description is too long. "name: desc" should be less than 80 characters. Length is calculated as foo + desc. (currently 95)
        end
      RUBY
    end
    it "When desc is multiline string" do
      expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
        class Foo < Formula
          url 'http://example.com/foo-1.0.tgz'
          desc 'Bar#{"bar" * 9}'\
            '#{"foo" * 21}'
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Description is too long. "name: desc" should be less than 80 characters. Length is calculated as foo + desc. (currently 98)
        end
      RUBY
    end
  end
end
describe RuboCop::Cop::FormulaAuditStrict::Desc do
  subject(:cop) { described_class.new }
  context "When auditing formula desc" do
    it "When wrong \"command-line\" usage in desc" do
      expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
        class Foo < Formula
          url 'http://example.com/foo-1.0.tgz'
          desc 'command line'
                ^ Description should start with a capital letter
                ^^^^^^^^^^^^ Description should use \"command-line\" instead of \"command line\"
        end
      RUBY
    end
    it "When an article is used in desc" do
      expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
        class Foo < Formula
          url 'http://example.com/foo-1.0.tgz'
          desc 'An '
                ^^^ Description shouldn\'t start with an indefinite article i.e. \"An\"
        end
      RUBY
    end
    it "When an lowercase letter starts a desc" do
      expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
        class Foo < Formula
          url 'http://example.com/foo-1.0.tgz'
          desc 'bar'
                ^ Description should start with a capital letter
        end
      RUBY
    end
    it "When formula name is in desc" do
      expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
        class Foo < Formula
          url 'http://example.com/foo-1.0.tgz'
          desc 'Foo is a foobar'
                ^^^^ Description shouldn\'t start with the formula name
        end
      RUBY
    end
    it "When the description ends with a full stop" do
      expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
        class Foo < Formula
          url 'http://example.com/foo-1.0.tgz'
          desc 'Description with a full stop at the end.'
                                                       ^ Description shouldn\'t end with a full stop
        end
      RUBY
    end
    it "autocorrects all rules" do
      source = <<~EOS
        class Foo < Formula
          url 'http://example.com/foo-1.0.tgz'
          desc ' an bar: commandline foo '
        end
      EOS
      correct_source = <<~EOS
        class Foo < Formula
          url 'http://example.com/foo-1.0.tgz'
          desc 'an bar: command-line'
        end
      EOS
      corrected_source = autocorrect_source(source, "/homebrew-core/Formula/foo.rb")
      expect(corrected_source).to eq(correct_source)
    end
  end
end
 |