LoadError:无法加载此类文件 – rspec / core / rake_task

更新:这个问题仍未解决! 任何帮助表示赞赏! 05/07/2015 更新:找到了解决方法。 请看我自己的答案05/09/2015

当我耙,我得到了这个错误。

AllenLins-MacBook-Pro:geoblacklight allenlin$ rake -t Resolving dependencies... You must `gem install bundler` and `bundle install` to run rake tasks rake aborted! LoadError: cannot load such file -- rspec/core/rake_task /Users/allenlin/Documents/USpatial/geoblacklight/Rakefile:12:in `require' /Users/allenlin/Documents/USpatial/geoblacklight/Rakefile:12:in `' /Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/rake_module.rb:28:in `load' /Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/rake_module.rb:28:in `load_rakefile' /Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:689:in `raw_load_rakefile' /Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:94:in `block in load_rakefile' /Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling' /Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:93:in `load_rakefile' /Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:77:in `block in run' /Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling' /Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:75:in `run' /Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-10.4.2/bin/rake:33:in `' /Users/allenlin/.rbenv/versions/2.2.2/bin/rake:23:in `load' /Users/allenlin/.rbenv/versions/2.2.2/bin/rake:23:in `' 

但是,我运行’gem install bundler’和’bundle install’rspec / core / rake_task实际上存在,显示为

 AllenLins-MacBook-Pro:geoblacklight allenlin$ gem which rspec/core/rake_task /Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rspec-core-3.0.4/lib/rspec/core/rake_task.rb 

我迷失在这里。 非常感谢您对此的任何帮助! 我附上了Gemfile:

 source 'https://rubygems.org' # Specify your gem's dependencies in geoblacklight.gemspec gemspec # If we don't specify 2.11.0 we'll end up with sprockets 2.12.0 in the main # Gemfile.lock but since sass-rails gets generated (rails new) into the test app # it'll want sprockets 2.11.0 and we'll have a conflict gem 'sprockets', '2.11.0' # If we don't specify 3.2.15 we'll end up with sass 3.3.2 in the main # Gemfile.lock but since sass-rails gets generated (rails new) into the test app # it'll want sass 3.2.0 and we'll have a conflict gem 'sass', '~> 3.2.0' gem 'bootstrap-sass', ">= 3.2" group :test do # Peg simplecov to  0.7.1', require: false gem 'coveralls', require: false end 

更新

添加我的gemenv,如果这是有帮助的

 RubyGems Environment: - RUBYGEMS VERSION: 2.4.5 - RUBY VERSION: 2.2.2 (2015-04-13 patchlevel 95) [x86_64-darwin14] - INSTALLATION DIRECTORY: /Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0 - RUBY EXECUTABLE: /Users/allenlin/.rbenv/versions/2.2.2/bin/ruby - EXECUTABLE DIRECTORY: /Users/allenlin/.rbenv/versions/2.2.2/bin - SPEC CACHE DIRECTORY: /Users/allenlin/.gem/specs - SYSTEM CONFIGURATION DIRECTORY: /Users/allenlin/.rbenv/versions/2.2.2/etc - RUBYGEMS PLATFORMS: - ruby - x86_64-darwin-14 - GEM PATHS: - /Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0 - /Users/allenlin/.gem/ruby/2.2.0 - GEM CONFIGURATION: - :update_sources => true - :verbose => true - :backtrace => false - :bulk_threshold => 1000 - REMOTE SOURCES: - https://rubygems.org/ - SHELL PATH: - /Users/allenlin/.rbenv/versions/2.2.2/bin - /usr/local/Cellar/rbenv/0.4.0/libexec - /Users/allenlin/.rbenv/shims - /Applications/Postgres.app/Contents/Versions/9.3/bin - /Library/Frameworks/Python.framework/Versions/2.7/bin - /Users/allenlin/Library/Enthought/Canopy_64bit/User/bin - /Users/allenlin/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bundler-1.9.6/bin - /Users/allenlin/gradle-1.12/bin - /usr/local/bin - /Users/allenlin/apache-maven/apache-maven-3.1.1/bin - /usr/local/bin - /usr/bin - /bin - /usr/sbin - /sbin - /opt/X11/bin - /usr/local/git/bin - /usr/texbin 

似乎运行bundle exec rake -t会起作用。 Per bundler.io http://bundler.io/man/bundle-exec.1.html我建议添加bundle exec以确保我们使用当前上下文中指定的Gem。 另见这篇SOpost。 bundle exec rake是什么意思?

之后:sudo gem install bundler

我创建了一个Gemfile:

 gem 'rake' gem 'rspec' gem 'kramdown' 

并做了捆绑安装。 现在我没有得到错误。

假设你的Gemfile中确实有rspec,如果你收到这个错误,或者意味着你没有使用应用程序需要的正确gems运行rake(使用应用程序根目录中的bundle exec rake来解决),或者你的尚未安装rspec核心gem。

如果在运行bundle install ,在运行bundle exec rake时仍然会遇到相同的错误,请检查您是否确实安装了“测试模式”gems。 这发生在我身上。

在我的情况下,我没有安装我的测试gem,因为Bundler通过记住传递给--without选项的先前参数表现出非常规行为,如此处所述 ,因此您可能认为在运行bundle install时安装了所有gembundle install但你可能实际上正在运行(例如…) – 没有--without development test ,也不知道它。

检查“未安装组开发和测试中的gem”之类的内容。 在bundle install输出结束时。

要重置捆绑选项,只需删除./.bundle目录(so … rm -r ./.bundle )。 现在bundle install将恢复正常,rake应该可以工作。

在生产环境中

会发生什么, capistrano配置为仅在production组中安装gem bundle(如在Gemfile中)。 因此它运行bundle命令,如bundle install --without development test

想validation?

在生产环境中的项目目录中运行bundle install命令,您将看到以下内容

 Using devise 4.2.0 Using activeadmin 1.0.0.pre4 Using responsive_active_admin 0.0.5 Bundle complete! 60 Gemfile dependencies, 133 gems now installed. Gems in the groups development and test were not installed. Bundled gems are installed into /path/to/your/app/production/shared/bundle. 

请注意( 未安装组开发和测试中的Gems。 )。

您可能还记得,您已指定仅在development模式下安装rspec-rails gem。


尝试指定RAILS_ENV类的

 # For Rails 5.0 + RAILS_ENV=production bundle exec rails -T # or RAILS_ENV=production bundle exec rake -T # but this may not work bundle exec rake -T RAILS_ENV=production