aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMarkus Reiter2017-05-19 21:07:25 +0200
committerMarkus Reiter2017-05-22 02:51:16 +0200
commit1714c73b497b44358fa9fc17d05c767996ac6b7f (patch)
treea6b4e6701d255d070850b22ec49204d744aaf90c /Library
parenta44d4ce88b6fb3deea8dc41be662583941d5c96d (diff)
downloadbrew-1714c73b497b44358fa9fc17d05c767996ac6b7f.tar.bz2
Refactor `CLI::Audit`.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/audit.rb16
-rw-r--r--Library/Homebrew/test/cask/cli/audit_spec.rb38
2 files changed, 34 insertions, 20 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/cli/audit.rb b/Library/Homebrew/cask/lib/hbc/cli/audit.rb
index ec1c33754..5da2be4cf 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/audit.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/audit.rb
@@ -6,20 +6,24 @@ module Hbc
end
def self.run(*args)
- failed_casks = new(args, Auditor).run
- return if failed_casks.empty?
- raise CaskError, "audit failed for casks: #{failed_casks.join(" ")}"
+ new(*args).run
end
- def initialize(args, auditor)
+ def initialize(*args, auditor: Auditor)
@args = args
@auditor = auditor
end
def run
- casks_to_audit.each_with_object([]) do |cask, failed|
- failed << cask unless audit(cask)
+ failed_casks = []
+
+ casks_to_audit.each do |cask|
+ next if audit(cask)
+ failed_casks << cask
end
+
+ return if failed_casks.empty?
+ raise CaskError, "audit failed for casks: #{failed_casks.join(" ")}"
end
def audit(cask)
diff --git a/Library/Homebrew/test/cask/cli/audit_spec.rb b/Library/Homebrew/test/cask/cli/audit_spec.rb
index 007ba1eb3..312a267f8 100644
--- a/Library/Homebrew/test/cask/cli/audit_spec.rb
+++ b/Library/Homebrew/test/cask/cli/audit_spec.rb
@@ -6,54 +6,64 @@ describe Hbc::CLI::Audit, :cask 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
+ expect(auditor).to receive(:audit).twice.and_return(true)
- run_audit([], auditor)
+ run_audit
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)
+ expect(auditor).to receive(:audit)
+ .with(cask, audit_download: false, check_token_conflicts: false)
+ .and_return(true)
- run_audit([cask_token], auditor)
+ run_audit(cask_token)
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)
+ expect(auditor).to receive(:audit)
+ .with(cask, audit_download: false, check_token_conflicts: false)
+ .and_return(true)
- run_audit(["casktoken"], auditor)
+ run_audit("casktoken")
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)
+ expect(auditor).to receive(:audit)
+ .with(cask, audit_download: true, check_token_conflicts: false)
+ .and_return(true)
- run_audit(["casktoken", "--download"], auditor)
+ run_audit("casktoken", "--download")
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)
+ expect(auditor).to receive(:audit)
+ .with(cask, audit_download: false, check_token_conflicts: false)
+ .and_return(true)
- run_audit(["casktoken"], auditor)
+ run_audit("casktoken")
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)
+ expect(auditor).to receive(:audit)
+ .with(cask, audit_download: false, check_token_conflicts: true)
+ .and_return(true)
- run_audit(["casktoken", "--token-conflicts"], auditor)
+ run_audit("casktoken", "--token-conflicts")
end
end
- def run_audit(args, auditor)
- Hbc::CLI::Audit.new(args, auditor).run
+ def run_audit(*args)
+ Hbc::CLI::Audit.new(*args, auditor: auditor).run
end
end