I've recently been doing a few things using Ruby on Rails. Being a proponent of microformats and increasingly a fan of test-driven development I wanted to write some tests to make sure that the microformats being produced by the Rails app I'm working on were all in the right places and contained the right information, so a couple of days ago I wrote a little Gem called assert-microformats.
You can include it in your Rails app by adding this line to your test environment config file (
:source => "http://gems.github.com/",
:lib => false
Now you can test your microformats using some shiny new assertions.
By default these assertions will look for microformats in Rails'
test "show view should contain an hcard" do
You can also test the values of microformat attributes:
assert_mf_hcard :fn => 'George Brocklehurst', :url => 'http://georgebrock.com/'
And you can pass in some HTML, which comes in handy when you're testing view helpers or not using Rails at all:
assert_mf_hcalendar my_html, :summary => 'Birthday party'
The microformat parsing is done using Mofo, so assert-microformats supports all the microformats that Mofo supports.
If you're interested in how it works, or you want to make any changes, the code is all on GitHub.
I'd also like to thank Tom Lea for looking over the code and making some improvements.