'Upgrading to Rails 6.1.4 - Module in lib directory no longer found by Test class
I have an application that I am upgrading from Rails 5.2.6, Ruby 2.6 to Rails 6.1.4, Ruby 3.0 and am running into a problem with a class in the test directory no longer finding a module in the lib directory. The configuration works fine in Rails 5.2.6 and I am not seeing anything in the 6.0.0 or 6.1.4 upgrade notes which clue me in on what has changed.
The configuration is as follows:
config/application.rb
config.autoload_paths += %W(
#{config.root}/lib
#{config.root}/app/models/concerns
)
lib/api.rb
module Api
URL_ID_REGEX = /(\/:([a-z_]+_id)\/)/
end
test/webmock/mock.rb
class Mock
def init
@resource_url.scan(Api::URL_ID_REGEX).each do |k, v|
....
....
....
end
end
end
I am getting the error message "uninitialized constant Mock::Api", which tells me that it in Rails 6.1.4 it is trying to find the module Api under its own hierarchy.
When I change the call to:
@resource_url.scan(::Api::URL_ID_REGEX).each do |k, v|
it simply changes the error message to "uninitialized constant Api".
I have tried including the Api module in the Mock class, but the module is never found and it always complains about the uninitialized constant.
I am aware that I can simply copy the constant definition from the module to the class and be done with it, but I would prefer to understand and resolve the problem.
I would appreciate any suggestions on how to overcome this issue.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
