Skip to content

Commit 08f2214

Browse files
author
Andrew Nordman
authored
Merge pull request #405 from dsander/default-rake-task
Set RAILS_ENV to test when executing the default rake task
2 parents 6649549 + c047f03 commit 08f2214

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/dotenv/rails.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require "dotenv"
22

3-
# Fix for rspec rake tasks loading in development
3+
# Fix for rake tasks loading in development
44
#
55
# Dotenv loads environment variables when the Rails application is initialized.
66
# When running `rake`, the Rails application is initialized in development.
@@ -9,8 +9,10 @@
99
#
1010
# See https://github.com/bkeepers/dotenv/issues/219
1111
if defined?(Rake.application)
12-
if Rake.application.top_level_tasks.grep(/^(parallel:spec|spec(:|$))/).any?
13-
Rails.env = ENV["RAILS_ENV"] ||= "test"
12+
task_regular_expression = /^(default$|parallel:spec|spec(:|$))/
13+
if Rake.application.top_level_tasks.grep(task_regular_expression).any?
14+
environment = Rake.application.options.show_tasks ? "development" : "test"
15+
Rails.env = ENV["RAILS_ENV"] ||= environment
1416
end
1517
end
1618

0 commit comments

Comments
 (0)