Create a Ruby Gem. Real World, play by play. Part 4
Part 4 of the Gem creation tutorial that follows the conception of a real Gem.
- Up until this point I haven't run all the specs just individual ones. Before I move on I run the entire test suite with a
bundle exec rakecommand.
- In another tmux window I switch to a sample QuickBooks/Rails app, minimulcasts.
- I add
quickbooks-ruby-baseto the Gemfile, pointing it to the local path.
- I run
- I edit
config/initializers/quickbooks.rbto add the Gem's persistent configuration settings.
- After saving
config/initializers/quickbooks.rbI enter the
- This was because I forgot to expose 'service'. I go back to the Gem code (
lib/quickbooks/base.rb) and add it.
- Within the existing rails console I have to reload the Gem changes I made to
base.rb. To do that without stopping and restarting the rails console I do the following:
- I get another error but at least the 'service' method is working.
- Upon further investigation, the Intuit App. API key and secret are not getting set.
- The problem is not within the
Quickbooks::Baseconfiguration code but the bash shell env values are not available in the tmux window that I am running
- With that is it time to work on the
bundle gemcommand gives me a boilerplate README to get going.
- To aid me in writing a great README I leverage the fantastic Ruby Gem, github-markdown-preview
- After completing the README I am ready to push to Github.
- The final step is to publish to Rubygems.org
- I sign in.
- I search over at Rubygems to verify.
$ cd ~/www/labs/minimulcasts
$ bundle install
Hey Minimul, you forgot to add a test for the
attr_reader :service code you added!
No, I already tested it in the console. The
attr_reader is Ruby core code and I don't need to test it formally. The console test gives me enough confidence to move on. See Part 3 for more on my test philosophy.
Hey Minimul, where is the inline documentation for RDoc or YARD support?
I normally don't find RDoc-like docs useful and consequently don't read them much. Perhaps, if this Gem becomes widely used would I go back and add inline documentation/comments but for now I don't want yet another "weight" preventing me from releasing the Gem. A good README is essential so I am going to focus my efforts there.
Do I have to restart
github-markdown-preview each time I make a change?
No, just refresh the file:// url and the README modifications will display.
That concludes the "Create a Ruby Gem. Real World, play by play." series.
Wow, that four-part tutorial clocked in at a little over 1.5 hours of video content (~95 minutes). I sincerely hope it aids and encourages you to contribute and distribute your knowledge through creating a Ruby Gem. Here are the other installments: