|
7 | 7 | describe ".installed?" do |
8 | 8 | it "returns true when process is available in current context" do |
9 | 9 | expect(Timeout).to receive(:timeout).with(described_class::VERSION_CHECK_TIMEOUT).and_yield |
10 | | - expect_any_instance_of(Kernel).to receive(:system) |
| 10 | + expect(described_class).to receive(:system) |
11 | 11 | .with("overmind", "--version", out: File::NULL, err: File::NULL).and_return(true) |
12 | 12 | expect(described_class).to be_installed("overmind") |
13 | 13 | end |
|
19 | 19 |
|
20 | 20 | it "returns false when all version flags fail" do |
21 | 21 | expect(Timeout).to receive(:timeout).with(described_class::VERSION_CHECK_TIMEOUT).exactly(3).times.and_yield |
22 | | - expect_any_instance_of(Kernel).to receive(:system) |
| 22 | + expect(described_class).to receive(:system) |
23 | 23 | .with("failing_process", "--version", out: File::NULL, err: File::NULL).and_return(false) |
24 | | - expect_any_instance_of(Kernel).to receive(:system) |
| 24 | + expect(described_class).to receive(:system) |
25 | 25 | .with("failing_process", "-v", out: File::NULL, err: File::NULL).and_return(false) |
26 | | - expect_any_instance_of(Kernel).to receive(:system) |
| 26 | + expect(described_class).to receive(:system) |
27 | 27 | .with("failing_process", "-V", out: File::NULL, err: File::NULL).and_return(false) |
28 | 28 | expect(described_class.installed?("failing_process")).to be false |
29 | 29 | end |
30 | 30 |
|
31 | 31 | it "returns true when second version flag succeeds" do |
32 | 32 | expect(Timeout).to receive(:timeout).with(described_class::VERSION_CHECK_TIMEOUT).twice.and_yield |
33 | | - expect_any_instance_of(Kernel).to receive(:system) |
| 33 | + expect(described_class).to receive(:system) |
34 | 34 | .with("foreman", "--version", out: File::NULL, err: File::NULL).and_return(false) |
35 | | - expect_any_instance_of(Kernel).to receive(:system) |
| 35 | + expect(described_class).to receive(:system) |
36 | 36 | .with("foreman", "-v", out: File::NULL, err: File::NULL).and_return(true) |
37 | 37 | expect(described_class.installed?("foreman")).to be true |
38 | 38 | end |
|
51 | 51 |
|
52 | 52 | it "exits with error when Procfile does not exist" do |
53 | 53 | allow(File).to receive(:exist?).with("Procfile.dev").and_return(false) |
54 | | - expect_any_instance_of(Kernel).to receive(:exit).with(1) |
| 54 | + expect(described_class).to receive(:exit).with(1) |
55 | 55 | described_class.ensure_procfile("Procfile.dev") |
56 | 56 | end |
57 | 57 | end |
58 | 58 |
|
59 | 59 | describe ".run_with_process_manager" do |
60 | 60 | before do |
61 | 61 | allow(ReactOnRails::Dev::FileManager).to receive(:cleanup_stale_files) |
62 | | - allow_any_instance_of(Kernel).to receive(:system).and_return(true) |
| 62 | + allow(described_class).to receive(:system).and_return(true) |
63 | 63 | allow(File).to receive(:readable?).and_return(true) |
64 | 64 | end |
65 | 65 |
|
|
85 | 85 | expect(described_class).to receive(:run_process_if_available) |
86 | 86 | .with("foreman", ["start", "-f", "Procfile.dev"]).and_return(nil) |
87 | 87 | expect(described_class).not_to receive(:show_process_manager_installation_help) |
88 | | - expect_any_instance_of(Kernel).to receive(:exit).with(1).and_raise(SystemExit) |
| 88 | + expect(described_class).to receive(:exit).with(1).and_raise(SystemExit) |
89 | 89 |
|
90 | 90 | expect { described_class.run_with_process_manager("Procfile.dev") }.to raise_error(SystemExit) |
91 | 91 | end |
|
96 | 96 | expect(described_class).to receive(:run_process_if_available) |
97 | 97 | .with("foreman", ["start", "-f", "Procfile.dev"]).and_return(true) |
98 | 98 | expect(described_class).not_to receive(:show_process_manager_installation_help) |
99 | | - expect_any_instance_of(Kernel).not_to receive(:exit) |
| 99 | + expect(described_class).not_to receive(:exit) |
100 | 100 |
|
101 | 101 | described_class.run_with_process_manager("Procfile.dev") |
102 | 102 | end |
|
107 | 107 | expect(described_class).to receive(:run_process_if_available) |
108 | 108 | .with("foreman", ["start", "-f", "Procfile.dev"]).and_return(false) |
109 | 109 | expect(described_class).not_to receive(:show_process_manager_installation_help) |
110 | | - expect_any_instance_of(Kernel).to receive(:exit).with(1).and_raise(SystemExit) |
| 110 | + expect(described_class).to receive(:exit).with(1).and_raise(SystemExit) |
111 | 111 |
|
112 | 112 | expect { described_class.run_with_process_manager("Procfile.dev") }.to raise_error(SystemExit) |
113 | 113 | end |
|
118 | 118 | expect(described_class).to receive(:run_process_if_available) |
119 | 119 | .with("foreman", ["start", "-f", "Procfile.dev"]).and_return(false) |
120 | 120 | expect(described_class).not_to receive(:show_process_manager_installation_help) |
121 | | - expect_any_instance_of(Kernel).to receive(:exit).with(1).and_raise(SystemExit) |
| 121 | + expect(described_class).to receive(:exit).with(1).and_raise(SystemExit) |
122 | 122 |
|
123 | 123 | expect { described_class.run_with_process_manager("Procfile.dev") }.to raise_error(SystemExit) |
124 | 124 | end |
|
129 | 129 | expect(described_class).to receive(:run_process_if_available) |
130 | 130 | .with("foreman", ["start", "-f", "Procfile.dev"]).and_return(nil) |
131 | 131 | expect(described_class).to receive(:show_process_manager_installation_help) |
132 | | - expect_any_instance_of(Kernel).to receive(:exit).with(1) |
| 132 | + expect(described_class).to receive(:exit).with(1) |
133 | 133 |
|
134 | 134 | described_class.run_with_process_manager("Procfile.dev") |
135 | 135 | end |
|
145 | 145 | describe ".run_process_if_available" do |
146 | 146 | it "returns true and runs process when available in current context" do |
147 | 147 | allow(described_class).to receive(:installed?).with("foreman").and_return(true) |
148 | | - expect_any_instance_of(Kernel).to receive(:system).with("foreman", "start", "-f", "Procfile.dev").and_return(true) |
| 148 | + expect(described_class).to receive(:system).with("foreman", "start", "-f", "Procfile.dev").and_return(true) |
| 149 | + |
| 150 | + result = described_class.send(:run_process_if_available, "foreman", ["start", "-f", "Procfile.dev"]) |
| 151 | + expect(result).to be true |
| 152 | + end |
| 153 | + |
| 154 | + it "returns true when interrupted while waiting on the process manager" do |
| 155 | + allow(described_class).to receive(:installed?).with("foreman").and_return(true) |
| 156 | + expect(described_class).to receive(:system).with("foreman", "start", "-f", "Procfile.dev").and_raise(Interrupt) |
149 | 157 |
|
150 | 158 | result = described_class.send(:run_process_if_available, "foreman", ["start", "-f", "Procfile.dev"]) |
151 | 159 | expect(result).to be true |
|
173 | 181 | describe ".run_process_outside_bundle" do |
174 | 182 | it "uses with_unbundled_context when Bundler is available" do |
175 | 183 | expect(described_class).to receive(:with_unbundled_context).and_yield |
176 | | - expect_any_instance_of(Kernel).to receive(:system).with("foreman", "start", "-f", "Procfile.dev") |
| 184 | + expect(described_class).to receive(:system).with("foreman", "start", "-f", "Procfile.dev") |
177 | 185 |
|
178 | 186 | described_class.send(:run_process_outside_bundle, "foreman", ["start", "-f", "Procfile.dev"]) |
179 | 187 | end |
180 | 188 |
|
181 | 189 | it "falls back to direct system call when Bundler is not available" do |
182 | 190 | hide_const("Bundler") |
183 | | - expect_any_instance_of(Kernel).to receive(:system).with("foreman", "start", "-f", "Procfile.dev") |
| 191 | + expect(described_class).to receive(:system).with("foreman", "start", "-f", "Procfile.dev") |
184 | 192 |
|
185 | 193 | described_class.send(:run_process_outside_bundle, "foreman", ["start", "-f", "Procfile.dev"]) |
186 | 194 | end |
|
190 | 198 | it "checks process availability outside bundle context with version flags" do |
191 | 199 | expect(described_class).to receive(:with_unbundled_context).and_yield |
192 | 200 | expect(Timeout).to receive(:timeout).with(described_class::VERSION_CHECK_TIMEOUT).and_yield |
193 | | - expect_any_instance_of(Kernel).to receive(:system) |
| 201 | + expect(described_class).to receive(:system) |
194 | 202 | .with("foreman", "--version", out: File::NULL, err: File::NULL).and_return(true) |
195 | 203 |
|
196 | 204 | expect(described_class.send(:process_available_in_system?, "foreman")).to be true |
|
205 | 213 | it "tries multiple version flags before failing" do |
206 | 214 | expect(described_class).to receive(:with_unbundled_context).and_yield |
207 | 215 | expect(Timeout).to receive(:timeout).with(described_class::VERSION_CHECK_TIMEOUT).twice.and_yield |
208 | | - expect_any_instance_of(Kernel).to receive(:system) |
| 216 | + expect(described_class).to receive(:system) |
209 | 217 | .with("foreman", "--version", out: File::NULL, err: File::NULL).and_return(false) |
210 | | - expect_any_instance_of(Kernel).to receive(:system) |
| 218 | + expect(described_class).to receive(:system) |
211 | 219 | .with("foreman", "-v", out: File::NULL, err: File::NULL).and_return(true) |
212 | 220 |
|
213 | 221 | expect(described_class.send(:process_available_in_system?, "foreman")).to be true |
|
0 commit comments