|
17 | 17 | it 'can glob directories with URI special chars in it (GH-2264)' do |
18 | 18 | expect(Dir.glob("#{dir_name}/**/*").size).to eq 1 |
19 | 19 | end |
20 | | -end |
21 | 20 |
|
22 | | -describe "Dir.glob" do |
23 | 21 | # We have common option processing code and a logic mistake made |
24 | 22 | # us process argv[2] as both a kwarg then try to convert it to an |
25 | 23 | # integer. |
26 | 24 | it "does not think the third arg should be an integer when it is kwargs" do |
27 | 25 | expect { Dir["*", "*", base: "."] }.not_to raise_error |
28 | 26 | end |
| 27 | + |
| 28 | + describe "with a uri:classloader: scheme" do |
| 29 | + before :all do |
| 30 | + # FIXME: unsanitary because we can't clear entries from $CLASSPATH |
| 31 | + $CLASSPATH << __dir__ |
| 32 | + end |
| 33 | + |
| 34 | + it "can find a specific file" do |
| 35 | + test1_files = Dir.glob("uri:classloader:/fixtures/test1.txt") |
| 36 | + expect(test1_files[0]).to eq "uri:classloader:/fixtures/test1.txt" |
| 37 | + expect(File.read(test1_files[0])).to eq "test1" |
| 38 | + end |
| 39 | + |
| 40 | + it "can find a set of files for a wildcard filename" do |
| 41 | + test_txt_files = Dir.glob("uri:classloader:/fixtures/test*.txt") |
| 42 | + expect(test_txt_files).to eq %w[test1 test2 test3].map { "uri:classloader:/fixtures/#{_1}.txt" } |
| 43 | + test_txt_files.each { expect(File.read(_1)).to eq File.basename(_1).split(".").first } |
| 44 | + |
| 45 | + test_txt_files = Dir.glob("uri:classloader:/fixtures/test?.txt") |
| 46 | + expect(test_txt_files).to eq %w[test1 test2 test3].map { "uri:classloader:/fixtures/#{_1}.txt" } |
| 47 | + test_txt_files.each { expect(File.read(_1)).to eq File.basename(_1).split(".").first } |
| 48 | + end |
| 49 | + |
| 50 | + it "can find a specific file in a double star path" do |
| 51 | + test5_files = Dir.glob("uri:classloader:/fixtures/**/test4.txt") |
| 52 | + expect(test5_files[0]).to eq "uri:classloader:/fixtures/testdir/test4.txt" |
| 53 | + expect(File.read(test5_files[0])).to eq "test4" |
| 54 | + end |
| 55 | + end |
| 56 | + |
| 57 | + describe "with a file: scheme" do |
| 58 | + it "can find a specific file" do |
| 59 | + test1_files = Dir.glob("file:#{__dir__}/fixtures/test1.txt") |
| 60 | + expect(test1_files[0]).to eq "file:#{__dir__}/fixtures/test1.txt" |
| 61 | + expect(File.read(test1_files[0])).to eq "test1" |
| 62 | + end |
| 63 | + |
| 64 | + it "can find a set of files for a wildcard filename" do |
| 65 | + test_txt_files = Dir.glob("file:#{__dir__}/fixtures/test*.txt") |
| 66 | + expect(test_txt_files).to eq %w[test1 test2 test3].map { "file:#{__dir__}/fixtures/#{_1}.txt" } |
| 67 | + test_txt_files.each { expect(File.read(_1)).to eq File.basename(_1).split(".").first } |
| 68 | + |
| 69 | + test_txt_files = Dir.glob("file:#{__dir__}/fixtures/test?.txt") |
| 70 | + expect(test_txt_files).to eq %w[test1 test2 test3].map { "file:#{__dir__}/fixtures/#{_1}.txt" } |
| 71 | + test_txt_files.each { expect(File.read(_1)).to eq File.basename(_1).split(".").first } |
| 72 | + end |
| 73 | + |
| 74 | + it "can find a specific file in a double star path" do |
| 75 | + test5_files = Dir.glob("file:#{__dir__}/fixtures/**/test4.txt") |
| 76 | + expect(test5_files[0]).to eq "file:#{__dir__}/fixtures/testdir/test4.txt" |
| 77 | + expect(File.read(test5_files[0])).to eq "test4" |
| 78 | + end |
| 79 | + end |
29 | 80 | end |
30 | 81 |
|
31 | 82 |
|
0 commit comments