aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/cask/cli/audit_spec.rb
blob: 007ba1eb3ea566eabc5c184f7cb8ae9a6dfe5410 (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
describe Hbc::CLI::Audit, :cask do
  let(:auditor) { double }
  let(:cask) { double }

  describe "selection of Casks to audit" do
    it "audits all Casks if no tokens are given" do
      allow(Hbc).to receive(:all).and_return([cask, cask])

      expect(auditor).to receive(:audit).twice

      run_audit([], auditor)
    end

    it "audits specified Casks if tokens are given" do
      cask_token = "nice-app"
      expect(Hbc::CaskLoader).to receive(:load).with(cask_token).and_return(cask)

      expect(auditor).to receive(:audit).with(cask, audit_download: false, check_token_conflicts: false)

      run_audit([cask_token], auditor)
    end
  end

  describe "rules for downloading a Cask" do
    it "does not download the Cask per default" do
      allow(Hbc::CaskLoader).to receive(:load).and_return(cask)
      expect(auditor).to receive(:audit).with(cask, audit_download: false, check_token_conflicts: false)

      run_audit(["casktoken"], auditor)
    end

    it "download a Cask if --download flag is set" do
      allow(Hbc::CaskLoader).to receive(:load).and_return(cask)
      expect(auditor).to receive(:audit).with(cask, audit_download: true, check_token_conflicts: false)

      run_audit(["casktoken", "--download"], auditor)
    end
  end

  describe "rules for checking token conflicts" do
    it "does not check for token conflicts per default" do
      allow(Hbc::CaskLoader).to receive(:load).and_return(cask)
      expect(auditor).to receive(:audit).with(cask, audit_download: false, check_token_conflicts: false)

      run_audit(["casktoken"], auditor)
    end

    it "checks for token conflicts if --token-conflicts flag is set" do
      allow(Hbc::CaskLoader).to receive(:load).and_return(cask)
      expect(auditor).to receive(:audit).with(cask, audit_download: false, check_token_conflicts: true)

      run_audit(["casktoken", "--token-conflicts"], auditor)
    end
  end

  def run_audit(args, auditor)
    Hbc::CLI::Audit.new(args, auditor).run
  end
end