--qySB1iFW++5nzUxH
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

David Garamond (lists / zara.6.isreserved.com) wrote:

> Eric Hodel wrote:
> >>The assert_follows_spec() could even perform several iterations of tests 
> >>if wanted, to test deterministic-ness.
> >
> >If you've got a spec like this, why not write a method to autogenerate
> >test methods?
> 
> Why is that better than something like assert_follows_spec()? It's not 
> more readable IMO, it's not shorter, it adds an additional step in the 
> Makefile/build process.

No additional steps.  Ruby does it for you:

require 'test/unit'

def my_meth(args)
  args.inject 0 do |acc, item|
    acc + item
  end
end

class MyTest < Test::Unit::TestCase

  SPEC_ONE = [[1, 1, 1], 3]
  SPEC_TWO = [[8, 1, 2], 11]
  SPEC_THREE = [[8, 3, 4], 15]
  SPEC_FOUR = [[4, 3, 2], 9]

  constants.each do |name|
    next unless name =~ /^SPEC_(.*)/

    eval "def test_#{$1.downcase}
      input = self.class.const_get(\"#{name}\")[0]
      output = self.class.const_get(\"#{name}\")[1]
      assert_equal output, my_meth(input)
    end"
  end
end


-- 
Eric Hodel - drbrain / segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E  7C11 332A 551C 796C 9F04


--qySB1iFW++5nzUxH
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (FreeBSD)

iD8DBQFAv1ZDMypVHHlsnwQRAlOlAJ4qUrwaBPIH9ieeMn3x4GI5HcbS0gCg7/r8
HR82jDVMT6FrS+siaVG2oJIMF
-----END PGP SIGNATURE-----

--qySB1iFW++5nzUxH--