aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/cask/cli/options_spec.rb
blob: 8b084113c9a2b502e63d330466a307cef4a54a8d (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
describe Hbc::CLI, :cask do
  it "supports setting the appdir" do
    allow(Hbc::Config.global).to receive(:appdir).and_call_original

    described_class.new.process_options("help", "--appdir=/some/path/foo")

    expect(Hbc::Config.global.appdir).to eq(Pathname.new("/some/path/foo"))
  end

  it "supports setting the appdir from ENV" do
    allow(Hbc::Config.global).to receive(:appdir).and_call_original

    ENV["HOMEBREW_CASK_OPTS"] = "--appdir=/some/path/bar"

    described_class.new.process_options("help")

    expect(Hbc::Config.global.appdir).to eq(Pathname.new("/some/path/bar"))
  end

  it "supports setting the prefpanedir" do
    allow(Hbc::Config.global).to receive(:prefpanedir).and_call_original

    described_class.new.process_options("help", "--prefpanedir=/some/path/foo")

    expect(Hbc::Config.global.prefpanedir).to eq(Pathname.new("/some/path/foo"))
  end

  it "supports setting the prefpanedir from ENV" do
    allow(Hbc::Config.global).to receive(:prefpanedir).and_call_original

    ENV["HOMEBREW_CASK_OPTS"] = "--prefpanedir=/some/path/bar"

    described_class.new.process_options("help")

    expect(Hbc::Config.global.prefpanedir).to eq(Pathname.new("/some/path/bar"))
  end

  it "supports setting the qlplugindir" do
    allow(Hbc::Config.global).to receive(:qlplugindir).and_call_original

    described_class.new.process_options("help", "--qlplugindir=/some/path/foo")

    expect(Hbc::Config.global.qlplugindir).to eq(Pathname.new("/some/path/foo"))
  end

  it "supports setting the qlplugindir from ENV" do
    allow(Hbc::Config.global).to receive(:qlplugindir).and_call_original

    ENV["HOMEBREW_CASK_OPTS"] = "--qlplugindir=/some/path/bar"

    described_class.new.process_options("help")

    expect(Hbc::Config.global.qlplugindir).to eq(Pathname.new("/some/path/bar"))
  end

  it "supports setting the colorpickerdir" do
    allow(Hbc::Config.global).to receive(:colorpickerdir).and_call_original

    described_class.new.process_options("help", "--colorpickerdir=/some/path/foo")

    expect(Hbc::Config.global.colorpickerdir).to eq(Pathname.new("/some/path/foo"))
  end

  it "supports setting the colorpickerdir from ENV" do
    allow(Hbc::Config.global).to receive(:colorpickerdir).and_call_original

    ENV["HOMEBREW_CASK_OPTS"] = "--colorpickerdir=/some/path/bar"

    described_class.new.process_options("help")

    expect(Hbc::Config.global.colorpickerdir).to eq(Pathname.new("/some/path/bar"))
  end

  it "supports setting the dictionarydir" do
    allow(Hbc::Config.global).to receive(:dictionarydir).and_call_original

    described_class.new.process_options("help", "--dictionarydir=/some/path/foo")

    expect(Hbc::Config.global.dictionarydir).to eq(Pathname.new("/some/path/foo"))
  end

  it "supports setting the dictionarydir from ENV" do
    allow(Hbc::Config.global).to receive(:dictionarydir).and_call_original

    ENV["HOMEBREW_CASK_OPTS"] = "--dictionarydir=/some/path/bar"

    described_class.new.process_options("help")

    expect(Hbc::Config.global.dictionarydir).to eq(Pathname.new("/some/path/bar"))
  end

  it "supports setting the fontdir" do
    allow(Hbc::Config.global).to receive(:fontdir).and_call_original

    described_class.new.process_options("help", "--fontdir=/some/path/foo")

    expect(Hbc::Config.global.fontdir).to eq(Pathname.new("/some/path/foo"))
  end

  it "supports setting the fontdir from ENV" do
    allow(Hbc::Config.global).to receive(:fontdir).and_call_original

    ENV["HOMEBREW_CASK_OPTS"] = "--fontdir=/some/path/bar"

    described_class.new.process_options("help")

    expect(Hbc::Config.global.fontdir).to eq(Pathname.new("/some/path/bar"))
  end

  it "supports setting the servicedir" do
    allow(Hbc::Config.global).to receive(:servicedir).and_call_original

    described_class.new.process_options("help", "--servicedir=/some/path/foo")

    expect(Hbc::Config.global.servicedir).to eq(Pathname.new("/some/path/foo"))
  end

  it "supports setting the servicedir from ENV" do
    allow(Hbc::Config.global).to receive(:servicedir).and_call_original

    ENV["HOMEBREW_CASK_OPTS"] = "--servicedir=/some/path/bar"

    described_class.new.process_options("help")

    expect(Hbc::Config.global.servicedir).to eq(Pathname.new("/some/path/bar"))
  end

  it "allows additional options to be passed through" do
    allow(Hbc::Config.global).to receive(:appdir).and_call_original

    rest = described_class.new.process_options("edit", "foo", "--create", "--appdir=/some/path/qux")

    expect(Hbc::Config.global.appdir).to eq(Pathname.new("/some/path/qux"))
    expect(rest).to eq(%w[edit foo --create])
  end

  describe "--help" do
    it "sets the Cask help method to true" do
      command = described_class.new("foo", "--help")
      expect(command.help?).to be true
    end
  end
end