RuntimeError: Circular dependency detected while autoloading constant
rspec-rails, ruby, ruby-on-rails-4, web
Solution
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
Problem
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 RuntimeError: 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 end end module Responses class FolderContentResponse < ContentResponse end end ``` The FolderContent response class inherits from ContentResponse which has more generic methods that FolderContent other content responses use.