From ee09df8db37b6b5e3f74afde20b29dda5042f8e8 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 21 Jul 2020 19:05:55 +0200 Subject: [PATCH] Move `Download` from `Auditor` into `Audit`. --- Library/Homebrew/cask/audit.rb | 4 ++-- Library/Homebrew/cask/auditor.rb | 6 ++---- Library/Homebrew/test/cask/audit_spec.rb | 22 ++++++++-------------- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/Library/Homebrew/cask/audit.rb b/Library/Homebrew/cask/audit.rb index db019bda75..fbaff98c80 100644 --- a/Library/Homebrew/cask/audit.rb +++ b/Library/Homebrew/cask/audit.rb @@ -17,12 +17,12 @@ module Cask 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, new_cask: false, commit_range: nil, command: SystemCommand) @cask = cask @appcast = appcast - @download = download + @download = Download.new(cask, quarantine: quarantine) if download @online = online @strict = strict @new_cask = new_cask diff --git a/Library/Homebrew/cask/auditor.rb b/Library/Homebrew/cask/auditor.rb index 4f209120dc..dcee4c4a9b 100644 --- a/Library/Homebrew/cask/auditor.rb +++ b/Library/Homebrew/cask/auditor.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "cask/download" - module Cask class Auditor include Checkable @@ -66,13 +64,13 @@ module Cask end def audit_cask_instance(cask) - download = audit_download? && Download.new(cask, quarantine: quarantine?) audit = Audit.new(cask, appcast: audit_appcast?, online: audit_online?, strict: audit_strict?, new_cask: audit_new_cask?, token_conflicts: audit_token_conflicts?, - download: download, + download: audit_download?, + quarantine: quarantine?, commit_range: commit_range) audit.run! puts audit.summary diff --git a/Library/Homebrew/test/cask/audit_spec.rb b/Library/Homebrew/test/cask/audit_spec.rb index 122913370b..3ddfdcc7ea 100644 --- a/Library/Homebrew/test/cask/audit_spec.rb +++ b/Library/Homebrew/test/cask/audit_spec.rb @@ -15,16 +15,6 @@ describe Cask::Audit, :cask do 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| match do |audit| include_msg?(audit.errors, error_msg) @@ -764,23 +754,27 @@ describe Cask::Audit, :cask do describe "audit of downloads" do let(:cask_token) { "with-binary" } 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(: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 - expect(download).to receive(:perform) + expect(download_double).to receive(:perform) expect(verify).to receive(:all) expect(subject).not_to fail_with(/#{error_msg}/) end 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}/) end 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(subject).to fail_with(/#{error_msg}/) end