bkeepers / dotenv

A Ruby gem to load environment variables from `.env`.
MIT License
6.61k stars 505 forks source link

Don't load Spring, just check if it is already loaded #510

Closed runephilosof-abtion closed 2 months ago

runephilosof-abtion commented 2 months ago

Steps to reproduce

dotenv-rails loads Spring. https://github.com/bkeepers/dotenv/blob/b86d9e4c23a9f1bc83f8853f6a1b244449c65cd0/lib/dotenv/rails.rb#L14

I like to have spring in my projects' Gemfiles with require: false and only have Spring loaded when I manually choose to use it, by running something like bin/spring rspec spec/models

It would be nice if dotenv-rails instead checks defined?(Spring).

# Gemfile
gem 'rails'
gem 'dotenv-rails'
gem 'spring', require: false

Expected behavior

bundle exec rails runner 'puts defined?(Spring)' should output nothing

Actual behavior

bundle exec rails runner 'puts defined?(Spring)' outputs constant

System configuration

dotenv version: 3.1.2 Rails version: 7.1.4 Ruby version: 3.3.3