RuntimeError:自动加载常量时检测到循环依赖性

时间:2023-01-19 20:49:36


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/

我的目录结构如下: - 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.

注意:我已经看到了与此问题相关的问题,但是,他们的问题与我的问题似乎不相似。在我的情况下,它是随机发生的,只有在运行测试(RAILS TEST ENV)时,应用程序才能完美运行。

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.

FolderContent响应类继承自ContentResponse,后者具有FolderContent其他内容响应使用的更通用的方法。

1 个解决方案

#1


13  

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)

这听起来很像是Xavier Noria最近发现的问题。简而言之,即使未预先加载所有应用程序代码的设置(因为需要和朋友不是线程安全),capybara会以多线程模式启动您的应用程序进行测试

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

在早期版本中,已针对rails 4.2进行了修复

config.allow_concurrency = false

in test.rb should do the trick

在test.rb应该做的伎俩

#1


13  

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)

这听起来很像是Xavier Noria最近发现的问题。简而言之,即使未预先加载所有应用程序代码的设置(因为需要和朋友不是线程安全),capybara会以多线程模式启动您的应用程序进行测试

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

在早期版本中,已针对rails 4.2进行了修复

config.allow_concurrency = false

in test.rb should do the trick

在test.rb应该做的伎俩