File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -1972,6 +1972,54 @@ class ChatRelayJobTest < ActiveJob::TestCase
1972
1972
end
1973
1973
```
1974
1974
1975
+ Testing Eager Loading
1976
+ ---------------------
1977
+
1978
+ Normally, applications do not eager load in the ` development ` or ` test ` environments to speed things up. But they do in the ` production ` environment.
1979
+
1980
+ If some file in the project cannot be loaded for whatever reason, you better detect it before deploying to production, right?
1981
+
1982
+ ### Continuous Integration
1983
+
1984
+ If your project has CI in place, eager loading in CI is an easy way to ensure the application eager loads.
1985
+
1986
+ CIs typically set some environment variable to indicate the test suite is running there. For example, it could be ` CI ` :
1987
+
1988
+ ``` ruby
1989
+ # config/environments/test.rb
1990
+ config.eager_load = ENV [" CI" ].present?
1991
+ ```
1992
+
1993
+ Starting with Rails 7, newly generated applications are configured that way by default.
1994
+
1995
+ ### Bare Test Suites
1996
+
1997
+ If your project does not have continuous integration, you can still eager load in the test suite by calling ` Rails.application.eager_load! ` :
1998
+
1999
+ #### minitest
2000
+
2001
+ ``` ruby
2002
+ require " test_helper"
2003
+
2004
+ class ZeitwerkComplianceTest < ActiveSupport ::TestCase
2005
+ test " eager loads all files without errors" do
2006
+ assert_nothing_raised { Rails .application.eager_load! }
2007
+ end
2008
+ end
2009
+ ```
2010
+
2011
+ #### RSpec
2012
+
2013
+ ``` ruby
2014
+ require " rails_helper"
2015
+
2016
+ RSpec .describe " Zeitwerk compliance" do
2017
+ it " eager loads all files without errors" do
2018
+ expect { Rails .application.eager_load! }.not_to raise_error
2019
+ end
2020
+ end
2021
+ ```
2022
+
1975
2023
Additional Testing Resources
1976
2024
----------------------------
1977
2025
You can’t perform that action at this time.
0 commit comments