|
164 | 164 | end |
165 | 165 |
|
166 | 166 | describe "#which" do |
167 | | - let(:executable) { "executable" } |
| 167 | + it "can detect relative path" do |
| 168 | + script_path = bundled_app("tmp/test_command") |
| 169 | + create_file(script_path, "#!/usr/bin/env ruby\n") |
168 | 170 |
|
169 | | - let(:path) do |
170 | | - if Gem.win_platform? |
171 | | - %w[C:/a C:/b C:/c C:/../d C:/e] |
172 | | - else |
173 | | - %w[/a /b c ../d /e] |
| 171 | + result = Dir.chdir script_path.dirname.dirname do |
| 172 | + Bundler.which("test_command") |
174 | 173 | end |
175 | | - end |
| 174 | + expect(result).to eq(nil) |
176 | 175 |
|
177 | | - let(:expected) do |
178 | | - if Gem.win_platform? |
179 | | - "executable.exe" |
180 | | - else |
181 | | - "executable" |
| 176 | + result = Dir.chdir script_path.dirname do |
| 177 | + Bundler.which("test_command") |
182 | 178 | end |
183 | | - end |
184 | | - |
185 | | - before do |
186 | | - ENV["PATH"] = path.join(File::PATH_SEPARATOR) |
187 | 179 |
|
188 | | - allow(File).to receive(:file?).and_return(false) |
189 | | - allow(File).to receive(:executable?).and_return(false) |
190 | | - if expected |
191 | | - expect(File).to receive(:file?).with(expected).and_return(true) |
192 | | - expect(File).to receive(:executable?).with(expected).and_return(true) |
193 | | - end |
| 180 | + expect(result).to eq("test_command") unless Gem.win_platform? |
| 181 | + expect(result).to eq("test_command.bat") if Gem.win_platform? |
194 | 182 | end |
195 | 183 |
|
196 | | - subject { described_class.which(executable) } |
| 184 | + it "can detect absolute path" do |
| 185 | + create_file("test_command", "#!/usr/bin/env ruby\n") |
197 | 186 |
|
198 | | - shared_examples_for "it returns the correct executable" do |
199 | | - it "returns the expected file" do |
200 | | - expect(subject).to eq(expected) |
201 | | - end |
202 | | - end |
203 | | - |
204 | | - it_behaves_like "it returns the correct executable" |
| 187 | + ENV["PATH"] = bundled_app("test_command").parent.to_s |
205 | 188 |
|
206 | | - context "when the executable in inside a quoted path" do |
207 | | - let(:expected) do |
208 | | - if Gem.win_platform? |
209 | | - "C:/e/executable.exe" |
210 | | - else |
211 | | - "/e/executable" |
212 | | - end |
213 | | - end |
214 | | - it_behaves_like "it returns the correct executable" |
| 189 | + result = Bundler.which("test_command") |
| 190 | + expect(result).to eq(bundled_app("test_command").to_s) unless Gem.win_platform? |
| 191 | + expect(result).to eq(bundled_app("test_command.bat").to_s) if Gem.win_platform? |
215 | 192 | end |
216 | 193 |
|
217 | | - context "when the executable is not found" do |
218 | | - let(:expected) { nil } |
219 | | - it_behaves_like "it returns the correct executable" |
| 194 | + it "returns nil when not found" do |
| 195 | + result = Bundler.which("test_command") |
| 196 | + expect(result).to eq(nil) |
220 | 197 | end |
221 | 198 | end |
222 | 199 |
|
|
0 commit comments