aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/cask/cli/create_spec.rb
blob: d77b0a2aac0267c8038678734f29b79a10ddcf16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
describe Hbc::CLI::Create, :cask do
  around(:each) do |example|
    begin
      example.run
    ensure
      %w[new-cask additional-cask another-cask yet-another-cask local-caff].each do |cask|
        FileUtils.rm_f Hbc::CaskLoader.path(cask)
      end
    end
  end

  before(:each) do
    allow_any_instance_of(described_class).to receive(:exec_editor)
  end

  it "opens the editor for the specified Cask" do
    command = described_class.new("new-cask")
    expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("new-cask"))
    command.run
  end

  it "drops a template down for the specified Cask" do
    described_class.run("new-cask")
    template = File.read(Hbc::CaskLoader.path("new-cask"))
    expect(template).to eq <<-EOS.undent
      cask 'new-cask' do
        version ''
        sha256 ''

        url 'https://'
        name ''
        homepage ''

        app ''
      end
    EOS
  end

  it "raises an exception when more than one Cask is given" do
    expect {
      described_class.run("additional-cask", "another-cask")
    }.to raise_error(/Only one Cask can be created at a time./)
  end

  it "raises an exception when the Cask already exists" do
    expect {
      described_class.run("basic-cask")
    }.to raise_error(Hbc::CaskAlreadyCreatedError)
  end

  it "allows creating Casks that are substrings of existing Casks" do
    command = described_class.new("local-caff")
    expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("local-caff"))
    command.run
  end

  describe "when no Cask is specified" do
    it "raises an exception" do
      expect {
        described_class.run
      }.to raise_error(Hbc::CaskUnspecifiedError)
    end
  end

  context "when an invalid option is specified" do
    it "raises an exception when no Cask is specified" do
      expect {
        described_class.run("--notavalidoption")
      }.to raise_error(/invalid option/)
    end

    it "raises an exception" do
      expect {
        described_class.run("--notavalidoption", "yet-another-cask")
      }.to raise_error(/invalid option/)
    end
  end
end