[rspec-users] [Rails, RSpec] The config.gem rake task chicken and egg thing

Scott Taylor scott at railsnewbie.com
Mon Jan 19 15:03:06 EST 2009

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:

    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


More information about the rspec-users mailing list