|
10 | 10 | end
|
11 | 11 |
|
12 | 12 | context "when a Brewfile is found" do
|
13 |
| - it "does not raise an error" do |
14 |
| - allow(described_class).to receive(:exec).and_return(nil) |
15 |
| - allow_any_instance_of(Pathname).to receive(:read) |
16 |
| - .and_return("brew 'openssl'") |
| 13 | + let(:brewfile_contents) { "brew 'openssl'" } |
17 | 14 |
|
18 |
| - expect { described_class.run("bundle", "install") }.not_to raise_error |
| 15 | + before do |
| 16 | + allow_any_instance_of(Pathname).to receive(:read) |
| 17 | + .and_return(brewfile_contents) |
19 | 18 | end
|
20 | 19 |
|
21 |
| - it "is able to run without bundle arguments" do |
22 |
| - allow(described_class).to receive(:exec).with("bundle", "install").and_return(nil) |
23 |
| - allow_any_instance_of(Pathname).to receive(:read) |
24 |
| - .and_return("brew 'openssl'") |
| 20 | + context "with valid command setup" do |
| 21 | + before do |
| 22 | + allow(described_class).to receive(:exec).and_return(nil) |
| 23 | + end |
25 | 24 |
|
26 |
| - expect { described_class.run("bundle", "install") }.not_to raise_error |
27 |
| - end |
| 25 | + it "does not raise an error" do |
| 26 | + expect { described_class.run("bundle", "install") }.not_to raise_error |
| 27 | + end |
28 | 28 |
|
29 |
| - it "raises an exception if called without a command" do |
30 |
| - allow(described_class).to receive(:exec).and_return(nil) |
31 |
| - allow_any_instance_of(Pathname).to receive(:read) |
32 |
| - .and_return("brew 'openssl'") |
| 29 | + it "does not raise an error when HOMEBREW_BUNDLE_EXEC_ALL_KEG_ONLY_DEPS is set" do |
| 30 | + ENV["HOMEBREW_BUNDLE_EXEC_ALL_KEG_ONLY_DEPS"] = "1" |
| 31 | + expect { described_class.run("bundle", "install") }.not_to raise_error |
| 32 | + end |
33 | 33 |
|
34 |
| - expect { described_class.run }.to raise_error(RuntimeError) |
| 34 | + it "uses the formula version from the environment variable" do |
| 35 | + openssl_version = "1.1.1" |
| 36 | + ENV["PATH"] = "/opt/homebrew/opt/openssl/bin" |
| 37 | + ENV["HOMEBREW_BUNDLE_EXEC_FORMULA_VERSION_OPENSSL"] = openssl_version |
| 38 | + described_class.run("bundle", "install") |
| 39 | + expect(ENV["PATH"]).to include("/Cellar/openssl/1.1.1/bin") |
| 40 | + end |
| 41 | + |
| 42 | + it "is able to run without bundle arguments" do |
| 43 | + allow(described_class).to receive(:exec).with("bundle", "install").and_return(nil) |
| 44 | + expect { described_class.run("bundle", "install") }.not_to raise_error |
| 45 | + end |
| 46 | + |
| 47 | + it "raises an exception if called without a command" do |
| 48 | + expect { described_class.run }.to raise_error(RuntimeError) |
| 49 | + end |
35 | 50 | end
|
36 | 51 |
|
37 | 52 | it "raises if called with a command that's not on the PATH" do
|
38 | 53 | allow(described_class).to receive_messages(exec: nil, which: nil)
|
39 |
| - allow_any_instance_of(Pathname).to receive(:read) |
40 |
| - .and_return("brew 'openssl'") |
41 |
| - |
42 | 54 | expect { described_class.run("bundle", "install") }.to raise_error(RuntimeError)
|
43 | 55 | end
|
44 | 56 |
|
|
47 | 59 | expect(described_class).to receive(:which).and_return(Pathname("/usr/local/bin/bundle"))
|
48 | 60 | allow(ENV).to receive(:prepend_path).with(any_args).and_call_original
|
49 | 61 | expect(ENV).to receive(:prepend_path).with("PATH", "/usr/local/bin").once.and_call_original
|
50 |
| - allow_any_instance_of(Pathname).to receive(:read) |
51 |
| - .and_return("brew 'openssl'") |
52 | 62 | described_class.run("bundle", "install")
|
53 | 63 | end
|
54 | 64 |
|
55 | 65 | describe "when running a command which exists but is not on the PATH" do
|
56 |
| - it "does not raise if the command is a relative path with current directory indicator" do |
57 |
| - allow(described_class).to receive(:exec).with("./configure").and_return(nil) |
58 |
| - expect(described_class).not_to receive(:which) |
59 |
| - allow_any_instance_of(Pathname).to receive(:read) |
60 |
| - .and_return("brew 'zlib'") |
61 |
| - |
62 |
| - expect { described_class.run("./configure") }.not_to raise_error |
| 66 | + let(:brewfile_contents) { "brew 'zlib'" } |
| 67 | + |
| 68 | + shared_examples "allows command execution" do |command| |
| 69 | + it "does not raise" do |
| 70 | + allow(described_class).to receive(:exec).with(command).and_return(nil) |
| 71 | + expect(described_class).not_to receive(:which) |
| 72 | + expect { described_class.run(command) }.not_to raise_error |
| 73 | + end |
63 | 74 | end
|
64 | 75 |
|
65 |
| - it "does not raise if the command is a relative path without current directory indicator" do |
66 |
| - allow(described_class).to receive(:exec).with("bin/install").and_return(nil) |
67 |
| - expect(described_class).not_to receive(:which) |
68 |
| - allow_any_instance_of(Pathname).to receive(:read) |
69 |
| - .and_return("brew 'zlib'") |
70 |
| - |
71 |
| - expect { described_class.run("bin/install") }.not_to raise_error |
72 |
| - end |
73 |
| - |
74 |
| - it "does not raise if the command is an absolute path" do |
75 |
| - allow(described_class).to receive(:exec).with("/Users/admin/Downloads/command").and_return(nil) |
76 |
| - expect(described_class).not_to receive(:which) |
77 |
| - allow_any_instance_of(Pathname).to receive(:read) |
78 |
| - .and_return("brew 'zlib'") |
79 |
| - |
80 |
| - expect { described_class.run("/Users/admin/Downloads/command") }.not_to raise_error |
81 |
| - end |
| 76 | + it_behaves_like "allows command execution", "./configure" |
| 77 | + it_behaves_like "allows command execution", "bin/install" |
| 78 | + it_behaves_like "allows command execution", "/Users/admin/Downloads/command" |
82 | 79 | end
|
83 | 80 |
|
84 | 81 | describe "when the Brewfile contains rbenv" do
|
85 |
| - before { ENV["HOMEBREW_RBENV_ROOT"] = rbenv_root.to_s } |
86 |
| - |
87 | 82 | let(:rbenv_root) { Pathname.new("/tmp/.rbenv") }
|
| 83 | + let(:brewfile_contents) { "brew 'rbenv'" } |
| 84 | + |
| 85 | + before do |
| 86 | + ENV["HOMEBREW_RBENV_ROOT"] = rbenv_root.to_s |
| 87 | + end |
88 | 88 |
|
89 | 89 | it "prepends the path of the rbenv shims to PATH before running" do
|
90 | 90 | allow(described_class).to receive(:exec).with("/usr/bin/true").and_return(0)
|
91 |
| - allow_any_instance_of(Pathname).to receive(:read) |
92 |
| - .and_return("brew 'rbenv'") |
93 | 91 | allow(ENV).to receive(:fetch).with(any_args).and_call_original
|
94 | 92 | allow(ENV).to receive(:prepend_path).with(any_args).once.and_call_original
|
95 | 93 |
|
|
0 commit comments