New Gem Generator gets RSpec [video]
One day you will be able to write a human description of a RubyGem and it will make it for you. Ok, that’s crap. But the New Gem Generator is doing more and more cooler things lately; so let’s take a peek…
RSpec
For a growing number of people, RSpec is the way to go, over the Test::Unit test suite. Now, thanks to a contribution from Robby Russell and Graeme Nelson during Railsconf.
$ newgem my_cool_gem -t rspec
$ cd my_cool_gem
$ rake # runs specs
Bonus website
New gems now have a website folder with an index.txt file (redcloth format). Put your glorious promotional materials and tutorials here (plus add additional .txt files as well) and the rake website task will convert them to html files and upload them to your rubyforge website.
The standard template looks like this (you’re encouraged to change some colours or fonts!)
Deploying gems
Ready to release a new X.Y.Z version of your gem? It takes 3 minutes.
- Set the version number in
lib/./version.rb - Check your Manifest.txt that it includes all new files (via
rake check_manifest) - Update
History.txtwith changes. The default supported format is 2 paragraphs - a header and group of bullet points; these look nice when converted to rdoc format. - Commit the new version to repository.
- Deploy/release gem
$ rake deploy VERSION=X.Y.Z
This will release your RubyGem to rubyforge so people can install it; plus upload your website and your rdocs.
You’ll then be prompted to commit a copy of the trunk as a tag REL-X.Y.Z. This could be very useful one day!
Video of NewGem at RejectConf
You can read the pdf slides and/or watch the presentation from RejectConf:
Dr Nic’s Magic Show at RejectConf2007
Update: there is a patch available for edge rails to support merging by generators; add comments to the ticket.
The original Dr Nic’s Magic Models were named as such because I entertained the idea of showing them off as a live magic show. So, given 3 minutes in front of some of the Ruby community’s hottest hackers, I got my chance! Not the Original Magic Models, but the never-before-released Magic Model Generator.
How to install and use the magic_model_generator follows the video from RejectConf:
The Magic Show
How to use it
Create a rails application, and point it to your database.
$ rails magic_show -d [mysql|sqlite|postgresql|oracle|etc|etc] $ cd magic_show $ cp database.yml.sample database.yml and point it to your database.yml to your legacy database
I use the database created for the ActiveRecord test cases – activerecord_unittest. If you’ve never downloaded the activerecord gem, run rake build_[mysql|sqlite|postgresql|oracle|etc|etc]_databases, and then rake test_[mysql|sqlite|postgresql|oracle|etc|etc], then you’ve probably got more free time than I do as a result and I appreciate that. And so does my wife.
Now install the magic_model_generator gem:
$ sudo gem install magic_model_generator
Nonetheless, you’re done. That’s all the preparation I did for the video.
Next I recreated the schema.rb file and the schema_info database table via rake db:migrate.
Next I ran the generator:
$ ./script/generate magic_model
And we’re done.
Coming soon
The MMG is awesome.
The one major drawback of the MMG is the same drawback of all rails generators: if you want to regenerate your models (say you update your schema via migrations) then you cannot regenerate your model associations and validations without completely recreating the file, thus destroying anything else you wrote. Which is useless.
The world of version control (subversion, cvs, etc etc) already solved this problem: merging. So I’m investigating adding merging to the rails_generator. That should be neat.
New Gem Generate to get merging too?
Currently the newgem command doesn’t use the rails_generator for creating files. So adding merging to rails_generator won’t help newgem. That is, unless I rewrite newgem. So, I’ll look into that too.
Functional Testing using a Matrix to cover all edge cases [video]
I’ve been a fan of Ryan Davis‘ (zenspider) and Eric Hodel‘ ZenTest library (including its autotest CI tool for rails and gems), and their Hoe gem, the Rubyforge gem, etc ever since I figured out what they did. (Side note: how to setup rubyforge gem)
Over the last month, Ryan mentioned “functional testing by a matrix” in four great blog articles.
Ryan shows this off at RejectConf; its 16 minutes but definitely worth your time to investigate, as I think this will be awesome for ensuring basic edge cases are thoroughly tested. Can a guest create something? Can a member delete something?
It is hard to see the code on the screen, but look at the blog posts linked above to get the gist of what is being shown.
People were really interested this as you can tell by the huge number of questions, despite this being the last of many many presentations.
This stuff looks primed for a sweet generator to create the test file.
“Drop Rails into TomCat and it just works” - Ola Bini on JRuby presentation
Until Ola Bini stood up at the Stockholm Rails/Ruby Group meeting the other night, I had only a passing interest in JRuby.
To me, running Ruby on Java made as much sense as running Java on a JVM on top of another JVM. Virtual machine on a virtual machine… surely that’s already one virtual machine too many?
Then he said something that no Rails person had said before:
You JAR up your rails app, upload it to TomCat and your Rails app is deployed. It just works.
“Upload it … and it just works” - I still don’t think I’ve heard of a technical solution for deploying Rails apps that’s been bold enough to claim this.
Below is the 30 minute presentation by Ola from the other night where he goes into the details, plus more on the status of JRuby, its performance compared to Ruby, and its future.
Summary: there’s a whole lot of wonderful energy within the JRuby Core camp.
Meta-Magic in Ruby: Dr Nic Unplugged in Stockholm
Last nights’ Ruby meeting in Stockholm had a great turn out and starred Ola Bini sharing the latest and greatest about JRuby, and myself giving an overview on the wonders of Meta-Magic in Ruby.
I’ll write a separate post on Ola’s presentation shortly. It was awesome and I videoed it. Hehehe.
Meta-magic in a programming language is as important to programmers as changeable ring tones are to teenagers. Authors of programming languages cannot provide every feature to everyone, so it is so wonderful to be able to add new language features and extensions that you want. Everyone knows you can add Jessica Simpson as your mobile ring tone, but not all programmers know that you can add new features to their programming world.
So here is an overview to a new world of happiness. It also overviews how the Magic Models work, and introduces a new gem I’m working on - the Magic Wiggly Lines - described as “genius or insane”






