Cobblers:

Below my sig is a Shoes class and a test rig, illustrating an application-specific assertion. The other good news is it's short.

To TDD with such a rig, you alternate between improving the assertions, improving the test cases, and improving the code. Eventually you will have a suite of assertions that detect graphical effects relevant to your application, and you TDD by reusing these.

(Rails's controller tests illustrate this effect, where the "application" is the web's GET and POST actions.)

The issues:

 - Shoes dislikes being told when to start and stop
 - Shoes resists commands from without.

Together, those problems break test isolation. A test rig, even if it paints a window, on your monitor, should disappear and report to its environment. And common windowing toolkits do not need to paint a window just to report what they would have painted.

Any suggestions?

--
  Phlip
  http://flea.sourceforge.net/PiglegToo_1.html

require 'test/unit'
require 'test/unit/ui/console/testrunner'


class HexShape < Shoes

  HEX_SHAPE = [
    [ 0,       9.375],
    [ 0,      28.125],
    [16.2375, 37.5  ],
    [32.475,  28.125],
    [32.475,   9.375],
    [16.2375,  0    ] ].freeze

  def hex(exx, why, size)
    shape do
      eol = HEX_SHAPE[-1]
      move_to eol[0] * size + exx, eol[1] * size + why
      HEX_SHAPE.each{|x,y| line_to(x * size + exx, y * size + why) }
    end
  end

  def draw_a_hex
    background rgb(0, 0, 0)
    fill gray(0xAA)
    hex(100, 150, 2)
  end

  def index
    $that = self
    ::Test::Unit::UI::Console::TestRunner.run(HexShapeTest.suite)
#     #quit  #  TODO  uh... bye bye? syonara? exit?
  end

  url '/', :index

end

HexShape::app :title => 'testage'

class HexShapeTest < Test::Unit::TestCase
  require 'rexml/document'

  def indent_xml(doc)
    @_xdoc = REXML::Document.new(doc)
  end

  def activate_shoes(*args)
    indent_xml $that.snapshot{ $that.send(*args) }
  end

  def test_hex
    activate_shoes :draw_a_hex
    assert_hexagon
  end

  def assert_hexagon
    REXML::XPath.each(@_xdoc, '//path') do |path|
      return path if path.attributes['d'].scan(/[A-Z]/) == %w(M L L L L L L Z M)
    end
  end

end

Reply via email to