How to do conditional gem dependencies?

15 views
Skip to first unread message

Andrew Grimm

unread,
Nov 7, 2009, 12:25:37 AM11/7/09
to jeweler.rb
I have a project that requires the gem "test-unit" under ruby 1.9, but
not under ruby 1.8.

http://stackoverflow.com/questions/1620342/how-do-i-add-conditional-rubygem-requirements-to-a-gem-specification/1624855#1624855
suggests building two gem specifications, but how should I do that?

Thanks,

Andrew Grimm

Pat Allan

unread,
Nov 7, 2009, 12:58:02 AM11/7/09
to jewel...@googlegroups.com
Hi Andrew

Not sure how you could make this play nicely with Jeweler, but maybe
the following in your actual gemspec will work:

if RUBY_VERSION.starts_with?("1.9")
add_dependency 'test-unit'
end

--
Pat

Josh Nichols

unread,
Nov 7, 2009, 12:56:22 PM11/7/09
to jewel...@googlegroups.com
minitest in ruby 1.9 does have some compatibility layer, such that you
can require 'test/unit', and things will still work... mostly.

I don't know about having two gemspecs, because that means two gems,
which starts to get a little weird.

Could you point us to the gem in question to take a look?

Andrew Grimm

unread,
Nov 7, 2009, 4:28:06 PM11/7/09
to jewel...@googlegroups.com
Hi Josh,

The project is http://github.com/agrimm/chaser and
http://gemcutter.org/gems/chaser , and it uses some of the stuff
removed from the Test::Unit standard library in Ruby 1.9.1, as can be
seen in http://gist.github.com/228900. It can run in ruby 1.8 without
the test-unit gem, and it can run in ruby 1.9.1 with the test-unit
gem, but it can't run in ruby 1.9.1 without the test-unit gem.

Andrew

Reply all
Reply to author
Forward
0 new messages