-
Notifications
You must be signed in to change notification settings - Fork 510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ActiveSupport::TestCase teardown error: undefined method `keys' for nil #500
Comments
Ah, I think I figured out how to repro: this happens when the test raises (in my case, I had a typo in a model, so loading the environment in the test_helper raised). That error gets swallowed, though, (for the sake of minitest's reporter, I imagine) and dotenv ends up at the top of the backtrace. Dropping a random raise in any autoloaded class will do the trick:
|
This was happening because of hotwired/turbo-rails#587 in my case. |
@searls I'm still having issue reproducing. Where are you referencing the # app/models/failwhale.rb
class Failwhale
raise
end
# test/test_helper.rb
ENV["RAILS_ENV"] ||= "test"
require_relative "../config/environment"
require "rails/test_help"
# I tried HERE first
# Failwhale
module ActiveSupport
class TestCase
# Run tests in parallel with specified workers
parallelize(workers: :number_of_processors)
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
# and HERE
# Failwhale
end
end
class MyTest < ActiveSupport::TestCase
setup do
# and HERE
# Failwhale
end
# And HERE
test "a test case" do
Failwhale
end
end In all cases, the error got was:
|
Getting the following error. I've seen it four or five times but every time I've cleared it I haven't been able to create a minimal reproduction:
The issue appears to be with the ActiveSupport::TestCase support, in the teardown:
Which calls:
But at this point
env
is nil. I can see that@diff
is set by:But the above
instrument(:save) block is never called, so
@diffis never set. When
any?is then called on the
Dotenv::Diffobject that has a nil
b` value:All three of those
added
,removed
, andchanged
methods will raise, becauseb
is nil and they all call eitherb.slice
orb.keys
.I'm not familiar with how dotenv works, so I don't know if the issue is that
save
isn't getting called, or if there's a missing guard clause to make this all nil-safeSystem configuration
dotenv version: 3.1.0
Rails version:
I'm on the current tip of rails/rails#main: rails/rails@68b20b6
Just verified it also occurs on
7.1.3.2
Ruby version:
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
The text was updated successfully, but these errors were encountered: