Move Download from Auditor into Audit.

This commit is contained in:
Markus Reiter 2020-07-21 19:05:55 +02:00
parent ee648ef88c
commit ee09df8db3
3 changed files with 12 additions and 20 deletions

View File

@ -17,12 +17,12 @@ module Cask
attr_predicate :appcast? attr_predicate :appcast?
def initialize(cask, appcast: false, download: false, def initialize(cask, appcast: false, download: false, quarantine: nil,
token_conflicts: false, online: false, strict: false, token_conflicts: false, online: false, strict: false,
new_cask: false, commit_range: nil, command: SystemCommand) new_cask: false, commit_range: nil, command: SystemCommand)
@cask = cask @cask = cask
@appcast = appcast @appcast = appcast
@download = download @download = Download.new(cask, quarantine: quarantine) if download
@online = online @online = online
@strict = strict @strict = strict
@new_cask = new_cask @new_cask = new_cask

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true # frozen_string_literal: true
require "cask/download"
module Cask module Cask
class Auditor class Auditor
include Checkable include Checkable
@ -66,13 +64,13 @@ module Cask
end end
def audit_cask_instance(cask) def audit_cask_instance(cask)
download = audit_download? && Download.new(cask, quarantine: quarantine?)
audit = Audit.new(cask, appcast: audit_appcast?, audit = Audit.new(cask, appcast: audit_appcast?,
online: audit_online?, online: audit_online?,
strict: audit_strict?, strict: audit_strict?,
new_cask: audit_new_cask?, new_cask: audit_new_cask?,
token_conflicts: audit_token_conflicts?, token_conflicts: audit_token_conflicts?,
download: download, download: audit_download?,
quarantine: quarantine?,
commit_range: commit_range) commit_range: commit_range)
audit.run! audit.run!
puts audit.summary puts audit.summary

View File

@ -15,16 +15,6 @@ describe Cask::Audit, :cask do
end end
end end
matcher :fail do
match(&:errors?)
end
matcher :warn do
match do |audit|
audit.warnings? && !audit.errors?
end
end
matcher :fail_with do |error_msg| matcher :fail_with do |error_msg|
match do |audit| match do |audit|
include_msg?(audit.errors, error_msg) include_msg?(audit.errors, error_msg)
@ -764,23 +754,27 @@ describe Cask::Audit, :cask do
describe "audit of downloads" do describe "audit of downloads" do
let(:cask_token) { "with-binary" } let(:cask_token) { "with-binary" }
let(:cask) { Cask::CaskLoader.load(cask_token) } let(:cask) { Cask::CaskLoader.load(cask_token) }
let(:download) { instance_double(Cask::Download) } let(:download_double) { instance_double(Cask::Download) }
let(:verify) { class_double(Cask::Verify).as_stubbed_const } let(:verify) { class_double(Cask::Verify).as_stubbed_const }
let(:error_msg) { "Download Failed" } let(:error_msg) { "Download Failed" }
before do
allow(audit).to receive(:download).and_return(download_double)
end
it "when download and verification succeed it does not fail" do it "when download and verification succeed it does not fail" do
expect(download).to receive(:perform) expect(download_double).to receive(:perform)
expect(verify).to receive(:all) expect(verify).to receive(:all)
expect(subject).not_to fail_with(/#{error_msg}/) expect(subject).not_to fail_with(/#{error_msg}/)
end end
it "when download fails it does not fail" do it "when download fails it does not fail" do
expect(download).to receive(:perform).and_raise(StandardError.new(error_msg)) expect(download_double).to receive(:perform).and_raise(StandardError.new(error_msg))
expect(subject).to fail_with(/#{error_msg}/) expect(subject).to fail_with(/#{error_msg}/)
end end
it "when verification fails it does not fail" do it "when verification fails it does not fail" do
expect(download).to receive(:perform) expect(download_double).to receive(:perform)
expect(verify).to receive(:all).and_raise(StandardError.new(error_msg)) expect(verify).to receive(:all).and_raise(StandardError.new(error_msg))
expect(subject).to fail_with(/#{error_msg}/) expect(subject).to fail_with(/#{error_msg}/)
end end