forked from Homebrew/homebrew-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrewfile_spec.rb
199 lines (154 loc) · 6.19 KB
/
brewfile_spec.rb
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# frozen_string_literal: true
require "spec_helper"
describe Bundle::Brewfile do
describe "path" do
subject(:path) do
described_class.path(dash_writes_to_stdout:, global: has_global, file: file_value)
end
let(:dash_writes_to_stdout) { false }
let(:env_bundle_file_global_value) { nil }
let(:env_bundle_file_value) { nil }
let(:env_user_config_home_value) { "/Users/username/.homebrew" }
let(:file_value) { nil }
let(:has_global) { false }
let(:config_dir_brewfile_exist) { false }
before do
allow(ENV).to receive(:fetch).and_return(nil)
allow(ENV).to receive(:fetch).with("HOMEBREW_BUNDLE_FILE_GLOBAL", any_args)
.and_return(env_bundle_file_global_value)
allow(ENV).to receive(:fetch).with("HOMEBREW_BUNDLE_FILE", any_args)
.and_return(env_bundle_file_value)
allow(ENV).to receive(:fetch).with("HOMEBREW_USER_CONFIG_HOME", any_args)
.and_return(env_user_config_home_value)
allow(File).to receive(:exist?).with("/Users/username/.homebrew/Brewfile")
.and_return(config_dir_brewfile_exist)
end
context "when `file` is specified with a relative path" do
let(:file_value) { "path/to/Brewfile" }
let(:expected_pathname) { Pathname.new(file_value).expand_path(Dir.pwd) }
it "returns the expected path" do
expect(path).to eq(expected_pathname)
end
context "with a configured HOMEBREW_BUNDLE_FILE" do
let(:env_bundle_file_value) { "/path/to/Brewfile" }
it "returns the value specified by `file` path" do
expect(path).to eq(expected_pathname)
end
end
context "with an empty HOMEBREW_BUNDLE_FILE" do
let(:env_bundle_file_value) { "" }
it "returns the value specified by `file` path" do
expect(path).to eq(expected_pathname)
end
end
end
context "when `file` is specified with an absolute path" do
let(:file_value) { "/tmp/random_file" }
let(:expected_pathname) { Pathname.new(file_value) }
it "returns the expected path" do
expect(path).to eq(expected_pathname)
end
context "with a configured HOMEBREW_BUNDLE_FILE" do
let(:env_bundle_file_value) { "/path/to/Brewfile" }
it "returns the value specified by `file` path" do
expect(path).to eq(expected_pathname)
end
end
context "with an empty HOMEBREW_BUNDLE_FILE" do
let(:env_bundle_file_value) { "" }
it "returns the value specified by `file` path" do
expect(path).to eq(expected_pathname)
end
end
end
context "when `file` is specified with `-`" do
let(:file_value) { "-" }
let(:expected_pathname) { Pathname.new("/dev/stdin") }
it "returns stdin by default" do
expect(path).to eq(expected_pathname)
end
context "with a configured HOMEBREW_BUNDLE_FILE" do
let(:env_bundle_file_value) { "/path/to/Brewfile" }
it "returns the value specified by `file` path" do
expect(path).to eq(expected_pathname)
end
end
context "with an empty HOMEBREW_BUNDLE_FILE" do
let(:env_bundle_file_value) { "" }
it "returns the value specified by `file` path" do
expect(path).to eq(expected_pathname)
end
end
context "when `dash_writes_to_stdout` is true" do
let(:expected_pathname) { Pathname.new("/dev/stdout") }
let(:dash_writes_to_stdout) { true }
it "returns stdout" do
expect(path).to eq(expected_pathname)
end
context "with a configured HOMEBREW_BUNDLE_FILE" do
let(:env_bundle_file_value) { "/path/to/Brewfile" }
it "returns the value specified by `file` path" do
expect(path).to eq(expected_pathname)
end
end
context "with an empty HOMEBREW_BUNDLE_FILE" do
let(:env_bundle_file_value) { "" }
it "returns the value specified by `file` path" do
expect(path).to eq(expected_pathname)
end
end
end
end
context "when `global` is true" do
let(:has_global) { true }
let(:expected_pathname) { Pathname.new("#{Dir.home}/.Brewfile") }
it "returns the expected path" do
expect(path).to eq(expected_pathname)
end
context "when HOMEBREW_BUNDLE_FILE_GLOBAL is set" do
let(:env_bundle_file_global_value) { "/path/to/Brewfile" }
let(:expected_pathname) { Pathname.new(env_bundle_file_global_value) }
it "returns the value specified by the environment variable" do
expect(path).to eq(expected_pathname)
end
end
context "when HOMEBREW_BUNDLE_FILE is set" do
let(:env_bundle_file_value) { "/path/to/Brewfile" }
it "returns the value specified by the variable" do
expect { path }.to raise_error(RuntimeError)
end
end
context "when HOMEBREW_BUNDLE_FILE is `` (empty)" do
let(:env_bundle_file_value) { "" }
it "returns the value specified by `file` path" do
expect(path).to eq(expected_pathname)
end
end
context "when HOMEBREW_USER_CONFIG_HOME/Brewfile exists" do
let(:config_dir_brewfile_exist) { true }
let(:expected_pathname) { Pathname.new("#{env_user_config_home_value}/Brewfile") }
it "returns the expected path" do
expect(path).to eq(expected_pathname)
end
end
end
context "when HOMEBREW_BUNDLE_FILE has a value" do
let(:env_bundle_file_value) { "/path/to/Brewfile" }
it "returns the expected path" do
expect(path).to eq(Pathname.new(env_bundle_file_value))
end
describe "that is `` (empty)" do
let(:env_bundle_file_value) { "" }
it "defaults to `${PWD}/Brewfile`" do
expect(path).to eq(Pathname.new("Brewfile").expand_path(Dir.pwd))
end
end
describe "that is `nil`" do
let(:env_bundle_file_value) { nil }
it "defaults to `${PWD}/Brewfile`" do
expect(path).to eq(Pathname.new("Brewfile").expand_path(Dir.pwd))
end
end
end
end
end