Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should I add development dependencies to my gemspec

Tags:

ruby

rubygems

It seems like a strange feature that rubygems wants to know what my development dependencies are, so far I never saw it used to actually load these when running the gem tests.

like image 936
grosser Avatar asked Aug 08 '11 16:08

grosser


2 Answers

If someone decides to hack your gem for whatever reason, e.g. they fork it on Github to add a feature to it (which they might want to contribute), it helps if they know what development dependencies your gem needs (e.g. testing frameworks, mocking tools etc.).

If you're using bundler with the gemspec command, it will hook into your gemspec dependencies and install the development dependencies along with the runtime ones when you run

bundle install

This saves you having to install these gems manually.

The gem command can also list all the dependencies of a gem including the development ones:

gem dependency my_gem

Gem my_gem-0.1.3
  activerecord (~> 3.0.0)
  json (~> 1.4.3, development)
  rake (>= 0, development)
  rspec (~> 2.5.0, development)
  ruby-openid (~> 2.1.0)

Once again this is probably more for other people rather than for yourself.

like image 92
skorks Avatar answered Dec 09 '22 04:12

skorks


My gems have normally unit-test. This test requires sometimes gems, which are not needed to use the gem. Or perhaps you need additional gems to generate parts of the gem.


Once I misused development dependencies to define 'optional dependecies' (dependecies were necessary for some specific features of my gem, but not needed for the 'normal' usage).

Example: My application offered the posibility to export to a file as text or pdf. The pdf-generation uses prawn. So prawn is a dependecy - but it is not necessary to use the application, only a specific feature needs it.

So I didn't add prawn to gem dependencies (it is not necessary), but to the development dependencies (it is usefull for the gem).

like image 39
knut Avatar answered Dec 09 '22 05:12

knut