Mukiza Andrew Mukiza Andrew - 5 months ago 110
Ruby Question

RuntimeError: Circular dependency detected while autoloading constant

I refactored my controllers by introducing request and response models to do some of the logic that was hanging around the controllers following this presentation. I wrapped all the response and request models with a module Responses and Requests respectively. The applications runs perfectly but when I run tests, I get the error below.

Failure/Error: Unable to find matching line from backtrace
Circular dependency detected while autoloading constant Responses::FolderContentResponse

My directory structure is as follows:

  - app/

   - models/

     - responses/

Note: I have seen the questions related to this issue but, their issues didn't seem similar to mine. In my case it happens randomly, and only when running tests (RAILS TEST ENV), the application is working perfectly.

module Responses
class ContentResponse
include ActiveAttr::Model
#some attributes
#some methods

module Responses
class FolderContentResponse < ContentResponse

The FolderContent response class inherits from ContentResponse which has more generic methods that FolderContent other content responses use.


This sounds a lot like an issue found recently by Xavier Noria. In a nutshell, capybara boots your application in multithreaded mode for the test even though the setting to load all app code upfront is not activated (needed because require and friends are not threadsafe)

It's been fixed for rails 4.2, on earlier versions

config.allow_concurrency = false

in test.rb should do the trick