Skip to content

Commit e74012c

Browse files
committed
Suggest eager load in CI in the testing guide
1 parent 14940de commit e74012c

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

guides/source/testing.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,6 +1972,54 @@ class ChatRelayJobTest < ActiveJob::TestCase
19721972
end
19731973
```
19741974

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+
19752023
Additional Testing Resources
19762024
----------------------------
19772025

0 commit comments

Comments
 (0)