brew/Library/Homebrew/test/cask/cmd/audit_spec.rb
Mike McQuaid d8a5e467e8
audit: quieten down and make casks audit consistent with formulae.
The current casks audit is very noisy in the no-op case (i.e. no errors)
https://github.com/Homebrew/brew/pull/10234/checks?check_run_id=1655630568#step:15:7

This means when there are errors and you're querying all casks it's
pretty hard to quickly identify the problems.

This commit silences the `passing`, `warning` and header/summary output
when you're querying all casks (rather than a specific cask or tap).

This is more consistent with `brew audit` for formulae which is silent
unless there are audit failures.
2021-01-07 13:31:14 +00:00

117 lines
3.9 KiB
Ruby

# typed: false
# frozen_string_literal: true
require_relative "shared_examples/invalid_option"
require "cask/auditor"
describe Cask::Cmd::Audit, :cask do
let(:cask) { Cask::Cask.new("cask") }
let(:result) { { warnings: Set.new, errors: Set.new } }
it_behaves_like "a command that handles invalid options"
describe "selection of Casks to audit" do
it "audits all Casks if no tokens are given" do
allow(Cask::Cask).to receive(:to_a).and_return([cask, cask])
expect(Cask::Auditor).to receive(:audit).twice.and_return(result)
described_class.run
end
it "audits specified Casks if tokens are given" do
cask_token = "nice-app"
expect(Cask::CaskLoader).to receive(:load).with(cask_token, any_args).and_return(cask)
expect(Cask::Auditor).to receive(:audit)
.with(cask, quarantine: true, any_named_args: true)
.and_return(result)
described_class.run(cask_token)
end
end
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, quarantine: true, any_named_args: true)
.and_return(result)
described_class.run("casktoken")
end
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, quarantine: true, any_named_args: true)
.and_return(result)
described_class.run("casktoken", "--download")
end
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, quarantine: true, any_named_args: true)
.and_return(result)
described_class.run("casktoken", "--token-conflicts")
end
it "passes `audit_strict` if the `--strict` flag is specified" do
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
expect(Cask::Auditor).to receive(:audit)
.with(cask, audit_strict: true, quarantine: true, any_named_args: true)
.and_return(result)
described_class.run("casktoken", "--strict")
end
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, quarantine: true, any_named_args: true)
.and_return(result)
described_class.run("casktoken", "--online")
end
it "passes `audit_new_cask` if the `--new-cask` flag is specified" do
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)
.and_return(result)
described_class.run("casktoken", "--new-cask")
end
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, quarantine: true, language: ["de-AT"], any_named_args: true)
.and_return(result)
described_class.run("casktoken", "--language=de-AT")
end
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, quarantine: false, any_named_args: true)
.and_return(result)
described_class.run("casktoken", "--no-quarantine")
end
it "passes `quarantine` if the `--no-quarantine` flag is in HOMEBREW_CASK_OPTS" do
ENV["HOMEBREW_CASK_OPTS"] = "--no-quarantine"
allow(Cask::CaskLoader).to receive(:load).and_return(cask)
expect(Cask::Auditor).to receive(:audit)
.with(cask, quarantine: false, any_named_args: true)
.and_return(result)
described_class.run("casktoken")
end
end