Rspec'无法加载此类文件 - 日期(加载错误)

时间:2014-08-04 17:12:30

标签: ruby-on-rails rspec

首先在这里提出问题,请随时纠正我的任何失礼。

我在Rails 4.1.0应用的app目录中运行rspec spec/models,我收到以下错误:

/home/david/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `require': cannot load such file -- Date (LoadError)
from /home/david/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `block in require'
from /home/david/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
from /home/david/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:247:in `require'
from /home/david/Projectsam/spec/models/batch_spec.rb:2:in `<top (required)>'
from /home/david/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load'
from /home/david/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `block in load'
from /home/david/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
from /home/david/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load'
from /home/david/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.3/lib/rspec/core/configuration.rb:1057:in `block in load_spec_files'
from /home/david/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.3/lib/rspec/core/configuration.rb:1057:in `each'
from /home/david/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.3/lib/rspec/core/configuration.rb:1057:in `load_spec_files'
from /home/david/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.3/lib/rspec/core/runner.rb:97:in `setup'
from /home/david/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.3/lib/rspec/core/runner.rb:85:in `run'
from /home/david/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.3/lib/rspec/core/runner.rb:70:in `run'
from /home/david/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.3/lib/rspec/core/runner.rb:38:in `invoke'
from /home/david/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.3/exe/rspec:4:in `<top (required)>'
from /home/david/.rvm/gems/ruby-2.1.1/bin/rspec:23:in `load'
from /home/david/.rvm/gems/ruby-2.1.1/bin/rspec:23:in `<main>'
from /home/david/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
from /home/david/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `<main>'

我检查了一些其他类似的问题,但它们似乎都与Gems有关或确保从项目目录运行rspec命令。我有点迷失,因为我认为&#39; Date&#39;是核心模块,而不是宝石。运行bundle exec rspec spec/models

时出现类似错误

我很有可能错过了一些愚蠢的事情,但对于我的生活,我无法弄清楚是什么。提前谢谢!

更新:为了更多地澄清这个问题,我在运行rspec spec时遇到了这个更普遍的错误:

~/myapp/spec/controllers/dashboard_controller_spec.rb:3:in `<top (required)>': uninitialized constant DashboardController (NameError)
    from /home/david/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.3/lib/rspec/core/configuration.rb:1057:in `block in load_spec_files'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.3/lib/rspec/core/configuration.rb:1057:in `each'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.3/lib/rspec/core/configuration.rb:1057:in `load_spec_files'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.3/lib/rspec/core/runner.rb:97:in `setup'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.3/lib/rspec/core/runner.rb:85:in `run'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.3/lib/rspec/core/runner.rb:70:in `run'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.3/lib/rspec/core/runner.rb:38:in `invoke'
    from /home/david/.rvm/gems/ruby-2.1.1/gems/rspec-core-3.0.3/exe/rspec:4:in `<top (required)>'
    from /home/david/.rvm/gems/ruby-2.1.1/bin/rspec:23:in `load'
    from /home/david/.rvm/gems/ruby-2.1.1/bin/rspec:23:in `<main>'
    from /home/david/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
    from /home/david/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `<main>'

更新2:

因此,其中一个规范文件中的require Date似乎导致了这一点 - 对此进行评论让rspec运行没有任何问题。奇怪的是,rspec在MacOS上工作正常而没有注释掉require语句。

1 个答案:

答案 0 :(得分:0)

结果使用rails generate命令创建了一些需要'spec helper'而不是'rspec'的错误,导致依赖问题。愚蠢的错误,我会关闭它。