简体   繁体   English

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

[英]LoadError: cannot load such file — rspec/core/rake_task

When I rake, I got this error.当我耙时,我收到了这个错误。

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 `<top (required)>'
/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 `<top (required)>'
/Users/allenlin/.rbenv/versions/2.2.2/bin/rake:23:in `load'
/Users/allenlin/.rbenv/versions/2.2.2/bin/rake:23:in `<main>'

However, I've run the 'gem install bundler' and 'bundle install' the rspec/core/rake_task actually exists, shown by但是,我已经运行了 '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

I am lost here.我在这里迷路了。 Thanks so much for any help on this!非常感谢您对此的任何帮助! I attached the Gemfile:我附上了 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.8 until this is resolved:
  # https://github.com/colszowka/simplecov/issues/281
  gem 'simplecov', '~> 0.7.1', require: false
  gem 'coveralls', require: false
end

Update更新

Add my gem env if that's helpful如果有帮助,请添加我的 gem env

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

It seems that running bundle exec rake -t will work.似乎运行bundle exec rake -t会起作用。 Per bundler.io http://bundler.io/man/bundle-exec.1.html I suggest adding bundle exec to ensure that we are using the Gem specified in the current context.根据 bundler.io http://bundler.io/man/bundle-exec.1.html我建议添加 bundle exec 以确保我们使用当前上下文中指定的 Gem。 Also see this SO post.另请参阅此 SO 帖子。 What does bundle exec rake mean? bundle exec rake 是什么意思?

After having earlier run : sudo gem install bundler较早运行后: sudo gem install bundler

I created a Gemfile with:我创建了一个 Gemfile:

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

and did bundle install .并做了bundle install Now I dont get the error.现在我没有得到错误。

In Production Environment在生产环境中

What happens is, capistrano is configured to only install gem bundle in production group(as in Gemfile).发生的情况是, capistrano配置为仅在production组中安装 gem 包(如在 Gemfile 中)。 So it runs bundle command like bundle install --without development test .所以它运行 bundle 命令,比如bundle install --without development test

Want to verify?想验证?

Run bundle install command in project dir in Production environment, you will see following在生产环境的项目目录中运行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.

Please note ( Gems in the groups development and test were not installed. ).请注意(未安装开发和测试组中的 Gems。 )。

You might recall that you have specified rspec-rails gem to be installed in development mode only.您可能还记得,您已指定rspec-rails gem 仅在development模式下安装。


Solution解决方案

try to specify the RAILS_ENV like尝试指定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

Assuming that you actually have rspec in your Gemfile, if you're getting this error it either means you're not running rake with the proper gems your application needs (use bundle exec rake from your application's root directory to solve), or that your rspec core gem has not been installed.假设您的 Gemfile 中确实有 rspec,如果您收到此错误,则意味着您没有使用应用程序所需的适当 gem 运行 rake(使用应用程序根目录中的bundle exec rake来解决),或者您的rspec 核心 gem 尚未安装。

If after running bundle install , you still get the same error when running bundle exec rake , check that you've actually installed your "test mode" gems.如果在运行bundle install ,您在运行bundle exec rake时仍然遇到相同的错误,请检查您是否实际安装了“测试模式”gems。 This happened to me.这发生在我身上。

In my case, I had not installed my test gems because Bundler exhibits unconventional behavior by remembering the previous arguments passed to the --without option as noted here , so it could be that you think you're installing all your gems when you run bundle install but you might actually be running with (for example...) --without development test as well and not know it.就我而言,我没有安装我的测试 gem,因为 Bundler 通过记住先前传递给--without选项的参数表现出非常规行为,如此处所述,因此您可能认为在运行bundle install时正在安装所有 gem bundle install但您实际上可能正在运行(例如...)--也没有--without development test并且不知道。

Check for something like "Gems in the groups development and test were not installed."检查诸如“未安装组开发和测试中的 Gems”之类的内容。 at the end of your bundle install output.bundle install输出的末尾。

To reset your bundle options, simply remove your ./.bundle dir (so... rm -r ./.bundle ).要重置您的捆绑选项,只需删除您的./.bundle目录(所以... rm -r ./.bundle )。 Now bundle install will be back to normal and rake should work.现在bundle install将恢复正常,rake 应该可以工作了。

I had this issue because in my gem file I did not specified the version of rspec and it got the old version.我有这个问题,因为在我的 gem 文件中我没有指定 rspec 的版本,它得到了旧版本。 I updated my gem file to it:我更新了我的 gem 文件:

gem 'rspec', '3.8.0'

and it worked!它奏效了!

暂无
暂无

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

相关问题 Heroku无法检测到rake任务(LoadError:无法加载此类文件 - rspec / core / rake_task) - Heroku could not detect rake tasks (LoadError: cannot load such file — rspec/core/rake_task) travis无法使用LoadError运行rake:无法加载此类文件— rspec / core / rake_task - travis failing to run rake with LoadError: cannot load such file — rspec/core/rake_task Travis-ci构建失败,耙停止! LoadError:无法加载此类文件— rspec / core / rake_task - Travis-ci build fails with rake aborted! LoadError: cannot load such file — rspec/core/rake_task 无法加载此类文件 -- 使用 capistrano 的 rspec/core/rake_task - cannot load such file -- rspec/core/rake_task with capistrano “rake”命令获取错误“没有这样的文件加载 - rspec / core / rake_task” - The “rake” command gets the error “no such file to load — rspec/core/rake_task” LoadError:无法加载此类文件(Rake Task) - LoadError: cannot load such file (Rake Task) 耙子流产了! LoadError:无法加载此类文件— httparty - rake aborted! LoadError: cannot load such file — httparty 耙子流产了! LoadError:无法加载此类文件 - rake aborted! LoadError: cannot load such file 耙子流产了! LoadError:无法加载此类文件— pilosa - rake aborted! LoadError: cannot load such file — pilosa `require':无法加载这样的文件 - capybara / rspec(LoadError) - `require': cannot load such file — capybara/rspec (LoadError)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM