Introducing the Testdata text gem

require 'testdata_text'

# the following text is an example of the manually input chronic_cron test data
# prior to being transformed to XML (specifically testdata Polyrex format).
 
txt =<<EOF
title: chronic_cron testdata
ruby_version: ruby-1.9.2-p180
script: //job:test http://rorbuilder.info/r/gemtest/chronic_cron.rsf
test_dir: /home/james/test-ruby/chronic_cron

path: 1
type: date only
desc:

input:
  date: 22-Apr-2011 12:34
  entry: * * * * *

output:
  date: 2011-04-22 12:34

------------------------------

path: 2
type: date only
desc:

input:
  date: 22-Apr-2011 12:34
  entry: * * * * *

output:
  date: 2011-04-22 12:34

------------------------------
EOF

xml = TestdataText.parse(txt)
#=>

<?xml version="1.0"?>  
<summary>
  <title>chronic_cron testdata</title>
  <recordx_type>polyrex</recordx_type>
  <schema>tests/test[path,type,description]/io[type,*]</schema>
  <ruby_version>ruby-1.9.2-p180</ruby_version>
  <script>//job:test http://rorbuilder.info/r/gemtest/chronic_cron.rsf</script>
  <test_dir>/home/james/test-ruby/chronic_cron</test_dir>
</summary>
<records>
  <test>
<summary>
  <path>1</path>   
  <type>date only</type>
  <description>date only</description>
</summary>
<records>
  <io>
    <summary>
      <type>input</type>
      <date>22-Apr-2011 12:34</date>
      <entry>* * * * *</entry>
    </summary>
    <records/>
  </io>
...

The Testdata text gem is used for transforming text into XML for input into the testdata gem. I've found over the past few months that editing inputs in XML format can be tedious which is why I'm experimenting with using this simpler approach. Note: If any of the initial text values contain angle brackets the value will automatically be wrapped within a CDATA element.

Resources

Tags:
Source:
2126hrs.txt
Published:
28-03-2014 21:26