Convert Audit test to spec.
This commit is contained in:
parent
d197e79d35
commit
9e31b51cb0
61
Library/Homebrew/cask/spec/cask/cli/audit_spec.rb
Normal file
61
Library/Homebrew/cask/spec/cask/cli/audit_spec.rb
Normal file
@ -0,0 +1,61 @@
|
||||
require "spec_helper"
|
||||
|
||||
describe Hbc::CLI::Audit do
|
||||
let(:auditor) { double }
|
||||
let(:cask) { double }
|
||||
|
||||
describe "selection of Casks to audit" 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
|
||||
|
||||
run_audit([], auditor)
|
||||
end
|
||||
|
||||
it "audits specified Casks if tokens are given" do
|
||||
cask_token = "nice-app"
|
||||
expect(Hbc).to receive(:load).with(cask_token).and_return(cask)
|
||||
|
||||
expect(auditor).to receive(:audit).with(cask, audit_download: false, check_token_conflicts: false)
|
||||
|
||||
run_audit([cask_token], auditor)
|
||||
end
|
||||
end
|
||||
|
||||
describe "rules for downloading a Cask" do
|
||||
it "does not download the Cask per default" do
|
||||
allow(Hbc).to receive(:load).and_return(cask)
|
||||
expect(auditor).to receive(:audit).with(cask, audit_download: false, check_token_conflicts: false)
|
||||
|
||||
run_audit(["casktoken"], auditor)
|
||||
end
|
||||
|
||||
it "download a Cask if --download flag is set" do
|
||||
allow(Hbc).to receive(:load).and_return(cask)
|
||||
expect(auditor).to receive(:audit).with(cask, audit_download: true, check_token_conflicts: false)
|
||||
|
||||
run_audit(["casktoken", "--download"], auditor)
|
||||
end
|
||||
end
|
||||
|
||||
describe "rules for checking token conflicts" do
|
||||
it "does not check for token conflicts per default" do
|
||||
allow(Hbc).to receive(:load).and_return(cask)
|
||||
expect(auditor).to receive(:audit).with(cask, audit_download: false, check_token_conflicts: false)
|
||||
|
||||
run_audit(["casktoken"], auditor)
|
||||
end
|
||||
|
||||
it "checks for token conflicts if --token-conflicts flag is set" do
|
||||
allow(Hbc).to receive(:load).and_return(cask)
|
||||
expect(auditor).to receive(:audit).with(cask, audit_download: false, check_token_conflicts: true)
|
||||
|
||||
run_audit(["casktoken", "--token-conflicts"], auditor)
|
||||
end
|
||||
end
|
||||
|
||||
def run_audit(args, auditor)
|
||||
Hbc::CLI::Audit.new(args, auditor).run
|
||||
end
|
||||
end
|
@ -1,64 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
describe Hbc::CLI::Audit do
|
||||
let(:auditor) { mock }
|
||||
let(:cask) { mock }
|
||||
|
||||
describe "selection of Casks to audit" do
|
||||
it "audits all Casks if no tokens are given" do
|
||||
Hbc.stub :all, [cask, cask] do
|
||||
auditor.expects(:audit).times(2)
|
||||
|
||||
run_audit([], auditor)
|
||||
end
|
||||
end
|
||||
|
||||
it "audits specified Casks if tokens are given" do
|
||||
cask_token = "nice-app"
|
||||
Hbc.expects(:load).with(cask_token).returns(cask)
|
||||
auditor.expects(:audit).with(cask, audit_download: false, check_token_conflicts: false)
|
||||
|
||||
run_audit([cask_token], auditor)
|
||||
end
|
||||
end
|
||||
|
||||
describe "rules for downloading a Cask" do
|
||||
it "does not download the Cask per default" do
|
||||
Hbc.stub :load, cask do
|
||||
auditor.expects(:audit).with(cask, audit_download: false, check_token_conflicts: false)
|
||||
|
||||
run_audit(["casktoken"], auditor)
|
||||
end
|
||||
end
|
||||
|
||||
it "download a Cask if --download flag is set" do
|
||||
Hbc.stub :load, cask do
|
||||
auditor.expects(:audit).with(cask, audit_download: true, check_token_conflicts: false)
|
||||
|
||||
run_audit(["casktoken", "--download"], auditor)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "rules for checking token conflicts" do
|
||||
it "does not check for token conflicts per default" do
|
||||
Hbc.stub :load, cask do
|
||||
auditor.expects(:audit).with(cask, audit_download: false, check_token_conflicts: false)
|
||||
|
||||
run_audit(["casktoken"], auditor)
|
||||
end
|
||||
end
|
||||
|
||||
it "checks for token conflicts if --token-conflicts flag is set" do
|
||||
Hbc.stub :load, cask do
|
||||
auditor.expects(:audit).with(cask, audit_download: false, check_token_conflicts: true)
|
||||
|
||||
run_audit(["casktoken", "--token-conflicts"], auditor)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def run_audit(args, auditor)
|
||||
Hbc::CLI::Audit.new(args, auditor).run
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user