Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 589
Koxzi Avatar asked Apr 19 '15 16:04

Koxzi


1 Answers

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.

like image 150
Frederick Cheung Avatar answered Sep 16 '22 17:09

Frederick Cheung