Best practice for specifying dependencies that cannot be put in gemspec?

5,337 views
Skip to first unread message

Earle Clubb

unread,
Feb 8, 2011, 10:32:45 AM2/8/11
to ruby-bundler
I'm developing a bundler-generated gem which depends on some other
gems. One of the dependencies has a name for the require statement
that is different from the gem name:

# Gemfile
gem 'curb', :require => 'curl'

Another uses a :git option:

# Gemfile
gem 'factory_girl', :git => 'git://github.com/thoughtbot/
factory_girl.git

Best-practices say to specify all dependencies in the gemspec instead
of in the Gemfile. I can't see how to to it in this case. These don't
work:

# gemspec
s.add_dependency 'curb', :require => 'curl'
s.add_development_dependency 'factory_girl', :git => 'git://github.com/
thoughtbot/factory_girl.git

What's the best way to handle this situation?

Rhett Sutphin

unread,
Feb 8, 2011, 1:46:34 PM2/8/11
to ruby-b...@googlegroups.com
Hi Earle,

Requires: You should not rely on bundler's auto-requires in a gem at all. Always explicitly require anything you use directly in library code.

Gems from git: in bundler 1.0.9 (I think) and later, you can put overrides in the Gemfile. E.g.:

# gemspec
s.add_development_dependency 'factory_girl', '~> 2.0'

# Gemfile
group :development do
gem 'factory_girl', :git => 'git://github.com/thoughtbot/factory_girl.git'
end

For a development dependency, this is fine. For a runtime dependency, you should only depend on the edge version while you are waiting for a new release to become available -- before you release your gem, you should remove all references to unreleased versions of runtime deps and ensure that your gem still works.

Further discussion: http://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/

Rhett

>
> --
> You received this message because you are subscribed to the Google Groups "ruby-bundler" group.
> To post to this group, send email to ruby-b...@googlegroups.com.
> To unsubscribe from this group, send email to ruby-bundler...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/ruby-bundler?hl=en.
>

Earle Clubb

unread,
Feb 8, 2011, 3:15:57 PM2/8/11
to ruby-b...@googlegroups.com
Awesome. I tried adding a couple of gems as devel dependencies in my gemspec:

s.add_development_dependency 'capybara', '>= 0.4.0'
s.add_development_dependency 'launchy'

but `bundle install` ignores them (I am not excluding any groups). Am I doing something wrong?

Earle

Earle Clubb

unread,
Feb 8, 2011, 3:27:26 PM2/8/11
to ruby-b...@googlegroups.com
Right. It helps if I save my gemspec after adding devel dependencies. ;-)

All is good. Thanks for the help.

Earle

Reply all
Reply to author
Forward
0 new messages