brew/Library/Homebrew/test/cask/cmd/audit_spec.rb

164 lines
5.2 KiB
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: false
# frozen_string_literal: true
2020-08-18 00:23:23 +01:00
require "cask/auditor"
2017-10-03 10:49:58 +02:00
2018-09-06 08:29:14 +02:00
describe Cask::Cmd::Audit, :cask do
let(:cask) { Cask::Cask.new("cask") }
let(:result) { { warnings: Set.new, errors: Set.new } }
2017-02-08 11:58:34 +01:00
describe "selection of Casks to audit" do
it "audits all Casks if no tokens are given" do
2018-09-06 08:29:14 +02:00
allow(Cask::Cask).to receive(:to_a).and_return([cask, cask])
2017-02-08 11:58:34 +01:00
expect(Cask::Auditor).to receive(:audit).twice.and_return(result)
2017-02-08 11:58:34 +01:00
2017-10-03 10:49:58 +02:00
described_class.run
2017-02-08 11:58:34 +01:00
end
it "audits specified Casks if tokens are given" do
cask_token = "nice-app"
2020-09-29 23:46:30 +02:00
expect(Cask::CaskLoader).to receive(:load).with(cask_token, any_args).and_return(cask)
2017-02-08 11:58:34 +01:00
2018-09-06 08:29:14 +02:00
expect(Cask::Auditor).to receive(:audit)
.with(
cask,
audit_new_cask: false, quarantine: true, any_named_args: true,
display_failures_only: false, display_passes: true,
only: [], except: []
)
.and_return(result)
2017-02-08 11:58:34 +01:00
2017-10-03 10:49:58 +02:00
described_class.run(cask_token)
2017-02-08 11:58:34 +01:00
end
end
2020-08-01 02:30:46 +02:00
it "does not pass anything if no flags are specified" do
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
expect(Cask::Auditor).to receive(:audit)
.with(
cask,
audit_new_cask: false, quarantine: true, any_named_args: true,
display_failures_only: false, display_passes: true,
only: [], except: []
)
2020-08-01 02:30:46 +02:00
.and_return(result)
2017-02-08 11:58:34 +01:00
2020-08-01 02:30:46 +02:00
described_class.run("casktoken")
end
2017-02-08 11:58:34 +01:00
2020-08-01 02:30:46 +02:00
it "passes `audit_download` if the `--download` flag is specified" do
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
expect(Cask::Auditor).to receive(:audit)
.with(
cask,
audit_download: true, audit_new_cask: false, quarantine: true, any_named_args: true,
display_failures_only: false, display_passes: true,
only: [], except: []
)
2020-08-01 02:30:46 +02:00
.and_return(result)
2017-02-08 11:58:34 +01:00
2020-08-01 02:30:46 +02:00
described_class.run("casktoken", "--download")
2017-02-08 11:58:34 +01:00
end
2020-08-01 02:30:46 +02:00
it "passes `audit_token_conflicts` if the `--token-conflicts` flag is specified" do
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
expect(Cask::Auditor).to receive(:audit)
.with(
cask,
audit_token_conflicts: true, audit_new_cask: false, quarantine: true, any_named_args: true,
display_failures_only: false, display_passes: true,
only: [], except: []
)
2020-08-01 02:30:46 +02:00
.and_return(result)
2017-02-08 11:58:34 +01:00
2020-08-01 02:30:46 +02:00
described_class.run("casktoken", "--token-conflicts")
end
2017-02-08 11:58:34 +01:00
it "passes `audit_strict` if the `--strict` flag is specified" do
2020-08-01 02:30:46 +02:00
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
expect(Cask::Auditor).to receive(:audit)
.with(
cask,
audit_strict: true, audit_new_cask: false, quarantine: true, any_named_args: true,
display_failures_only: false, display_passes: true,
only: [], except: []
)
2020-08-01 02:30:46 +02:00
.and_return(result)
2017-02-08 11:58:34 +01:00
2020-08-01 02:30:46 +02:00
described_class.run("casktoken", "--strict")
2017-02-08 11:58:34 +01:00
end
2020-04-23 21:16:17 +02:00
2020-08-01 02:30:46 +02:00
it "passes `audit_online` if the `--online` flag is specified" do
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
expect(Cask::Auditor).to receive(:audit)
.with(
cask,
audit_online: true, audit_new_cask: false, quarantine: true, any_named_args: true,
display_failures_only: false, display_passes: true,
only: [], except: []
)
2020-08-01 02:30:46 +02:00
.and_return(result)
2020-04-23 21:16:17 +02:00
2020-08-01 02:30:46 +02:00
described_class.run("casktoken", "--online")
end
2020-04-23 21:16:17 +02:00
it "passes `audit_new_cask` if the `--new-cask` flag is specified" do
2020-08-01 02:30:46 +02:00
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
expect(Cask::Auditor).to receive(:audit)
.with(
cask,
audit_new_cask: true, quarantine: true, any_named_args: true,
display_failures_only: false, display_passes: true,
only: [], except: []
)
2020-08-01 02:30:46 +02:00
.and_return(result)
described_class.run("casktoken", "--new-cask")
2020-04-23 21:16:17 +02:00
end
2020-08-01 02:30:46 +02:00
it "passes `language` if the `--language` flag is specified" do
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
expect(Cask::Auditor).to receive(:audit)
.with(
cask,
audit_new_cask: false, quarantine: true, language: ["de-AT"], any_named_args: true,
display_failures_only: false, display_passes: true,
only: [], except: []
)
2020-08-01 02:30:46 +02:00
.and_return(result)
2020-04-23 21:16:17 +02:00
2020-08-01 02:30:46 +02:00
described_class.run("casktoken", "--language=de-AT")
end
2020-04-23 21:16:17 +02:00
2020-08-01 02:30:46 +02:00
it "passes `quarantine` if the `--no-quarantine` flag is specified" do
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
expect(Cask::Auditor).to receive(:audit)
.with(
cask,
audit_new_cask: false, quarantine: false, any_named_args: true,
display_failures_only: false, display_passes: true,
only: [], except: []
)
2020-08-01 02:30:46 +02:00
.and_return(result)
2020-04-23 21:16:17 +02:00
2020-08-01 02:30:46 +02:00
described_class.run("casktoken", "--no-quarantine")
2020-04-23 21:16:17 +02:00
end
2020-08-01 02:30:46 +02:00
it "passes `quarantine` if the `--no-quarantine` flag is in HOMEBREW_CASK_OPTS" do
ENV["HOMEBREW_CASK_OPTS"] = "--no-quarantine"
2020-04-23 21:16:17 +02:00
2020-08-01 02:30:46 +02:00
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
expect(Cask::Auditor).to receive(:audit)
.with(
cask,
audit_new_cask: false, quarantine: false, any_named_args: true,
display_failures_only: false, display_passes: true,
only: [], except: []
)
2020-08-01 02:30:46 +02:00
.and_return(result)
2020-04-23 21:16:17 +02:00
2020-08-01 02:30:46 +02:00
described_class.run("casktoken")
2020-04-23 21:16:17 +02:00
end
2017-02-08 11:58:34 +01:00
end