LoadError: cannot load such file -- rspec/core/rake_task

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?


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

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.