aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/cask/cli/edit_spec.rb
blob: f5f98afc8738908013e404842c7f26af2c55e1e5 (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
# monkeypatch for testing
module Hbc
  class CLI
    class Edit
      def self.exec_editor(*command)
        editor_commands << command
      end

      def self.reset!
        @editor_commands = []
      end

      def self.editor_commands
        @editor_commands ||= []
      end
    end
  end
end

describe Hbc::CLI::Edit, :cask do
  before(:each) do
    Hbc::CLI::Edit.reset!
  end

  it "opens the editor for the specified Cask" do
    Hbc::CLI::Edit.run("local-caffeine")
    expect(Hbc::CLI::Edit.editor_commands).to eq [
      [Hbc::CaskLoader.path("local-caffeine")],
    ]
  end

  it "throws away additional arguments and uses the first" do
    Hbc::CLI::Edit.run("local-caffeine", "local-transmission")
    expect(Hbc::CLI::Edit.editor_commands).to eq [
      [Hbc::CaskLoader.path("local-caffeine")],
    ]
  end

  it "raises an exception when the Cask doesnt exist" do
    expect {
      Hbc::CLI::Edit.run("notacask")
    }.to raise_error(Hbc::CaskUnavailableError)
  end

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

  describe "when no Cask is specified, but an invalid option" do
    it "raises an exception" do
      expect {
        Hbc::CLI::Edit.run("--notavalidoption")
      }.to raise_error(Hbc::CaskUnspecifiedError)
    end
  end
end