116 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			116 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| # 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).and_return(cask)
 | |
| 
 | |
|       expect(Cask::Auditor).to receive(:audit)
 | |
|         .with(cask, quarantine: 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)
 | |
|       .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)
 | |
|       .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)
 | |
|       .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)
 | |
|       .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)
 | |
|       .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)
 | |
|       .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"])
 | |
|       .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)
 | |
|       .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)
 | |
|       .and_return(result)
 | |
| 
 | |
|     described_class.run("casktoken")
 | |
|   end
 | |
| end
 | 
