I have created several shared example groups for Rspec which I would like to reuse in other applications. The best approach to achieving this seems to be to package these into a gem. However I can’t seem to find a good guide to get me started. There are several different methods to accomplish this, and all of the guides I’ve read look like they might be outdated. Can anybody point me in the right direction?
Share
Necessary Knowledge
Gems are pretty simple, but there was a huge void in terms of documentation for a really long time. Fortunately that isn’t the case anymore.
They’re ultimately nothing more than a .gemspec file and an understanding of paths and dependencies (which you only need to know about if you depend on other gems), though people do expect you to follow certain conventions.
The best walkthrough I’ve seen is in the guides.
For the conventions, the guides have a nice list here and the packaging standard is really great as well.
Further Thoughts
These days, when I want to make a gem, I start off with Bundler (which I prefer over hoe/new gem/jeweler/etc…). This Railscast covers how to do that. Now, Bundler will assume you know all sorts of stuff (git, bundler, rake) which I do, so it doesn’t bug me anymore, but once upon a time it was too much.
The simple fact of the matter is you don’t need Bundler (in the future, if you have dependencies and want to maintain your gem, then it will make your life easier, but for now you don’t need it). And you don’t need git or any version control if you don’t understand it yet (put it on your tolearn list, though). And you don’t need rake (its just a CLI to common tasks, but if you don’t understand all the crap it’s doing, you don’t need it, you can test directly with the rspec binary, you can package your gems directly with the gem binary, you can manage your .gemspec yourself rather than having Rake generate it for you, etc).
The trick is to separate out what all these tools do for you from what you actually want them to do for you. That can be tricky when you don’t know how they work / what they do, since they want to do everything. I was able to get past this ignorance by using a really simple tool called gem this which was a bit dated the last time I used it, but is ultimately about as simple as you can get. Here‘s a great video by it’s author.