I’m trying to load a module (defined in lib/) in one of my test cases.
The error:
Error:
VendorApis::FooVendorTest#test_fetching_data_works_properly:
Zeitwerk::NameError: expected file /home/blaine/project/lib/vendor_apis/foo_vendor.rb to define constant VendorApis::FooVendor, but didn't
app/models/inv_procure/vendor_api.rb:6:in `get_api_class_const'
app/models/inv_procure/vendor_api_mapping.rb:42:in `api_instance'
test/lib/vendor_apis/foo_vendor_test.rb:6:in `block in <class:FooVendorTest>'
This is how it’s being loaded:
def get_api_class_const
require "./lib/" + self.lib_path
return Object.const_get(self.class_path)
end
I think Zeitwerk (I don’t know much about this) is expecting a constant to be in the file, based on the file name, i.e. VendorApis::FooVendor. However, that is not the case. The file defines a class constant FooVendor::ApiConsumer
. Is there a way around this?