rails + rspec + spring + eager_load = uninitialized constant #519
Comments
I have almost same problem, but rspec throws error even on second run without modifying any files. I faced with this problem after enabling eager_loading for test environment |
Apparently this is due to Rails 5 disabling autoloading (and thus auto-reloading) of constants when However, thanks to this article I learned that it's possible to re-enable that behaviour using
With that line added to |
@radarek @lime An alternative to It doesn't AFAICT gain anything to turn However I'm still working through this approach in practice. It may mean you need to explicitly |
I find that |
load_disparities = (ActiveSupport::Dependencies.autoload_paths - config.eager_load_paths).uniq
config.eager_load_paths += load_disparities unless Rails.env.development? I prefer to keep autoload in test to true, to keep cfg between test and prod the same |
I'm using minitest in a Rails engine and encountered a similar issue. None of the proposed solutions worked for me. I found that adding my autoload paths to
|
When I set eager_load = true in
config/environments/test.rb
then after spring is loaded and any file is changed then running specs again will fail with a message like "uninitialized constant User (NameError)".I created simple rails project repository to reproduce it: https://github.com/radarek/rails_rspec_spring_eager_load_bug. It's pure rails project. I added only gems rspec-rails and spring-commands-rspec and generated
User
model. When I runbin/rspec
specs pass, running it again still gives success. But after modifyingapp/models/user.rb
file and running it again it will fail with a messageuser_spec.rb:3:in
<top (required)>': uninitialized constant User (NameError)`.I know that doesn't have to be a problem with spring itself but it's hard to guess what it causes.
Steps to reproduce:
The text was updated successfully, but these errors were encountered: