From a1527f3b6158ab0edd348fd98b71ed77d7ae8019 Mon Sep 17 00:00:00 2001 From: Yves Siegrist Date: Tue, 24 Jan 2017 09:03:59 +0100 Subject: [PATCH] fix tests --- lib/dotenv/rails.rb | 19 ++++++++++++------- spec/dotenv/rails_development_spec.rb | 10 +++++----- spec/dotenv/rails_test_spec.rb | 3 ++- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/dotenv/rails.rb b/lib/dotenv/rails.rb index ca1d761a..86e796f8 100644 --- a/lib/dotenv/rails.rb +++ b/lib/dotenv/rails.rb @@ -35,13 +35,7 @@ class Railtie < Rails::Railtie # This will get called during the `before_configuration` callback, but you # can manually call `Dotenv::Railtie.load` if you needed it sooner. def load - envs = [ - root.join(".env.#{Rails.env}.local"), - root.join(".env.#{Rails.env}"), - root.join(".env") - ] - envs.insert(1, root.join(".env.local")) unless Rails.env == 'test' - Dotenv.load(*envs) + Dotenv.load(*dotenv_files) end # Internal: `Rails.root` is nil in Rails 4.1 before the application is @@ -58,5 +52,16 @@ def self.load end config.before_configuration { load } + + private + def dotenv_files + envs = [ + root.join(".env.#{Rails.env}.local"), + root.join(".env.#{Rails.env}"), + root.join(".env") + ] + envs.insert(1, root.join(".env.local")) unless Rails.env == 'test' + envs + end end end diff --git a/spec/dotenv/rails_development_spec.rb b/spec/dotenv/rails_development_spec.rb index e1922e44..e476a151 100644 --- a/spec/dotenv/rails_development_spec.rb +++ b/spec/dotenv/rails_development_spec.rb @@ -20,6 +20,7 @@ def add(*items) ENV["RAILS_ENV"] = "development" allow(Rails).to receive(:root) .and_return Pathname.new(File.expand_path("../../fixtures", __FILE__)) + allow(Rails).to receive(:env).and_return "development" Rails.application = double(:application) Spring.watcher = SpecWatcher.new end @@ -52,12 +53,11 @@ def add(*items) end it "loads .env, .env.local, and .env.#{Rails.env}" do - p Rails.root - expect(Spring.watcher.items).to eql( + expect(Dotenv::Railtie.instance.send(:dotenv_files)).to eql( [ - Rails.root.join(".env.local").to_s, - Rails.root.join(".env.development").to_s, - Rails.root.join(".env").to_s + Rails.root.join(".env.local"), + Rails.root.join(".env.development"), + Rails.root.join(".env") ] ) end diff --git a/spec/dotenv/rails_test_spec.rb b/spec/dotenv/rails_test_spec.rb index 8e4343fd..008d45dd 100644 --- a/spec/dotenv/rails_test_spec.rb +++ b/spec/dotenv/rails_test_spec.rb @@ -20,6 +20,7 @@ def add(*items) ENV["RAILS_ENV"] = "test" allow(Rails).to receive(:root) .and_return Pathname.new(File.expand_path("../../fixtures", __FILE__)) + allow(Rails).to receive(:env).and_return "test" Rails.application = double(:application) Spring.watcher = SpecWatcher.new end @@ -52,7 +53,7 @@ def add(*items) end it "does not load .env.local in test rails environment" do - expect(Spring.watcher.items).to eql( + expect(Dotenv::Railtie.instance.send(:dotenv_files)).to eql( [ Rails.root.join(".env.test.local").to_s, Rails.root.join(".env.test").to_s,