Use test / block with anonymous TestCase

This question is for the zu test module version 2.5.3

Problem solved with test block version 2.5.4

I have a test with many anonymous TestCases. It worked with test block 2.5.0, but the actual 2.5.3 version throws an error.

When I run this test:

gem 'test-unit', ">=2.5.2"
require 'test/unit'
Class.new( Test::Unit::TestCase ) do
  def test_add
    assert_equal( 2, 1+1)
  end
end

      

no test is running and I am getting an error undefined method sub' for nil:NilClass (NoMethodError)

in testrunner.rb:361

(I am using actual test-block-pearl 2.5.3).

With a name for TestCase, the problem goes away:

gem 'test-unit'
require 'test/unit'
X = Class.new( Test::Unit::TestCase ) do
  def test_add
    assert_equal( 2, 1+1)
  end
end

      

In my real problem, I am generating a lot of TestCases. So I have a situation like:

gem 'test-unit'
require 'test/unit'
2.times {
  X = Class.new( Test::Unit::TestCase ) do
    def test_add
      assert_equal( 2, 1+1)
    end
  end
}

      

If I execute this I get a warning already initialized constant X

and an error: comparison of Array with Array failed (ArgumentError)

(in collector.rb: 48: in sort_by ').

My question (s):

  • How can I avoid the error?
  • Or: How can I create TestCases with dynamically assigned constants?
+3


source to share


1 answer


This seems to be due to a change in the latest version of the test-unit

gem, which now requires a readable name for the class.

Something like this will work



gem 'test-unit', ">=2.5.2"
require 'test/unit'

Class.new( Test::Unit::TestCase ) do
  def test_add
    assert_equal( 2, 1+1)
  end

  def self.to_s
    "GeneratedClass"
  end

  def self.name
    to_s
  end
end

      

+3


source







All Articles