Rspec,Capybara,Guard - 未初始化的常量ActiveRecord :: Base(NameError)

时间:2014-01-28 13:35:34

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

当我开始守护并保存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测试。这是我第一次。我当然知道我错过了一些配置。请帮忙。

1 个答案:

答案 0 :(得分:1)

这太棒了,我在lib目录中有一个名为“active_record.rb”的空文件,这是加载而不是rails ActiveRecord。因此,未初始化的名称错误。伙计们,要小心你要将你的课程命名为lib。它会覆盖。

天哪,有一天吃了这个想法。