Forum: RSpec [Rails, RSpec] The config.gem rake task chicken and egg thing

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Matt W. (Guest)
on 2009-01-19 21:47
(Received via mailing list)
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.


Matt W.
http://blog.mattwynne.net
http://www.songkick.com
Scott T. (Guest)
on 2009-01-19 22:23
(Received via mailing list)
Matt W. wrote:
>     require 'spec/rake/spectask'
> 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
This topic is locked and can not be replied to.