【问题标题】:Rspec, Capybara, Guard - uninitialized constant ActiveRecord::Base (NameError)Rspec,Capybara,Guard - 未初始化的常量 ActiveRecord::Base (NameError)
【发布时间】:2014-01-28 13:35:34
【问题描述】:

当我开始保护并保存一个 rspec 请求时,我总是得到这个错误,

我参考了这个教程,http://railscasts.com/episodes/275-how-i-test

未初始化的常量 ActiveRecord::Base (NameError)

见下文,

/home/think/.rvm/gems/ruby-1.9.3-p385/gems/audited-activerecord-3.0.0/lib/audited/adapters/active_record/audit.rb:16:in `<module:ActiveRecord>': uninitialized constant ActiveRecord::Base (NameError)
    from /home/think/.rvm/gems/ruby-1.9.3-p385/gems/audited-activerecord-3.0.0/lib/audited/adapters/active_record/audit.rb:6:in `<module:Adapters>'
    from /home/think/.rvm/gems/ruby-1.9.3-p385/gems/audited-activerecord-3.0.0/lib/audited/adapters/active_record/audit.rb:5:in `<module:Audited>'
    from /home/think/.rvm/gems/ruby-1.9.3-p385/gems/audited-activerecord-3.0.0/lib/audited/adapters/active_record/audit.rb:4:in `<top (required)>'
    from /home/think/.rvm/gems/ruby-1.9.3-p385/gems/audited-activerecord-3.0.0/lib/audited/adapters/active_record.rb:3:in `<top (required)>'
    from /home/think/.rvm/gems/ruby-1.9.3-p385/gems/audited-activerecord-3.0.0/lib/audited-activerecord.rb:2:in `<top (required)>'
    from /home/think/.rvm/gems/ruby-1.9.3-p385@global/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `require'
    from /home/think/.rvm/gems/ruby-1.9.3-p385@global/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
    from /home/think/.rvm/gems/ruby-1.9.3-p385@global/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `each'
    from /home/think/.rvm/gems/ruby-1.9.3-p385@global/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `block in require'
    from /home/think/.rvm/gems/ruby-1.9.3-p385@global/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `each'
    from /home/think/.rvm/gems/ruby-1.9.3-p385@global/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `require'
    from /home/think/.rvm/gems/ruby-1.9.3-p385@global/gems/bundler-1.2.3/lib/bundler.rb:128:in `require'
    from /home/think/jonathan/organizor/config/application.rb:7:in `<top (required)>'
    from /home/think/jonathan/organizor/config/environment.rb:2:in `require'
    from /home/think/jonathan/organizor/config/environment.rb:2:in `<top (required)>'
    from /home/think/jonathan/organizor/spec/spec_helper.rb:3:in `require'
    from /home/think/jonathan/organizor/spec/spec_helper.rb:3:in `<top (required)>'
    from /home/think/jonathan/organizor/spec/requests/password_resets_spec.rb:1:in `require'
    from /home/think/jonathan/organizor/spec/requests/password_resets_spec.rb:1:in `<top (required)>'
    from /home/think/.rvm/gems/ruby-1.9.3-p385/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `load'
    from /home/think/.rvm/gems/ruby-1.9.3-p385/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
    from /home/think/.rvm/gems/ruby-1.9.3-p385/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `each'
    from /home/think/.rvm/gems/ruby-1.9.3-p385/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `load_spec_files'
    from /home/think/.rvm/gems/ruby-1.9.3-p385/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:22:in `run'
    from /home/think/.rvm/gems/ruby-1.9.3-p385/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:80:in `run'
    from /home/think/.rvm/gems/ruby-1.9.3-p385/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:17:in `block in autorun'

我还没有做过 Rails 测试。这是我第一次。我当然知道我错过了一些配置。请帮忙。

【问题讨论】:

    标签: activerecord rspec ruby-on-rails-3.2 capybara


    【解决方案1】:

    这太棒了,我在 lib 目录中有一个名为“active_record.rb”的空文件,它被加载而不是 rails ActiveRecord。因此,未初始化的名称错误。伙计们,请注意将要保留在 lib 下的类的名称。它会覆盖。

    天哪,吃了一天就知道了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-10
      • 1970-01-01
      • 1970-01-01
      • 2013-03-21
      • 1970-01-01
      • 2015-06-14
      • 1970-01-01
      相关资源
      最近更新 更多