|
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) |
| 184 | + expect(described_class).to receive(:system) |
177 | 185 | .with(a_kind_of(Hash), "foreman", "start", "-f", "Procfile.dev") |
178 | 186 |
|
179 | 187 | described_class.send(:run_process_outside_bundle, "foreman", ["start", "-f", "Procfile.dev"]) |
|
185 | 193 | allow(ENV).to receive(:[]).with("SHAKAPACKER_DEV_SERVER_PORT").and_return("3036") |
186 | 194 |
|
187 | 195 | expect(described_class).to receive(:with_unbundled_context).and_yield |
188 | | - expect_any_instance_of(Kernel).to receive(:system) |
| 196 | + expect(described_class).to receive(:system) |
189 | 197 | .with({ "PORT" => "3001", "SHAKAPACKER_DEV_SERVER_PORT" => "3036" }, "foreman", "start", "-f", "Procfile.dev") |
190 | 198 |
|
191 | 199 | described_class.send(:run_process_outside_bundle, "foreman", ["start", "-f", "Procfile.dev"]) |
|
197 | 205 | allow(ENV).to receive(:[]).with("SHAKAPACKER_DEV_SERVER_PORT").and_return(nil) |
198 | 206 |
|
199 | 207 | expect(described_class).to receive(:with_unbundled_context).and_yield |
200 | | - expect_any_instance_of(Kernel).to receive(:system) |
| 208 | + expect(described_class).to receive(:system) |
201 | 209 | .with({ "PORT" => "3001" }, "foreman", "start", "-f", "Procfile.dev") |
202 | 210 |
|
203 | 211 | described_class.send(:run_process_outside_bundle, "foreman", ["start", "-f", "Procfile.dev"]) |
204 | 212 | end |
205 | 213 |
|
206 | 214 | it "falls back to direct system call when Bundler is not available" do |
207 | 215 | hide_const("Bundler") |
208 | | - expect_any_instance_of(Kernel).to receive(:system).with("foreman", "start", "-f", "Procfile.dev") |
| 216 | + expect(described_class).to receive(:system).with("foreman", "start", "-f", "Procfile.dev") |
209 | 217 |
|
210 | 218 | described_class.send(:run_process_outside_bundle, "foreman", ["start", "-f", "Procfile.dev"]) |
211 | 219 | end |
|
215 | 223 | it "checks process availability outside bundle context with version flags" do |
216 | 224 | expect(described_class).to receive(:with_unbundled_context).and_yield |
217 | 225 | expect(Timeout).to receive(:timeout).with(described_class::VERSION_CHECK_TIMEOUT).and_yield |
218 | | - expect_any_instance_of(Kernel).to receive(:system) |
| 226 | + expect(described_class).to receive(:system) |
219 | 227 | .with("foreman", "--version", out: File::NULL, err: File::NULL).and_return(true) |
220 | 228 |
|
221 | 229 | expect(described_class.send(:process_available_in_system?, "foreman")).to be true |
|
230 | 238 | it "tries multiple version flags before failing" do |
231 | 239 | expect(described_class).to receive(:with_unbundled_context).and_yield |
232 | 240 | expect(Timeout).to receive(:timeout).with(described_class::VERSION_CHECK_TIMEOUT).twice.and_yield |
233 | | - expect_any_instance_of(Kernel).to receive(:system) |
| 241 | + expect(described_class).to receive(:system) |
234 | 242 | .with("foreman", "--version", out: File::NULL, err: File::NULL).and_return(false) |
235 | | - expect_any_instance_of(Kernel).to receive(:system) |
| 243 | + expect(described_class).to receive(:system) |
236 | 244 | .with("foreman", "-v", out: File::NULL, err: File::NULL).and_return(true) |
237 | 245 |
|
238 | 246 | expect(described_class.send(:process_available_in_system?, "foreman")).to be true |
|
0 commit comments