Gemspecs

Erica Kastner · April 9, 2010

I don’t follow Yehuda Katz’ blog (though I should) but he posted an article on basic gem configuration and build steps. It irks me to no end when I clone a git repo and run through the following process:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
> gem build somegem.gemspec
> gem install ./
[write code using gem]
> run code
#ERROR# some gem code is missing a file in "require_once"
> ls /path/to/gem/file/that/is/missing
File not found:  /path/to/gem/file/that/is/missing
> cd /path/to/gem/repo
> ls  /path/to/gem/repo/path/to/gem/file/that/is/missing
missing.rb
> rake build
#ERROR# missing gem my_crappy_test_library
> gem install my_crappy_test_library
> rake build
#ERROR# missing gem my_crappy_mock_library
> rake build
OK
> gem install pkg/

When it could simply be:

1
2
3
4
> gem build somegem.gemspec
> gem install ./
[write code using gem]
> run code

The first scenario happens when someone uses a tool like jeweler to build their gemspec and forgets to commit the latest generated (or what should have been generated) gemspec. Jewler likes to list every single file packaged with the gem, so the gemspec must be refreshed whenever a file is added or removed. When writing a gemspec by hand one, can simply say “all the files in the lib directory are part of this gem.” You can use a handy tool like a .gitignore to prevent unwanted files from appearing in your gem.

Why is this such a big issue? Because, as Yehuda wrote, writing your own gemspec isn’t that hard. In fact, it’s kind of enjoyable, being that it’s a Ruby DSL. Ruby was designed to cause the lowest amount of pain for developers. Our Ruby code should reflect that ethos.