|
30 | 30 | expect(described_class.installed?("nonexistent")).to be false |
31 | 31 | end |
32 | 32 |
|
33 | | - it "returns false when process returns false" do |
| 33 | + it "returns false when all version flags fail" do |
34 | 34 | expect_any_instance_of(Kernel).to receive(:system) |
35 | 35 | .with("failing_process", "--version", out: File::NULL, err: File::NULL).and_return(false) |
| 36 | + expect_any_instance_of(Kernel).to receive(:system) |
| 37 | + .with("failing_process", "-v", out: File::NULL, err: File::NULL).and_return(false) |
| 38 | + expect_any_instance_of(Kernel).to receive(:system) |
| 39 | + .with("failing_process", "-V", out: File::NULL, err: File::NULL).and_return(false) |
36 | 40 | expect(described_class.installed?("failing_process")).to be false |
37 | 41 | end |
| 42 | + |
| 43 | + it "returns true when second version flag succeeds" do |
| 44 | + expect_any_instance_of(Kernel).to receive(:system) |
| 45 | + .with("foreman", "--version", out: File::NULL, err: File::NULL).and_return(false) |
| 46 | + expect_any_instance_of(Kernel).to receive(:system) |
| 47 | + .with("foreman", "-v", out: File::NULL, err: File::NULL).and_return(true) |
| 48 | + expect(described_class.installed?("foreman")).to be true |
| 49 | + end |
38 | 50 | end |
39 | 51 |
|
40 | 52 | describe ".ensure_procfile" do |
|
58 | 70 | end |
59 | 71 |
|
60 | 72 | it "uses overmind when available" do |
61 | | - allow(described_class).to receive(:process_available?).with("overmind").and_return(true) |
62 | | - expect(described_class).to receive(:run_process).with("overmind", ["start", "-f", "Procfile.dev"]) |
| 73 | + expect(described_class).to receive(:run_process_if_available) |
| 74 | + .with("overmind", ["start", "-f", "Procfile.dev"]).and_return(true) |
63 | 75 |
|
64 | 76 | described_class.run_with_process_manager("Procfile.dev") |
65 | 77 | end |
66 | 78 |
|
67 | 79 | it "uses foreman when overmind not available and foreman is available" do |
68 | | - allow(described_class).to receive(:process_available?).with("overmind").and_return(false) |
69 | | - allow(described_class).to receive(:process_available?).with("foreman").and_return(true) |
70 | | - expect(described_class).to receive(:run_process).with("foreman", ["start", "-f", "Procfile.dev"]) |
| 80 | + expect(described_class).to receive(:run_process_if_available) |
| 81 | + .with("overmind", ["start", "-f", "Procfile.dev"]).and_return(false) |
| 82 | + expect(described_class).to receive(:run_process_if_available) |
| 83 | + .with("foreman", ["start", "-f", "Procfile.dev"]).and_return(true) |
71 | 84 |
|
72 | 85 | described_class.run_with_process_manager("Procfile.dev") |
73 | 86 | end |
74 | 87 |
|
75 | 88 | it "exits with error when no process manager available" do |
76 | | - allow(described_class).to receive(:process_available?).with("overmind").and_return(false) |
77 | | - allow(described_class).to receive(:process_available?).with("foreman").and_return(false) |
| 89 | + expect(described_class).to receive(:run_process_if_available) |
| 90 | + .with("overmind", ["start", "-f", "Procfile.dev"]).and_return(false) |
| 91 | + expect(described_class).to receive(:run_process_if_available) |
| 92 | + .with("foreman", ["start", "-f", "Procfile.dev"]).and_return(false) |
78 | 93 | expect(described_class).to receive(:show_process_manager_installation_help) |
79 | 94 | expect_any_instance_of(Kernel).to receive(:exit).with(1) |
80 | 95 |
|
81 | 96 | described_class.run_with_process_manager("Procfile.dev") |
82 | 97 | end |
83 | 98 |
|
84 | 99 | it "cleans up stale files before starting" do |
85 | | - allow(described_class).to receive(:process_available?).with("overmind").and_return(true) |
86 | | - allow(described_class).to receive(:run_process) |
| 100 | + allow(described_class).to receive(:run_process_if_available).and_return(true) |
87 | 101 | expect(ReactOnRails::Dev::FileManager).to receive(:cleanup_stale_files) |
88 | 102 |
|
89 | 103 | described_class.run_with_process_manager("Procfile.dev") |
90 | 104 | end |
91 | 105 | end |
92 | 106 |
|
93 | | - describe ".process_available?" do |
94 | | - it "returns true when process is available in current context" do |
| 107 | + describe ".run_process_if_available" do |
| 108 | + it "returns true and runs process when available in current context" do |
95 | 109 | allow(described_class).to receive(:installed?).with("foreman").and_return(true) |
96 | | - allow(described_class).to receive(:process_available_in_system?).with("foreman").and_return(false) |
| 110 | + expect_any_instance_of(Kernel).to receive(:system).with("foreman", "start", "-f", "Procfile.dev").and_return(true) |
97 | 111 |
|
98 | | - expect(described_class.send(:process_available?, "foreman")).to be true |
| 112 | + result = described_class.send(:run_process_if_available, "foreman", ["start", "-f", "Procfile.dev"]) |
| 113 | + expect(result).to be true |
99 | 114 | end |
100 | 115 |
|
101 | | - it "returns true when process is available system-wide" do |
| 116 | + it "tries system context when not available in current context" do |
102 | 117 | allow(described_class).to receive(:installed?).with("foreman").and_return(false) |
103 | 118 | allow(described_class).to receive(:process_available_in_system?).with("foreman").and_return(true) |
| 119 | + expect(described_class).to receive(:run_process_outside_bundle) |
| 120 | + .with("foreman", ["start", "-f", "Procfile.dev"]).and_return(true) |
104 | 121 |
|
105 | | - expect(described_class.send(:process_available?, "foreman")).to be true |
106 | | - end |
107 | | - |
108 | | - it "returns false when process is not available anywhere" do |
109 | | - allow(described_class).to receive(:installed?).with("foreman").and_return(false) |
110 | | - allow(described_class).to receive(:process_available_in_system?).with("foreman").and_return(false) |
111 | | - |
112 | | - expect(described_class.send(:process_available?, "foreman")).to be false |
113 | | - end |
114 | | - end |
115 | | - |
116 | | - describe ".run_process" do |
117 | | - before do |
118 | | - allow_any_instance_of(Kernel).to receive(:system).and_return(true) |
119 | | - end |
120 | | - |
121 | | - it "tries current context first when process works there" do |
122 | | - allow(described_class).to receive(:installed?).with("foreman").and_return(true) |
123 | | - expect_any_instance_of(Kernel).to receive(:system).with("foreman", "start", "-f", "Procfile.dev").and_return(true) |
124 | | - expect(described_class).not_to receive(:run_process_outside_bundle) |
125 | | - |
126 | | - described_class.send(:run_process, "foreman", ["start", "-f", "Procfile.dev"]) |
127 | | - end |
128 | | - |
129 | | - it "falls back to system process when current context fails" do |
130 | | - allow(described_class).to receive(:installed?).with("foreman").and_return(true) |
131 | | - expect_any_instance_of(Kernel).to receive(:system) |
132 | | - .with("foreman", "start", "-f", "Procfile.dev").and_return(false) |
133 | | - expect(described_class).to receive(:run_process_outside_bundle).with("foreman", ["start", "-f", "Procfile.dev"]) |
134 | | - |
135 | | - described_class.send(:run_process, "foreman", ["start", "-f", "Procfile.dev"]) |
| 122 | + result = described_class.send(:run_process_if_available, "foreman", ["start", "-f", "Procfile.dev"]) |
| 123 | + expect(result).to be true |
136 | 124 | end |
137 | 125 |
|
138 | | - it "uses system process directly when not available in current context" do |
139 | | - allow(described_class).to receive(:installed?).with("overmind").and_return(false) |
140 | | - expect(described_class).to receive(:run_process_outside_bundle).with("overmind", ["start", "-f", "Procfile.dev"]) |
| 126 | + it "returns false when process not available anywhere" do |
| 127 | + allow(described_class).to receive(:installed?).with("nonexistent").and_return(false) |
| 128 | + allow(described_class).to receive(:process_available_in_system?).with("nonexistent").and_return(false) |
141 | 129 |
|
142 | | - described_class.send(:run_process, "overmind", ["start", "-f", "Procfile.dev"]) |
| 130 | + result = described_class.send(:run_process_if_available, "nonexistent", ["start"]) |
| 131 | + expect(result).to be false |
143 | 132 | end |
144 | 133 | end |
145 | 134 |
|
|
162 | 151 | end |
163 | 152 |
|
164 | 153 | describe ".process_available_in_system?" do |
165 | | - it "checks process availability outside bundle context" do |
| 154 | + it "checks process availability outside bundle context with version flags" do |
166 | 155 | bundler_double = class_double(Bundler) |
167 | 156 | stub_const("Bundler", bundler_double) |
168 | 157 | expect(bundler_double).to receive(:with_unbundled_env).and_yield |
|
178 | 167 | expect(described_class.send(:process_available_in_system?, "foreman")).to be false |
179 | 168 | end |
180 | 169 |
|
181 | | - it "returns false when process fails outside bundle context" do |
| 170 | + it "tries multiple version flags before failing" do |
182 | 171 | bundler_double = class_double(Bundler) |
183 | 172 | stub_const("Bundler", bundler_double) |
184 | 173 | expect(bundler_double).to receive(:with_unbundled_env).and_yield |
185 | 174 | expect_any_instance_of(Kernel).to receive(:system) |
186 | | - .with("overmind", "--version", out: File::NULL, err: File::NULL).and_return(false) |
| 175 | + .with("foreman", "--version", out: File::NULL, err: File::NULL).and_return(false) |
| 176 | + expect_any_instance_of(Kernel).to receive(:system) |
| 177 | + .with("foreman", "-v", out: File::NULL, err: File::NULL).and_return(true) |
| 178 | + |
| 179 | + expect(described_class.send(:process_available_in_system?, "foreman")).to be true |
| 180 | + end |
| 181 | + end |
| 182 | + |
| 183 | + describe ".version_flags_for" do |
| 184 | + it "returns specific flags for overmind" do |
| 185 | + expect(described_class.send(:version_flags_for, "overmind")).to eq(["--version"]) |
| 186 | + end |
| 187 | + |
| 188 | + it "returns multiple flags for foreman" do |
| 189 | + expect(described_class.send(:version_flags_for, "foreman")).to eq(["--version", "-v"]) |
| 190 | + end |
187 | 191 |
|
188 | | - expect(described_class.send(:process_available_in_system?, "overmind")).to be false |
| 192 | + it "returns generic flags for unknown processes" do |
| 193 | + expect(described_class.send(:version_flags_for, "unknown")).to eq(["--version", "-v", "-V"]) |
189 | 194 | end |
190 | 195 | end |
191 | 196 |
|
|
0 commit comments