Matt Wynne wrote:
Sorry folks, because I know this has been asked before but I don't remember anyone giving enough detail for me to sort this out the way I want to.

How do I change my rake tasks to silently fail if they can't require rspec?

I can do this:

  begin
    require 'spec/rake/spectask'

    ... the whole Rake task ...

  rescue LoadError
    puts "Unable to load RSpec - do you need to install the gem?"
  end


... but that seems insane to have to indent all the code inside that big begin / rescue block. I'm sure there's a way to exit the script without causing the whole rake loading chain to fail, but what is it? I tried 'exit 0' but that seems to exit the whole process.

So I guess this is more a Ruby question than an RSpec question really, but I'm sure a good answer will help a few other people out too.


I suppose you could override describe:

 begin
   require 'spec/rake/spectask'
 rescue LoadError
   Kernel.warn "Unable to load RSpec - do you need to install the gem?"

   class << self
     def describe(*args)
       # do nothing
     end
   end
 end


Scott

_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to