views:

510

answers:

1

I am creating a new ruby gem using NetBeans as my IDE. The initial project structure contains a Rakefile with the gem specification and other rake tasks.

My question is, what is the difference between having a gem specification located in a Rakefile compared with having it located in a .gemspec file? Is there a best-practice for where to declare the specification? Should every gem also contain a gemspec file or is having everything in the Rakefile sufficient?

+1  A: 

Having a task in your Rakefile to build a gem for you is fine for most cases. However I prefer having a gemspec file in the project root because most people would expect those settings to be there rather then buried in the Rakefile.

As far as differences are concerned, the Rakefile is going to run the gem build command on its inline gemspec with a rake task. ie. rake gem:build or if using a gemspec you run the command gem build .gemspec

For instance Jeweler, a helper for creating and managing Rubygem projects with Github, keeps a basic spec in a Rakefile and then generates a gemspec file which contains settings from .gitignore as well as generic default settings for generating rdoc, etc.

Corban Brook