From: Eric Hodel Date: 2004-06-03T09:48:03-07:00 Subject: Re: Test::Unit: assert_follows_spec() (or something like that) --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 test= s=20 > >>if wanted, to test deterministic-ness. > > > >If you've got a spec like this, why not write a method to autogenerate > >test methods? >=20 > Why is that better than something like assert_follows_spec()? It's not=20 > more readable IMO, it's not shorter, it adds an additional step in the=20 > 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 =3D [[1, 1, 1], 3] SPEC_TWO =3D [[8, 1, 2], 11] SPEC_THREE =3D [[8, 3, 4], 15] SPEC_FOUR =3D [[4, 3, 2], 9] constants.each do |name| next unless name =3D~ /^SPEC_(.*)/ eval "def test_#{$1.downcase} input =3D self.class.const_get(\"#{name}\")[0] output =3D self.class.const_get(\"#{name}\")[1] assert_equal output, my_meth(input) end" end end --=20 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+siaVG2oJI= =zRMF -----END PGP SIGNATURE----- --qySB1iFW++5nzUxH--