How I use the testdata gem

The testdata gem is a test framework for unit testing. It uses a separate file for test data to keep things as simple as possible. Here's an example:

#!/usr/bin/env ruby

# file: test_gtk2html.rb

require 'testdata'
require 'requestor'

eval'') do |x|
  x.require 'gtk2html'

class TestGtk2HTML < Testdata::Base

  def tests()

    test 'Render to_a' do |html, width, height|
      doc =, width, height).to_a.inspect


url = ''
#=> {:passed=>true, :score=>"2/2", :failed=>[]}

To run a specific test, we enter the path number into the run method e.g. '1'

Note: The path number is simply the identifier for a specific test.

If the test failed, we can examine the expected results with the actual results using the debug flag e.g. '1', debug=true


  html: <html style="background-color:white;margin:0;padding:0;font-size:1.3em;color:red"><div style="background-color:white;margin:0;padding:0;font-size:1.3em;color:red"></div></html>
  width: 320
  height: 240

type or description:
 Render to_a: 

expected : 
  ["[[:draw_box, [0.0, 0.0, 0.0, 0.0], [0, 0, 320, 240], [0.0, 0.0, 0.0, 0.0], {:\"background-color\"=>\"white\", :margin=>{:top=>0.0, :right=>0.0, :bottom=>0.0, :left=>0.0}, :padding=>{:top=>0.0, :right=>0.0, :bottom=>0.0, :left=>0.0}, :\"font-size\"=>\"1.3em\", :color=>\"red\"}], [[:draw_box, [0.0, 0.0, 0.0, 0.0], [nil, nil, nil, nil], [0.0, 0.0, 0.0, 0.0], {:\"background-color\"=>\"white\", :margin=>{:top=>0.0, :right=>0.0, :bottom=>0.0, :left=>0.0}, :padding=>{:top=>0.0, :right=>0.0, :bottom=>0.0, :left=>0.0}, :\"font-size\"=>\"1.3em\", :color=>\"red\"}]]]"]