Skip to content

Commit

Permalink
Add spec for no .env files present
Browse files Browse the repository at this point in the history
  • Loading branch information
azimux committed Jan 13, 2024
1 parent c777e36 commit e7e0ee2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Empty file added spec/fixtures/no_dotenvs/.keep
Empty file.
5 changes: 5 additions & 0 deletions spec/fixtures/no_root_dotenv/.env.development.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DOTENV=.env.development.test
ENV_VAR=.env.development.test
DEVELOPMENT_TEST=.env.development.test
DEVELOPMENT=.env.development.test
TEST=.env.development.test
24 changes: 23 additions & 1 deletion spec/load_dotenv_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
RSpec.describe Foobara::LoadDotenv do
let(:dir) { "#{__dir__}/fixtures/test_dotenvs" }

it "has a version number" do
expect(Foobara::LoadDotenv::VERSION).to_not be_nil
end
Expand All @@ -12,7 +14,7 @@
let(:env) { "development" }

it "applies .env.development.local" do
described_class.run!(env:, dir: "#{__dir__}/fixtures/test_dotenvs")
described_class.run!(env:, dir:)

expect(Dotenv).to have_received(:load!).with(
".env.development.test.local",
Expand All @@ -23,6 +25,26 @@
".env"
)
end

context "when no .env files" do
let(:dir) { "#{__dir__}/fixtures/no_dotenvs" }

it "does nothing" do
expect {
described_class.run!(env:, dir:)
}.to_not raise_error
end
end

context "when no root .env file but there are others" do
let(:dir) { "#{__dir__}/fixtures/no_root_dotenv" }

it "does not try to load .env" do
described_class.run!(env:, dir:)

expect(Dotenv).to have_received(:load!).with(".env.development.test")
end
end
end
end
end

0 comments on commit e7e0ee2

Please sign in to comment.