Polishing a gem

Since Watu is an application written using Ruby on Rails, we use a lot of gems. A couple of weeks ago I found a bug in one of these gems. In this situation, the common action is to fix the bug and provide a patch upstream. The problem was that the gem was really out of shape: tests were red, there was a lot of outdated code and it was packaged using Jeweler. So, before fixing the bugs, I took on the job of polishing the gem. These are my gem-agnostic tips for the job:

  • Use bundler to package/manage the gem.
  • If the gem tests are written using a testing tool like RSpec, update the tests to work with the latest stable version of the tool (I migrated from RSpec 2 to RSpec 3 and it wasn’t big deal).
  • Make the gem work with the latest versions of its dependencies (but also support versions widely used by the community).
  • Use appraisal to test the gem against different versions of its dependencies.
  • Use Travis or other continuous integration service to ensure the tests are continuously run after every push against the different versions of dependencies and different Ruby versions. (Tip: you can run this testing matrix locally using wwtd).

After that, the gem is ready for a new release. After the release, you can fix that damned bug.

Picture by Mitch Altman

Leave a Reply