I have a test with many anonymous TestCases. It worked with test-unit 2.5.0, but the actual version 2.5.3 produces 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 executed and I get the error undefined method sub' for nil:NilClass (NoMethodError) in testrunner.rb:361 (I use the actual test-unit-gem 2.5.3).
With a name for the TestCase, the problem disappears:
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 generate many 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 the error:
comparison of Array with Array failed (ArgumentError) (in collector.rb:48:in sort_by').
My question(s):
It seems this is down to a change in the latest version of the test-unit gem, which now requires a readable name for a 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With