rubyrubygemsgemspecs

Should the Gemspec be packaged with a Ruby Gem?


I read that we shouldn't package test files with a Ruby Gem.

Now I'm wondering, if we should package the Gemspec.

For example, given the following Ruby Gem:

tree .
.
├── LICENSE.txt
├── README.md
├── lib
│   └── simplegem.rb
├── simplegem.gemspec
└── test
    ├── simplegem_test.rb
    └── thing_test.rb

2 directories, 6 files

Should my Gem::Specification look like:

$LOAD_PATH.unshift 'lib'
require 'simplegem'

Gem::Specification.new do |s|
  s.name        = 'simplegem'
  s.version     = Simplegem::VERSION
  s.licenses    = ['MIT']
  s.summary     = 'This is a simple gem!'
  s.description = 'Much longer explanation of the simple gem!'
  s.authors     = ['...']
  s.email       = '...'
  s.files       = %w(simplegem.gemspec
                     LICENSE.txt
                     README.md
                     lib/simplegem.rb)
  s.homepage    = 'https://github.com/mbigras'
end

Or:

$LOAD_PATH.unshift 'lib'
require 'simplegem'

Gem::Specification.new do |s|
  s.name        = 'simplegem'
  s.version     = Simplegem::VERSION
  s.licenses    = ['MIT']
  s.summary     = 'This is a simple gem!'
  s.description = 'Much longer explanation of the simple gem!'
  s.authors     = ['...']
  s.email       = '...'
  s.files       = %w(LICENSE.txt
                     README.md
                     lib/simplegem.rb)
  s.homepage    = 'https://github.com/mbigras'
end

Notice how the first includes simplegem.gemspec in the s.files array and the second does not.


Solution

  • There is no need to pack a Gemspec with a Ruby gem, in a survey of the gems installed in one of my gem homes I noticed that in fact most gems don't include the gemspec file:

     ~/.rvm/gems/ruby-2.3.7/gems $ find . -name \*.gemspec | wc -l
          95
     ~/.rvm/gems/ruby-2.3.7@happy-backend/gems $ ls | wc -l
         318
    

    Why would you want to not pack it?

    Why pack it?