问题
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