|
| 1 | +# typed: false |
| 2 | +# frozen_string_literal: true |
| 3 | + |
| 4 | +require "cask/caskroom" |
| 5 | + |
| 6 | +RSpec.describe Cask::Caskroom do |
| 7 | + describe ".cask_installed?" do |
| 8 | + it "returns true when a cask has an installed caskfile" do |
| 9 | + Dir.mktmpdir do |dir| |
| 10 | + allow(described_class).to receive(:path).and_return(Pathname(dir)) |
| 11 | + casks_dir = (Pathname(dir)/"test-cask"/".metadata"/"1.0"/"0"/"Casks") |
| 12 | + casks_dir.mkpath |
| 13 | + FileUtils.touch casks_dir/"test-cask.rb" |
| 14 | + |
| 15 | + expect(described_class.cask_installed?("test-cask")).to be true |
| 16 | + end |
| 17 | + end |
| 18 | + |
| 19 | + it "returns false when .metadata exists but has no caskfile" do |
| 20 | + Dir.mktmpdir do |dir| |
| 21 | + allow(described_class).to receive(:path).and_return(Pathname(dir)) |
| 22 | + (Pathname(dir)/"test-cask"/".metadata"/"1.0"/"0"/"Casks").mkpath |
| 23 | + |
| 24 | + expect(described_class.cask_installed?("test-cask")).to be false |
| 25 | + end |
| 26 | + end |
| 27 | + |
| 28 | + it "returns false when a cask directory has no .metadata" do |
| 29 | + Dir.mktmpdir do |dir| |
| 30 | + allow(described_class).to receive(:path).and_return(Pathname(dir)) |
| 31 | + (Pathname(dir)/"test-cask"/"1.0").mkpath |
| 32 | + |
| 33 | + expect(described_class.cask_installed?("test-cask")).to be false |
| 34 | + end |
| 35 | + end |
| 36 | + |
| 37 | + it "returns false when a cask directory does not exist" do |
| 38 | + Dir.mktmpdir do |dir| |
| 39 | + allow(described_class).to receive(:path).and_return(Pathname(dir)) |
| 40 | + |
| 41 | + expect(described_class.cask_installed?("nonexistent-cask")).to be false |
| 42 | + end |
| 43 | + end |
| 44 | + end |
| 45 | + |
| 46 | + describe ".any_casks_installed?" do |
| 47 | + it "returns false when caskroom is empty" do |
| 48 | + Dir.mktmpdir do |dir| |
| 49 | + allow(described_class).to receive(:path).and_return(Pathname(dir)) |
| 50 | + |
| 51 | + expect(described_class.any_casks_installed?).to be false |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + it "returns false when only bare directories exist" do |
| 56 | + Dir.mktmpdir do |dir| |
| 57 | + allow(described_class).to receive(:path).and_return(Pathname(dir)) |
| 58 | + (Pathname(dir)/"bare-cask"/"1.0").mkpath |
| 59 | + |
| 60 | + expect(described_class.any_casks_installed?).to be false |
| 61 | + end |
| 62 | + end |
| 63 | + |
| 64 | + it "returns true when at least one cask has an installed caskfile" do |
| 65 | + Dir.mktmpdir do |dir| |
| 66 | + allow(described_class).to receive(:path).and_return(Pathname(dir)) |
| 67 | + (Pathname(dir)/"bare-cask"/"1.0").mkpath |
| 68 | + casks_dir = (Pathname(dir)/"installed-cask"/".metadata"/"1.0"/"0"/"Casks") |
| 69 | + casks_dir.mkpath |
| 70 | + FileUtils.touch casks_dir/"installed-cask.rb" |
| 71 | + |
| 72 | + expect(described_class.any_casks_installed?).to be true |
| 73 | + end |
| 74 | + end |
| 75 | + end |
| 76 | +end |
0 commit comments