我通过引入请求和响应模型来重构我的 Controller ,以执行此 presentation 之后 Controller 周围的一些逻辑。 .我分别用模块 Responses 和 Requests 包装了所有的响应和请求模型。应用程序运行完美,但当我运行测试时,出现以下错误。
Failure/Error: Unable to find matching line from backtrace
RuntimeError:
Circular dependency detected while autoloading constant Responses::FolderContentResponse
我的目录结构如下:
- 应用/
- 模型/
- 回应/
注意:我看过与此问题相关的问题,但他们的问题似乎与我的不相似。在我的例子中,它是随机发生的,并且只有在运行测试 (RAILS TEST ENV) 时,应用程序才能完美运行。
module Responses
class ContentResponse
include ActiveAttr::Model
#some attributes
#some methods
end
end
module Responses
class FolderContentResponse < ContentResponse
end
end
FolderContent 响应类继承自 ContentResponse,它具有 FolderContent 其他内容响应使用的更通用的方法。
最佳答案
这听起来很像 issue最近由 Xavier Noria 发现。简而言之,即使未激活预先加载所有应用程序代码的设置, capybara 也会以多线程模式启动您的应用程序以进行测试(需要,因为 require
并且 friends 不是线程安全的)
在早期版本的 rails 4.2 中已经修复
config.allow_concurrency = false
在 test.rb 中应该可以做到这一点
关于ruby - 运行时错误 : Circular dependency detected while autoloading constant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24673301/