Convert OPML into rspec spec files

20 August 2007

I’ve been doing lots of work recently by writing up my specs in OmniOutliner and then converting them into spec files before I start writing my code. I knocked up a quick ruby script to handle the conversion for me.

First off, as I write my specs in a certain way in OmniOutliner the script follows my own conventions so will probably need modifying if you use it in a different way. In OPML form they should look like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
  <head>
    <title>billing_specs</title>
    <expansionState>0,1,5,9,10,14,18,19,23,26,27,34,42,48,57,60,69,78,85,89,94</expansionState>
  </head>
  <body>
    <outline text="Account">
      <outline text="when placing a first order">
        <outline text="should do something"/>
      </outline>
      <outline text="when upgrading">
        <outline text="should do something"/>
      </outline>
   </outline>
  </body>
</opml>


This will produce a spec file like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
describe Account, "when placing a first order" do

  it "should do something" do

  end

end

describe Account, "when upgrading" do

  it "should do something" do

  end
end

And there you have it, this has speeded up my development and saves me the tedium of rewriting everything into spec files.

You can download the script here – you’ll need to have the ‘xmlsimple’ gem installed for it to work


Comments

Sorry, comments are closed for this article.