aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/cmd/style_spec.rb
blob: 61faa4af2ab666dc2f5350e00b66f8c04900c1cb (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
require "cmd/style"

describe "brew style" do
  around(:each) do |example|
    begin
      FileUtils.ln_s HOMEBREW_LIBRARY_PATH, HOMEBREW_LIBRARY/"Homebrew"
      FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop.yml", HOMEBREW_LIBRARY/".rubocop_audit.yml"

      example.run
    ensure
      FileUtils.rm_f HOMEBREW_LIBRARY/"Homebrew"
      FileUtils.rm_f HOMEBREW_LIBRARY/".rubocop_audit.yml"
    end
  end

  describe "Homebrew::check_style_json" do
    let(:dir) { mktmpdir }

    it "returns RubocopResults when RuboCop reports offenses" do
      formula = dir/"my-formula.rb"

      formula.write <<~'EOS'
        class MyFormula < Formula

        end
      EOS

      rubocop_result = Homebrew.check_style_json([formula])

      expect(rubocop_result.file_offenses(formula.realpath.to_s).map(&:message))
        .to include("Layout/EmptyLinesAroundClassBody: Extra empty line detected at class body beginning.")
    end
  end
end