Heroku could not detect rake tasks (LoadError: cannot load such file — rspec/core/rake_task)

 ̄綄美尐妖づ 提交于 2021-02-08 13:07:54

问题


I'm using travisCI to deploy to heroku and I am getting this error. It has only just started happening.

I have the basic rails Rakefile and I have a file that looks like this as otherwise travis cannot detect the rake tasks:

# lib\tasks\spec.rake
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new
task :default => :spec

Why would this error be displaying specifically for heroku?

EDIT - I had a similar version to the (better) answer given:

begin
  require 'rspec/core/rake_task'
  desc "Run all examples"
  RSpec::Core::RakeTask.new(:spec) do |t|
    t.rspec_opts = %w[--color]
    t.pattern = 'spec/*_spec.rb'
  end
 rescue LoadError
end

回答1:


If rspec isn't in the production group (it generally isn't) then the code you posted would fail when run in a production environment like heroku.

In the rspec docs they recommend doing this:

begin
  require 'rspec/core/rake_task'
  RSpec::Core::RakeTask.new(:spec)
rescue LoadError
end

So that the absence of rspec doesn't stop your rakefile loading.




回答2:


FWIW, I just faced the same issue. I fixed it by moving rspec-rails to production as shown below. I don't know why it works, but it works for me.

group :production, :development, :test do
  gem 'rspec-rails', '~> 3.8'
end



回答3:


You can edit your Gemfile to add rspec gem into production group. For example.

group :production, :test do
    gem 'rspec-rails', '~> 3.5'
end


来源:https://stackoverflow.com/questions/29732542/heroku-could-not-detect-rake-tasks-loaderror-cannot-load-such-file-rspec-co

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!