简体   繁体   English

`load_missing_constant':未初始化的常量AuthenticatedTestHelper(NameError)

[英]`load_missing_constant': uninitialized constant AuthenticatedTestHelper (NameError)

I have an old rails project I need to make changes to and perhaps even update. 我有一个旧的Rails项目,需要更改甚至更新。

My gem list looks like this: 我的宝石清单如下所示:

*** LOCAL GEMS ***

actionmailer (2.3.14, 2.3.11, 2.3.8, 2.3.5, 2.3.2)
actionpack (2.3.14, 2.3.11, 2.3.8, 2.3.5, 2.3.2)
activerecord (2.3.14, 2.3.11, 2.3.8, 2.3.5, 2.3.2)
activeresource (2.3.14, 2.3.11, 2.3.8, 2.3.5, 2.3.2)
activesupport (3.2.9, 2.3.14, 2.3.11, 2.3.8, 2.3.5, 2.3.2)
addressable (2.3.2)
BlueCloth (1.0.1)
bourne (1.1.2)
bundler (1.2.3)
childprocess (0.3.6)
ffi (1.2.0)
i18n (0.6.1)
json (1.7.5)
libwebsocket (0.1.7.1)
metaclass (0.0.1)
mocha (0.10.5)
multi_json (1.5.0)
mysql (2.8.1)
paperclip (2.3.1.1)
rack (1.1.3, 1.0.1)
rails (2.3.14, 2.3.2)
rake (0.8.7)
rdoc (3.12)
restful_authentication (1.1.6)
rspec (1.3.1)
ruby-net-ldap (0.0.4)
rubygems-bundler (1.1.0)
rubyzip (0.9.9)
rvm (1.11.3.5)
selenium-client (1.2.18)
selenium-webdriver (2.27.2)
shoulda (2.11.3)
shoulda-context (1.0.2)
shoulda-matchers (1.4.2)
thoughtbot-shoulda (2.11.1)
websocket (1.0.6)

When I run rake test I get: 运行rake test我得到:

/Users/noah/.rvm/gems/ruby-1.8.7-p371@website/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:469:in `load_missing_constant': uninitialized constant AuthenticatedTestHelper (NameError)
    from /Users/noah/.rvm/gems/ruby-1.8.7-p371@website/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:106:in `const_missing'
    from /Users/noah/.rvm/gems/ruby-1.8.7-p371@website/gems/activesupport-2.3.14/lib/active_support/dependencies.rb:118:in `const_missing'
    from ./test/test_helper.rb:4
    from ./test/functional/admin/articles_controller_test.rb:1:in `require'
    from ./test/functional/admin/articles_controller_test.rb:1
    from /Users/noah/.rvm/gems/ruby-1.8.7-p371@website/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `load'
    from /Users/noah/.rvm/gems/ruby-1.8.7-p371@website/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
    from /Users/noah/.rvm/gems/ruby-1.8.7-p371@website/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `each'
    from /Users/noah/.rvm/gems/ruby-1.8.7-p371@website/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
/Users/noah/.rvm/rubies/ruby-1.8.7-p371/bin/ruby -I"lib:test" "/Users/noah/.rvm/gems/ruby-1.8.7-p371@website/gems/rake-0.8.7/lib/rake/rake_test_loader.rb"  
Errors running test:units and test:functionals!

Here is the first part my test helper: 这是我的测试助手的第一部分:

ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
include AuthenticatedTestHelper

Anywhere where include AuthenticatedTestHelper is included it fails. include AuthenticatedTestHelper任何地方都会失败。 Any ideas on why this maybe? 关于为什么这样做的任何想法?

Updates: 更新:

I believe my problem is that restful_authentication is failing to generate the file that would provide AuthenticatedTestHelper. 我相信我的问题是restful_authentication无法生成将提供AuthenticatedTestHelper的文件。

Inside of dependencies, I have the following: 在依赖项内部,我具有以下内容:

qualified_name = qualified_name_for from_mod, const_name
      path_suffix = qualified_name.underscore
      name_error = NameError.new("uninitialized constant #{qualified_name}")

      file_path = search_for_file(path_suffix)
      if file_path && ! loaded.include?(File.expand_path(file_path)) # We found a matching file to load
        require_or_load file_path
        raise LoadError, "Expected #{file_path} to define #{qualified_name}" unless uninherited_const_defined?(from_mod, const_name)
        return from_mod.const_get(const_name)
      elsif mod = autoload_module!(from_mod, const_name, qualified_name, path_suffix)
        return mod
      elsif (parent = from_mod.parent) && parent != from_mod &&
            ! from_mod.parents.any? { |p| uninherited_const_defined?(p, const_name) }
        # If our parents do not have a constant named +const_name+ then we are free
        # to attempt to load upwards. If they do have such a constant, then this
        # const_missing must be due to from_mod::const_name, which should not
        # return constants from from_mod's parents.
        begin
          return parent.const_missing(const_name)
        rescue NameError => e
          raise unless e.missing_name? qualified_name_for(parent, const_name)
          raise name_error
        end
      else
        puts file_path #added this line
        raise name_error
      end
    end

and I've added the line puts file_path and this is nil, so again rails has no idea where this file is. 并且我添加了puts file_path这一行,它为nil,所以rails也不知道这个文件在哪里。 Any ideas? 有任何想法吗?

Normally this module shoud be in lib/authenticated_test_helper.rb 通常,此模块应位于lib/authenticated_test_helper.rb

If you can't find it or get it elsewhere you could simply create an empty module in that file and then gradually implement or stub it. 如果找不到或无法找到它,则可以在该文件中创建一个空模块,然后逐步实现或存根。

But if you are planning to upgrade to Rails 3 you have to choose another authentication framework anyway (Authlogic, Devise), since restful_authentication doesn't seem to work with Rails 3. 但是,如果您打算升级到Rails 3,则无论如何都必须选择另一个身份验证框架(Authlogic,Devise),因为restful_authentication似乎不适用于Rails 3。

PS: The code from dependencies.rb doesn't help you. PS:从代码dependencies.rb不帮你。 It just contains the code to derive the file name from the constant (= module in your case) It simply fails because you have no file named authenticated_test_helper in your load paths. 它仅包含从常量(在您的情况下为=)中导出文件名的代码。它只是失败,因为在加载路径中没有名为authenticated_test_helper文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 load_missing_constant' 中的块:未初始化的常量 API::V1::Users (NameError) - block in load_missing_constant': uninitialized constant API::V1::Users (NameError) `block in load_missing_constant':启动 Rails 服务器和控制台时未初始化的常量 Pry::Command::ExitAll (NameError) - `block in load_missing_constant': uninitialized constant Pry::Command::ExitAll (NameError) when launching rails server and console `load_missing_constant':未初始化的常量Rails :: Railtie - `load_missing_constant': uninitialized constant Rails::Railtie radrails开发服务器启动错误:load_missing_constant - radrails dev server startup error: load_missing_constant 尝试在Rails上创建观察者时出现“ load_missing_constant” - 'load_missing_constant' when trying to create an observer on Rails 安装Typus rails插件后的`load_missing_constant' - `load_missing_constant' after installing Typus rails plugin `const_missing': 未初始化的常量 (NameError) - 需要 - `const_missing': uninitialized constant (NameError) - Require `const_missing':未初始化的常量(NameError) - `const_missing': uninitialized constant (NameError) Puma:无法加载应用程序:NameError:未初始化的常量 - Puma: Unable to load application: NameError: uninitialized constant Rails NameError:初始加载时未初始化的常量 - Rails NameError: uninitialized constant on initial load
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM