Skip to content

Commit 14940de

Browse files
committed
Suggest eager load in CI in the C2Z HOWTO guide
1 parent 099289b commit 14940de

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

guides/source/classic_to_zeitwerk_howto.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,26 @@ Please make sure to depend on at least Bootsnap 1.4.4.
306306
Check Zeitwerk Compliance in the Test Suite
307307
-------------------------------------------
308308

309-
The Rake task `zeitwerk:check` just eager loads, because doing so triggers built-in validations in Zeitwerk.
309+
The task `zeitwerk:check` is handy while migrating. Once the project is compliant, it is recommended to automate this check. In order to do so, it is enough to eager load the application, which is all the task does, indeed.
310310

311-
You can add the equivalent of this to your test suite to make sure the application always loads correctly regardless of test coverage:
311+
### Continuous Integration
312312

313-
### minitest
313+
If your project has continuous integration in place, it is a good idea to eager load the application when the suite runs there. If the application cannot be eager loaded for whatever reason, you want to know in CI, better than in production, right?
314+
315+
CIs typically set some environment variable to indicate the test suite is running there. For example, it could be `CI`:
316+
317+
```ruby
318+
# config/environments/test.rb
319+
config.eager_load = ENV["CI"].present?
320+
```
321+
322+
Starting with Rails 7, newly generated applications are configured that way by default.
323+
324+
### Bare Test Suites
325+
326+
If your project does not have continuous integration, you can still eager load in the test suite by calling `Rails.application.eager_load!`:
327+
328+
#### minitest
314329

315330
```ruby
316331
require "test_helper"
@@ -322,7 +337,7 @@ class ZeitwerkComplianceTest < ActiveSupport::TestCase
322337
end
323338
```
324339

325-
### RSpec
340+
#### RSpec
326341

327342
```ruby
328343
require "rails_helper"

0 commit comments

Comments
 (0)