|
18 | 18 | end |
19 | 19 |
|
20 | 20 | describe ".installed?" do |
21 | | - it "returns true when process is available" do |
22 | | - allow(IO).to receive(:popen).with(["overmind", "-v"]).and_return("Some version info") |
| 21 | + it "returns true when process is available in current context" do |
| 22 | + expect_any_instance_of(Kernel).to receive(:system) |
| 23 | + .with("overmind", "--version", out: File::NULL, err: File::NULL).and_return(true) |
23 | 24 | expect(described_class).to be_installed("overmind") |
24 | 25 | end |
25 | 26 |
|
26 | | - it "returns false when process is not available" do |
27 | | - allow(IO).to receive(:popen).with(["nonexistent", "-v"]).and_raise(Errno::ENOENT) |
| 27 | + it "returns false when process is not available in current context" do |
| 28 | + expect_any_instance_of(Kernel).to receive(:system) |
| 29 | + .with("nonexistent", "--version", out: File::NULL, err: File::NULL).and_raise(Errno::ENOENT) |
28 | 30 | expect(described_class.installed?("nonexistent")).to be false |
29 | 31 | end |
| 32 | + |
| 33 | + it "returns false when process returns false" do |
| 34 | + expect_any_instance_of(Kernel).to receive(:system) |
| 35 | + .with("failing_process", "--version", out: File::NULL, err: File::NULL).and_return(false) |
| 36 | + expect(described_class.installed?("failing_process")).to be false |
| 37 | + end |
30 | 38 | end |
31 | 39 |
|
32 | 40 | describe ".ensure_procfile" do |
|
50 | 58 | end |
51 | 59 |
|
52 | 60 | it "uses overmind when available" do |
53 | | - allow(described_class).to receive(:installed?).with("overmind").and_return(true) |
54 | | - expect_any_instance_of(Kernel).to receive(:system).with("overmind", "start", "-f", "Procfile.dev") |
| 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"]) |
55 | 63 |
|
56 | 64 | described_class.run_with_process_manager("Procfile.dev") |
57 | 65 | end |
58 | 66 |
|
59 | | - it "uses foreman when overmind not available and foreman is in bundle" do |
60 | | - allow(described_class).to receive(:installed?).with("overmind").and_return(false) |
61 | | - allow(described_class).to receive(:foreman_available?).and_return(true) |
62 | | - allow(described_class).to receive(:installed?).with("foreman").and_return(true) |
63 | | - expect(described_class).to receive(:run_foreman).with("Procfile.dev") |
| 67 | + 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"]) |
64 | 71 |
|
65 | 72 | described_class.run_with_process_manager("Procfile.dev") |
66 | 73 | end |
67 | 74 |
|
68 | 75 | it "exits with error when no process manager available" do |
69 | | - allow(described_class).to receive(:installed?).with("overmind").and_return(false) |
70 | | - allow(described_class).to receive(:foreman_available?).and_return(false) |
| 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) |
71 | 78 | expect(described_class).to receive(:show_process_manager_installation_help) |
72 | 79 | expect_any_instance_of(Kernel).to receive(:exit).with(1) |
73 | 80 |
|
74 | 81 | described_class.run_with_process_manager("Procfile.dev") |
75 | 82 | end |
76 | 83 |
|
77 | 84 | it "cleans up stale files before starting" do |
78 | | - allow(described_class).to receive(:installed?).with("overmind").and_return(true) |
| 85 | + allow(described_class).to receive(:process_available?).with("overmind").and_return(true) |
| 86 | + allow(described_class).to receive(:run_process) |
79 | 87 | expect(ReactOnRails::Dev::FileManager).to receive(:cleanup_stale_files) |
80 | 88 |
|
81 | 89 | described_class.run_with_process_manager("Procfile.dev") |
82 | 90 | end |
83 | 91 | end |
84 | 92 |
|
85 | | - describe ".foreman_available?" do |
86 | | - it "returns true when foreman is available in bundle context" do |
| 93 | + describe ".process_available?" do |
| 94 | + it "returns true when process is available in current context" do |
87 | 95 | allow(described_class).to receive(:installed?).with("foreman").and_return(true) |
88 | | - allow(described_class).to receive(:foreman_available_in_system?).and_return(false) |
| 96 | + allow(described_class).to receive(:process_available_in_system?).with("foreman").and_return(false) |
89 | 97 |
|
90 | | - expect(described_class.send(:foreman_available?)).to be true |
| 98 | + expect(described_class.send(:process_available?, "foreman")).to be true |
91 | 99 | end |
92 | 100 |
|
93 | | - it "returns true when foreman is available system-wide" do |
| 101 | + it "returns true when process is available system-wide" do |
94 | 102 | allow(described_class).to receive(:installed?).with("foreman").and_return(false) |
95 | | - allow(described_class).to receive(:foreman_available_in_system?).and_return(true) |
| 103 | + allow(described_class).to receive(:process_available_in_system?).with("foreman").and_return(true) |
96 | 104 |
|
97 | | - expect(described_class.send(:foreman_available?)).to be true |
| 105 | + expect(described_class.send(:process_available?, "foreman")).to be true |
98 | 106 | end |
99 | 107 |
|
100 | | - it "returns false when foreman is not available anywhere" do |
| 108 | + it "returns false when process is not available anywhere" do |
101 | 109 | allow(described_class).to receive(:installed?).with("foreman").and_return(false) |
102 | | - allow(described_class).to receive(:foreman_available_in_system?).and_return(false) |
| 110 | + allow(described_class).to receive(:process_available_in_system?).with("foreman").and_return(false) |
103 | 111 |
|
104 | | - expect(described_class.send(:foreman_available?)).to be false |
| 112 | + expect(described_class.send(:process_available?, "foreman")).to be false |
105 | 113 | end |
106 | 114 | end |
107 | 115 |
|
108 | | - describe ".run_foreman" do |
| 116 | + describe ".run_process" do |
109 | 117 | before do |
110 | 118 | allow_any_instance_of(Kernel).to receive(:system).and_return(true) |
111 | 119 | end |
112 | 120 |
|
113 | | - it "tries bundle context first when foreman is in bundle" do |
| 121 | + it "tries current context first when process works there" do |
114 | 122 | allow(described_class).to receive(:installed?).with("foreman").and_return(true) |
115 | 123 | expect_any_instance_of(Kernel).to receive(:system).with("foreman", "start", "-f", "Procfile.dev").and_return(true) |
116 | | - expect(described_class).not_to receive(:run_foreman_outside_bundle) |
| 124 | + expect(described_class).not_to receive(:run_process_outside_bundle) |
117 | 125 |
|
118 | | - described_class.send(:run_foreman, "Procfile.dev") |
| 126 | + described_class.send(:run_process, "foreman", ["start", "-f", "Procfile.dev"]) |
119 | 127 | end |
120 | 128 |
|
121 | | - it "falls back to system foreman when bundle context fails" do |
| 129 | + it "falls back to system process when current context fails" do |
122 | 130 | allow(described_class).to receive(:installed?).with("foreman").and_return(true) |
123 | 131 | expect_any_instance_of(Kernel).to receive(:system) |
124 | 132 | .with("foreman", "start", "-f", "Procfile.dev").and_return(false) |
125 | | - expect(described_class).to receive(:run_foreman_outside_bundle).with("Procfile.dev") |
| 133 | + expect(described_class).to receive(:run_process_outside_bundle).with("foreman", ["start", "-f", "Procfile.dev"]) |
126 | 134 |
|
127 | | - described_class.send(:run_foreman, "Procfile.dev") |
| 135 | + described_class.send(:run_process, "foreman", ["start", "-f", "Procfile.dev"]) |
128 | 136 | end |
129 | 137 |
|
130 | | - it "uses system foreman directly when not in bundle" do |
131 | | - allow(described_class).to receive(:installed?).with("foreman").and_return(false) |
132 | | - expect(described_class).to receive(:run_foreman_outside_bundle).with("Procfile.dev") |
| 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"]) |
133 | 141 |
|
134 | | - described_class.send(:run_foreman, "Procfile.dev") |
| 142 | + described_class.send(:run_process, "overmind", ["start", "-f", "Procfile.dev"]) |
135 | 143 | end |
136 | 144 | end |
137 | 145 |
|
138 | | - describe ".run_foreman_outside_bundle" do |
| 146 | + describe ".run_process_outside_bundle" do |
139 | 147 | it "uses Bundler.with_unbundled_env when Bundler is available" do |
140 | 148 | bundler_double = class_double(Bundler) |
141 | 149 | stub_const("Bundler", bundler_double) |
142 | 150 | expect(bundler_double).to receive(:with_unbundled_env).and_yield |
143 | 151 | expect_any_instance_of(Kernel).to receive(:system).with("foreman", "start", "-f", "Procfile.dev") |
144 | 152 |
|
145 | | - described_class.send(:run_foreman_outside_bundle, "Procfile.dev") |
| 153 | + described_class.send(:run_process_outside_bundle, "foreman", ["start", "-f", "Procfile.dev"]) |
146 | 154 | end |
147 | 155 |
|
148 | 156 | it "falls back to direct system call when Bundler is not available" do |
149 | 157 | hide_const("Bundler") |
150 | 158 | expect_any_instance_of(Kernel).to receive(:system).with("foreman", "start", "-f", "Procfile.dev") |
151 | 159 |
|
152 | | - described_class.send(:run_foreman_outside_bundle, "Procfile.dev") |
| 160 | + described_class.send(:run_process_outside_bundle, "foreman", ["start", "-f", "Procfile.dev"]) |
153 | 161 | end |
154 | 162 | end |
155 | 163 |
|
156 | | - describe ".foreman_available_in_system?" do |
157 | | - it "checks foreman availability outside bundle context" do |
| 164 | + describe ".process_available_in_system?" do |
| 165 | + it "checks process availability outside bundle context" do |
158 | 166 | bundler_double = class_double(Bundler) |
159 | 167 | stub_const("Bundler", bundler_double) |
160 | 168 | expect(bundler_double).to receive(:with_unbundled_env).and_yield |
161 | | - expect(described_class).to receive(:installed?).with("foreman").and_return(true) |
| 169 | + expect_any_instance_of(Kernel).to receive(:system) |
| 170 | + .with("foreman", "--version", out: File::NULL, err: File::NULL).and_return(true) |
162 | 171 |
|
163 | | - expect(described_class.send(:foreman_available_in_system?)).to be true |
| 172 | + expect(described_class.send(:process_available_in_system?, "foreman")).to be true |
164 | 173 | end |
165 | 174 |
|
166 | 175 | it "returns false when Bundler is not available" do |
167 | 176 | hide_const("Bundler") |
168 | 177 |
|
169 | | - expect(described_class.send(:foreman_available_in_system?)).to be false |
| 178 | + expect(described_class.send(:process_available_in_system?, "foreman")).to be false |
| 179 | + end |
| 180 | + |
| 181 | + it "returns false when process fails outside bundle context" do |
| 182 | + bundler_double = class_double(Bundler) |
| 183 | + stub_const("Bundler", bundler_double) |
| 184 | + expect(bundler_double).to receive(:with_unbundled_env).and_yield |
| 185 | + expect_any_instance_of(Kernel).to receive(:system) |
| 186 | + .with("overmind", "--version", out: File::NULL, err: File::NULL).and_return(false) |
| 187 | + |
| 188 | + expect(described_class.send(:process_available_in_system?, "overmind")).to be false |
170 | 189 | end |
171 | 190 | end |
172 | 191 |
|
|
0 commit comments