Dr Nic

newgem 1.0.0 all thanks to Cucumber

The New Gem Generator (newgem) was exciting, moderately revolutionary, and definitely helpful two years ago when I created it. Of late it seems to attract a chunk of criticism:

  • making a new gem, but newgem seems broken… hoe hoe
  • NewGem has the “hoe” virus. Much prefer Mr. Bones.
  • the newgem site is begging for someone to put the word fuck on its front page
  • Almost two days fighting with newgem, but today i won! The secret is hoe 1.7.0 and rubygem 1.2.0.
  • unfortunately for the one project I went with newgem, will give Mr. Bones a try on the next gem I throw out there.
  • sow or newgem, neither, Mr. Bones
  • egads, the website newgem sets up for you looks awful
  • newgem seems to be failed to generate package if AUTHOR is an array of authors.

On the positive side of the spectrum is the following list:

  • newgem? really? you rock drnic!

Comparatively, the two lists are awfully different in length. And not in a good way. No, not at all.

I know about these criticisms and platitude(s) because they appear publicly on newgem’s website within a live Twitter search of ‘newgem’. So that the twitter messages on the project’s own homepage are more positive, it was time for a new direction. A new beginning. It was time for a change.

So I fixed it. All of it. As of release 1.0.3 it is perfect [1].

To help you realise how wonderful newgem now is, I shall use the time-proven medium for proving awesomeness: a list. The bullet points are for free.

  • newgem now finally gone 1.0.0. It made it all the way to 0.29.0, but I think 1.0.0 was needed to transfer the message of a new beginning. This is the Obama of Gem Generators.
  • Generated gems are 50% smaller. No more config/hoe.rb. No more website folder (by default). No more tasks folder. No more license file. No more version.rb file.
  • Very little config required before releasing your gem. Just a few fields in the Rakefile.
  • You can use rspec or test/unit for unit testing (option: -T rspec)
  • You can use cucumber for functional testing (option: -i cucumber or run script/generate install_cucumber)
  • Generated gems are future-proofed. They will automatically benefit from future newgem releases.
  • Executable apps within gems now have a lib/appname/cli.rb file for the code base, and a lightweight bin/appname (option: -b appname or run script/generate executable appname)
  • Your README file can be called README.rdoc so it appears nicely formatted on github. No more hoe warning messages about “README.txt is missing” (see feature)
  • GitHub RubyGem support. rake gemspec generates a clean my_project.gemspec file that will work with GitHub
  • RubyForge support. As before, rake release VERSION=X.Y.Z releases your project to RubyForge (see ‘preparing for releases to rubyforge’ help page)
  • newgem’s website is a different colour. Its a nice peppermint green colour. The default website template is now this theme too.
  • You can raise bugs or suggest improvements via Lighthouse tracker

Installation

sudo gem install newgem

Usage

To create your RubyGem scaffold:

newgem mygem
newgem mygem -b myapp              # create a CLI executable
newgem mygem -T rspec -i cucumber  # use rspec and cucumber for gem tests
newgem mygem -w                    # create a simple website
newgem -h                          # get help

Now your code goes in lib folder, and your tests go in test, spec, and/or features as appropriate.

There are a bunch of rails-esque generators (like model or migration) that you can use to help your development:

script/generate executable myapp                       # create your own command-line interface (CLI)
script/generate extconf mylib                          # starting point for C-extensions, plus TDD framework
script/generate component_generator mygenerator scope  # create your own generators for Rails, Merb, RubyGems
script/generate application_generator myapp            # create a CLI that is a generator for something
script/generate -h                                     # get help

Bugs and suggestions

You can raise bugs or suggest improvements via Lighthouse tracker

Thanks goes to… Cucumber

Aside from several days of my time refactoring it, reducing it, and doubling the amount of awesomeness within it, all its wondefulness is thanks to Cucumber.

Cucumber is the successor to Rspec Story Runner. I never found time to play with Story Runner, but Cucumber is blowing my mind with awesomeness. My attention-span is short so I may be forgetting something but I think Cucumber could be the most important piece of software released in 2008 for Ruby-based developers.

Cucumber gave me a framework to specify newgem’s expected behaviour; its features. First I wrote feature descriptions for known, expected behaviour. Then I refactored the crap out of newgem until it was in tip-top shape.

There are over 90 feature steps defining newgem’s current features. To run them:

