New Plugin: xls_fixtures

Posted by trevor Tue, 17 Oct 2006 17:54:46 GMT

Here’s a little something I whipped up that’s proved useful.

Yaml is a pretty good format for storing fixture data but it can be a real pain to set up a bunch of fixtures with repeating or incrementing data. There’s a much better tool out there for that – Excel.

One way you can ease the pain of generating reams of fixture data is to build it all up in Excel and export your spreadsheets as csv files and tell Rails to use csv fixtures. Unfortunately I couldn’t find a way to have a moniker (my name for the non-indented line in your yaml fixtures) in the csv files so that I could refer to fixtures by name in my tests.

So what I’ve done is to write a little plugin and rake task that converts xls files into yaml fixtures. See:

Note that it requires the ‘parseexcel’ gem (as in “gem install parseexcel”) and you need to arrange your rows and columns as per the README file in the plugin.


  1. josh susser said 17 minutes later:
    Fixtures in Rails are processed using ERb, so you can use Ruby code to loop and generate reams of data programmatically. This is documented in the API docs:
  2. trevor said 31 minutes later:
    Josh, thanks for the comment. I'm aware that fixtures use ERB - in fact the README for the plugin shows using an ERB string to generate a time value. My personal experience is that ERB looping to generate reams of data is more cumbersome than Excel cut and paste or dragging a cel boundary to autoincrement values.

(leave url/email »)