Configure Zeitwerk for test-only classes inside spec/ directory

I’m working on a Hanami 2 app where I want to configure Zeitwerk to namespace the files under spec into the namespace Test. I saw that Tim Riley is namespacing all helpers/factories and stuff in the spec directory into the Test namespace in his decaf app, and I think this is quite elegant. How can I do this as well?

Hey @choallin! I’m not actually autoloading anything inside my spec/ directory; everything is brought in by requires, so Zeitwerk configuration is not involved there. (For reference, the original post refers to decafsucks/spec at main · decafsucks/decafsucks · GitHub)

If you wanted to autoload files inside your spec/ directory using Zeitwerk, I would recommend you create a totally separate Zeitwerk loader to do this, not reuse any that are set up for the Hanami app. So this would mean creating a Zeitwerk::Loader inside your spec_helper.rb and then just following Zeitwerk’s own (excellent) README to set it up.