Skip to content

Commit

Permalink
Merge pull request #405 from dsander/default-rake-task
Browse files Browse the repository at this point in the history
Set RAILS_ENV to test when executing the default rake task
  • Loading branch information
Andrew Nordman committed Jul 11, 2020
2 parents 6649549 + c047f03 commit 08f2214
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/dotenv/rails.rb
@@ -1,6 +1,6 @@
require "dotenv"

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

Expand Down

0 comments on commit 08f2214

Please sign in to comment.