简体   繁体   English

运行Rails控制台时未初始化的常量测试

[英]uninitialized constant Test when running Rails console

I'm getting uninitialized constant Test when running rails console in terminal. 在终端中运行rails console时,我得到了uninitialized constant Test I'm not sure why I just set it up and using the command rails server works. 我不确定为什么要设置它并使用命令rails server起作用。

This is the error I get: 这是我得到的错误:

/usr/lib/ruby/vendor_ruby/active_support/test_case.rb:12:in `<module:ActiveSupport>': uninitialized constant Test (NameError)

I ran into this same problem on my Ubuntu 14.04 desktop. 我在Ubuntu 14.04桌面上遇到了同样的问题。 Solved in the following way: 解决方法如下:

sudo apt-get install ruby-test-unit echo require 'test/unit' >> /usr/lib/ruby/vendor_ruby/active_support/test_case.rb

see this link: https://bugs.launchpad.net/ubuntu/+source/ruby-activesupport-3.2/+bug/1319101 看到这个链接: https : //bugs.launchpad.net/ubuntu/+source/ruby-activesupport-3.2/+bug/1319101

I had this issue when copied and pasted the config from shoulda-matchers getting started guide . 复制并粘贴来自Shoulda-matchers入门指南的配置时,我遇到了这个问题。 But I wasn't removing the unused tests frameworks. 但是我没有删除未使用的测试框架。

To use with RSpec it will be as: 要与RSpec一起使用,它将是:

Shoulda::Matchers.configure do |config|
  config.integrate do |with|
    # Choose a test framework:
    with.test_framework :rspec
    # with.test_framework :minitest
    # with.test_framework :minitest_4
    # with.test_framework :test_unit

    # Choose one or more libraries:
    with.library :active_record
    with.library :active_model
    with.library :action_controller
    # Or, choose the following (which implies all of the above):
    with.library :rails
  end
end

the echo command above may not work on all installs of Ubuntu 14.04. 上面的echo命令可能不适用于所有安装的Ubuntu 14.04。 You can do a sudo vi and physically edit the test_case.rb file and put the require 'test/unit' after the existing require(s). 您可以执行sudo vi并实际编辑test_case.rb文件,并将require'test / unit'放在现有的require之后。

First: Why are you not using rvm or rbenv ? 第一:为什么不使用rvmrbenv You can mess your operational system! 您可能会弄乱您的操作系统!

Second: It is not finding any reference to a class named Test. 第二:找不到对名为Test的类的任何引用。 Are you sure is this the name? 您确定是这个名字吗? Have you properly required it? 您有适当的要求吗? Which Test Framework are you using? 您正在使用哪个测试框架?

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM