Skip to content

Commit c70fe0c

Browse files
committed
Merge branch 'Roupiye/main'
* Roupiye/main: Add specs for loading a directory fix crash when .env is a folder
2 parents 53920cd + 134c867 commit c70fe0c

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/dotenv.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def parse(*filenames, overwrite: false, ignore: true, &block)
5555
begin
5656
env = Environment.new(File.expand_path(filename), overwrite: overwrite)
5757
env = block.call(env) if block
58-
rescue Errno::ENOENT
58+
rescue Errno::ENOENT, Errno::EISDIR
5959
raise unless ignore
6060
end
6161

spec/dotenv_spec.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@
8686

8787
describe "load" do
8888
let(:env_files) { [] }
89-
subject { Dotenv.load(*env_files) }
89+
let(:options) { {}}
90+
subject { Dotenv.load(*env_files, **options) }
9091

9192
it_behaves_like "load"
9293

@@ -107,6 +108,26 @@
107108
expect { subject }.not_to change { ENV.inspect }
108109
end
109110
end
111+
112+
context "when the file is a directory" do
113+
let(:env_files) { [] }
114+
115+
around do |example|
116+
Dir.mktmpdir do |dir|
117+
env_files.push dir
118+
example.run
119+
end
120+
end
121+
122+
it "fails silently with ignore: true (default)" do
123+
expect { subject }.not_to raise_error
124+
end
125+
126+
it "raises error with ignore: false" do
127+
options[:ignore] = false
128+
expect { subject }.to raise_error(/Is a directory/)
129+
end
130+
end
110131
end
111132

112133
describe "load!" do

0 commit comments

Comments
 (0)