LoadError: cannot load such file -- rspec/core/rake_task
Solution 1
It seems that running bundle exec rake -t
will work. 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. Also see this SO post. What does bundle exec rake mean?
Solution 2
After having earlier run : sudo gem install bundler
I created a Gemfile with:
gem 'rake'
gem 'rspec'
gem 'kramdown'
and did bundle install
. Now I dont get the error.
Solution 3
In Production Environment
What happens is, capistrano
is configured to only install gem bundle in production
group(as in Gemfile). So it runs bundle command like bundle install --without development test
.
Want to verify?
Run bundle install
command in project dir in Production environment, you will see following
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.).
You might recall that you have specified rspec-rails
gem to be installed in development
mode only.
Solution
try to specify the RAILS_ENV
like
# 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
Solution 4
I had this issue because in my gem file I did not specified the version of rspec and it got the old version. I updated my gem file to it:
gem 'rspec', '3.8.0'
and it worked!
Solution 5
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.
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. 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.
Check for something like "Gems in the groups development and test were not installed." at the end of your bundle install
output.
To reset your bundle options, simply remove your ./.bundle
dir (so... rm -r ./.bundle
). Now bundle install
will be back to normal and rake should work.
Related videos on Youtube
Allen Lin
Updated on May 19, 2020Comments
-
Allen Lin almost 4 years
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
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:
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
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
-
pangpang almost 9 years(1)this Gemfile contains multiple primary sources. (2)Your Gemfile lists the gem geoblacklight (>= 0) more than once.(3)You must
gem install bundler
andbundle install
-
Allen Lin almost 9 years@pangpang Thanks for your reply! I've updated the post! Essentially, I don't understand why the error and warning messages say that I have multiple 'source' and geoblacklight. Is there any other files I should look into?
-
Taryn East almost 9 yearsWhat happened when you followed this instruction: "(See full trace by running task with --trace)" ? :)
-
Taryn East almost 9 yearsAlso - the whole file-expand-path bit at the bottom. isn't that just loading the same Gemfile a second time? That might be why you're getting "two sources" and two of everything else too
-
Allen Lin almost 9 years@TarynEast Thanks for reminding me that! :) Please see the full trace!
-
Allen Lin almost 9 years@TarynEast And just tried deleting the last block of code - you are right that the last block loads Gemfile the second time which creates the warning message. But the other error messages are exactly the same when I ran without the last block of code.
-
pangpang almost 9 yearsPlease run
rake -T
-
Allen Lin almost 9 years@pangpang Yes, just did what you said. Please see the edited post! Thanks for your help!
-
pangpang almost 9 yearsCan you check the bundler version?
bundler -v
-
Allen Lin almost 9 years@pangpang Yes, it's Bundler version 1.9.6
-
pangpang almost 9 yearsLet us continue this discussion in chat.
-
Allen Lin almost 9 yearsIssue is still not solved. Sad :( Please let me know if there is any other additional information I could provide!
-
-
nikkypx about 8 years-t just adds a trace
-
rogerdpack about 4 yearsSure enough
gem install rspec
fixed it.