gpt4 book ai didi

ruby-on-rails - 当类位于子目录中并被子类化时,Rspec 因 load_missing_constant 而失败

转载 作者:行者123 更新时间:2023-12-04 02:26:39 24 4
gpt4 key购买 nike

由于我怀疑与自动加载有关,我在运行一堆 RSpec 测试时遇到了一些麻烦。这是错误:

/usr/share/ruby-rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.1.4/lib/active_support/dependencies.rb:490:in `load_missing_constant': Expected /var/lib/jenkins/.../portfolios/base_manage_controller.rb to define Portfolios::BaseManageController (LoadError)
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.1.4/lib/active_support/dependencies.rb:181:in `block in const_missing'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.1.4/lib/active_support/dependencies.rb:179:in `each'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.1.4/lib/active_support/dependencies.rb:179:in `const_missing'
from /usr/share/ruby-rvm/gems/ruby-1.9.2-p320@global/gems/rake-0.9.2.2/lib/rake/ext/module.rb:36:in `const_missing'
from /var/lib/jenkins/jobs/.../app/controllers/portfolios/customize_controller.rb:1:in `<top (required)>'

这是文件的标题:
class Portfolios::BaseManageController < ApplicationController

它住在 app/controllers/portfolios/base_manage_controller.rb
及其子类:
class Portfolios::CustomizeController < Portfolios::BaseManageController

它住在 app/controllers/portfolios/customize_controller.rb
最后是一堆自动加载:
config.autoload_paths += Dir["#{config.root}/lib",  "#{config.root}/lib/**/"]
config.autoload_paths += %W(#{config.root}/app/models/statistics)

#Any test/dev specific load paths
if not Rails.env.production?
config.autoload_paths += %W(#{config.root}/spec/support)
config.autoload_paths += %W(#{config.root}/spec/support/builders)
config.autoload_paths += %W(#{config.root}/spec/support/modules)
config.autoload_paths += %W(#{config.root}/spec/support/utils)
end

任何帮助将非常感激!

最佳答案

当定义类时引发异常时,有时会发生此错误。在这种情况下,尝试定义在 base_manage_controller.rb 中找到的类时可能会发生运行时错误。

要验证是否是这种情况,请尝试从 base_manage_controller.rb 中删除所有内容。 ,除了类声明:

class Portfolios::BaseManageController < ApplicationController
end

它应该导致规范运行,但失败。

要查找运行时错误,请将所有内容放回类中,然后从 script/console 加载它。 , 调用 Portfolios::BaseManageController .这将尝试动态加载类,并引发阻止定义类的异常。

关于ruby-on-rails - 当类位于子目录中并被子类化时,Rspec 因 load_missing_constant 而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11958201/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com