Skip to content

Commit

Permalink
Fixes #key missing for NilClass errors on empty folders
Browse files Browse the repository at this point in the history
  • Loading branch information
nolantait committed Jul 9, 2024
1 parent 9925b80 commit dc5a9db
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dry/files/memory_file_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ def entries(path)
raise IOError, Errno::ENOENT.new(path.to_s) if node.nil?
raise IOError, Errno::ENOTDIR.new(path.to_s) unless node.directory?

[".", ".."] + node.children.keys
[".", ".."] + Array(node.children&.keys)
end

private
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/dry/files/file_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,12 @@
expect(subject.entries(root)).to eq [".", "..", "file-2.txt", "file-1.txt"]
end

it "returns an array with only relative paths on an empty directory" do
subject.mkdir(root.join("empty"))

expect(subject.entries(root.join("empty"))).to eq [".", ".."]
end

it "raises error if directory doesn't exist" do
path = root.join("non-existent")

Expand Down
6 changes: 6 additions & 0 deletions spec/unit/dry/files/memory_file_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -660,5 +660,11 @@ def call(*)
"file-2.txt"
]
end

it "returns an array with only relative paths on an empty directory" do
subject.mkdir("empty")

expect(subject.entries(subject.join("empty"))).to eq [".", ".."]
end
end
end

0 comments on commit dc5a9db

Please sign in to comment.