gem unpack newgem
cd newgem-*
sudo gem install cucumber
cucumber features

And watch the awesomeness of Cucumber unfold before your eyes. What you are seeing isn’t just newgem’s generators being executed, but also the generated code is being executed, rake tasks executed, and generated test files tested.

I can now setup continuous integration for newgem. I have a framework to know that newgem, or any other RubyGem, is doing what it should do.

UPDATE: I want to thank David Chelimsky for our time hanging out in Brazil during RailsSummit. I saw him using Cucumber, and talking about it on stage and then help helped me whilst I integrated it into newgem as a generator and then using it internally itself. For a day and a half we hung out in the hotel foyer. He’s so wonderful.

Cucumber makes me so happy.

Summary

Use newgem. Write gems.

Use mrbones. Write gems.

Use sow. Write gems.

Use gemhub. Write gems.

And write cucumber feature descriptions first. Then unit tests. Then code. Then release. Then profit.

[1] All claims of perfection are for the express purpose of making you try the product enough to use it, share it with your friends, and wrap it up and give it as a gift to family on Xmas day. Gift boxes are available upon request.

Related posts:

  1. First look at rails 3.0.pre This article is out of date in some aspects....
  2. Cucumber: building a better World (object) How to write helper libraries for your Cucumber step definitions...
  3. Testing outbound emails with Cucumber My testimonial for Cucumber still stands even in 2009....
  4. Migrating project websites to github pages with sake tasks, new websites with jekyll_generator Its almost Christmas time and that means presents. It...
  5. My RubyGems development tools and workflow The Open Source Developers Conference (osdc) is a nifty...

16 Responses to “newgem 1.0.0 all thanks to Cucumber”

  1. For simples gems creation, GemHub is another option:

    http://github.com/dcrec1/gemhub/tree/master

  2. Justin says:

    Thanks for acknowledging Mr. Bones superiority over previous versions of NewGem… Hoe is the reason I left NewGem from the start… that and how simply perfect and tiny Mr. Bones can be.

    Either case, its great when people understand why something might not be perfect, and improve on it! Can’t wait to try out the new newgem. ;)

  3. Dr Nic says:

    @Diego – thx, link added.

    @Justin – heh, newgem will probably never be tiny :)

  4. Rob Sanheim says:

    And you could get continuous integration with RunCodeRun. =) Let me know if you’d like to get newgem onto it.

  5. Dr Nic says:

    @rob – its definitely on my todo list now that I have the cucumber features

  6. Luis Lavena says:

    Awesome job Dr. Nic!

    I’ll give a whirl to the fresh new newgem this weekend!

    Thanks!

  7. Rechnung says:

    Usefull post Dr.Nic! Thank you!

  8. [...] newgem 1.0.0 all thanks to Cucumber – Dr. Nic revises his gem generation tool with lots of new features. I’m a full-time Rails developer and contributor, available for long- or short-term consulting, with solid experience in working as part of a distributed team. If you’d like to hire me, drop me a line. Links [...]

  9. Matthijs Langenberg says:

    It appears that ‘gem install cucumber’ will install version 0.1.8 while 0.1.9 is required for running ‘cucumber features’.

  10. Dr Nic says:

    @Matthijs – ok I guess cucumber will need to be built from github until they release 0.1.9. Sorry I didn’t realise ‘cucumber features’ was a new feature.

  11. Dr Nic says:

    @Mattijs – newgem 1.0.4 has hardcoded the dev dependency on cucumber to >= 0.1.8 to prevent this issue now.

  12. jeremy says:

    Hi drnic, that first comment you picked out was my first ever twitter post, so I was pretty surprised, shocked even, to see it posted here! I’ve used newgem many a time in the past and loved it, but I just couldn’t get it going last thursday.

  13. martin says:

    Hey drnic,

    The Rakefile for 1.0.4 is specifying 1.1.8 for cucumber. Shouldn’t that be 0.1.8?

  14. Dr Nic says:

    @martin – doh. Fixed in 1.0.5

  15. Hi Nic, Thanks for pimping Cucumber. I’m super happy you like it.

  16. HH says:

    Hi Dr Nic,
    thanks for the newgem library.
    I’m on my first gem and I am getting the error reported here:
    http://groups.google.com/group/new-gem-generator/browse_thread/thread/4e3bb2d32bf97f2e

    The suggested fixes don’t seem to work for me.
    Any other asuggestions?