9

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
Koxzi
  • 1,021
  • 1
  • 10
  • 21

2 Answers2

11

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.

Frederick Cheung
  • 83,189
  • 8
  • 152
  • 174
  • Oh right. I had a slightly more complex version but commented out. I've added it to the post for reference. – Koxzi Apr 19 '15 at 18:24
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
suretrust
  • 31
  • 2