Skip to content

Commit dc5a9db

Browse files
committed
Fixes #key missing for NilClass errors on empty folders
1 parent 9925b80 commit dc5a9db

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

lib/dry/files/memory_file_system.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ def entries(path)
401401
raise IOError, Errno::ENOENT.new(path.to_s) if node.nil?
402402
raise IOError, Errno::ENOTDIR.new(path.to_s) unless node.directory?
403403

404-
[".", ".."] + node.children.keys
404+
[".", ".."] + Array(node.children&.keys)
405405
end
406406

407407
private

spec/unit/dry/files/file_system_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,12 @@
609609
expect(subject.entries(root)).to eq [".", "..", "file-2.txt", "file-1.txt"]
610610
end
611611

612+
it "returns an array with only relative paths on an empty directory" do
613+
subject.mkdir(root.join("empty"))
614+
615+
expect(subject.entries(root.join("empty"))).to eq [".", ".."]
616+
end
617+
612618
it "raises error if directory doesn't exist" do
613619
path = root.join("non-existent")
614620

spec/unit/dry/files/memory_file_system_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,5 +660,11 @@ def call(*)
660660
"file-2.txt"
661661
]
662662
end
663+
664+
it "returns an array with only relative paths on an empty directory" do
665+
subject.mkdir("empty")
666+
667+
expect(subject.entries(subject.join("empty"))).to eq [".", ".."]
668+
end
663669
end
664670
end

0 commit comments

Comments
 (0)