On 10/21/06, Jay <jay / jayfields.com> wrote:
> Since Test::Unit is an xUnit port, it's not surprising that defining
> tests means defining methods that begin with 'test_'; however, my
> team has had success with writing tests by using a 'test' class method.
>
> For example, our tests are similar to:
>
> test "two plus two should equal four" do
>    assert_equal 4, Math.plus(2,2)
> end
>
> Using the test class method also allows you to detect tests with
> duplicate names and raise an error.  I believe this is far superior
> to silently failing (where failing is defined as a test that I
> expected to run was not run).
>
> The code for a test class method is very simple:
>
> class Test::Unit::TestCase
>    def self.test(name, &block)
>      test_name = :"test_#{name.gsub(' ','_')}"
>      raise ArgumentError, "#{test_name} is already defined" if
> self.instance_methods.include? test_name.to_s
>      define_method test_name, &block
>    end
> end
>
> Thoughts?  If other people agree that it's a good idea, who can add
> this to Test::Unit?

I'm playing with this now for the next major version of test/unit, but
it will show up in 1.9/2.0, not 1.8. That said, I do plan to do a gem
release that could be used with 1.8.

I'll announce something more definite when I have something more definite.

Thanks,


-- 
Nathaniel Talbott

<:((><