From: Pit Capitain Date: 2006-01-01T03:49:18+09:00 Subject: Re: Where is my TestResult? cgmjr schrieb: > So I'm teaching myself Ruby. Welcome! > I'm playing with Test::Unit. I've progressed to: > > class TC_venueCreate < Test::Unit::TestCase > .... > def test_Nil > begin > assert_nil(@v) > rescue Test::Unit::AssertionFailedError > puts "Ha ha! It ain't nil!" > ????TestResult.failures.each {|f| puts f.short_display } > raise > end > end > .... > end > > Where is that TestResult? Maybe the following code helps a little bit: require "test/unit" require "enumerator" # the code is in the form of a unit test, just like yours class TestResultSearch < Test::Unit::TestCase # returns all known instances of the given class def instances_of klass ObjectSpace.enum_for( :each_object, klass ).to_a end # returns all classes with the name "TestResult" def testresult_classes instances_of( Class ).select { |c| c.name =~ /\bTestResult$/ } end # this test succeeds, so there is exactly one class named # "TestResult", but see the next test def test_find_class assert_equal 1, testresult_classes.size end # this test doesn't succeed, so the TestResult class doesn't have a # method named "failures". Look at the error message to find the # full name of the TestResult class def test_access_to_failures_via_class testresult_class = testresult_classes[ 0 ] assert_respond_to testresult_class, :failures end # returns all instances of the TestResult class def testresult_instances instances_of Test::Unit::TestResult end # this test succeeds, so there seems to be exactly one instance of # the TestResult class def test_find_instance assert_equal 1, testresult_instances.size end # this test doesn't succeed, so the instances of the TestResult # class don't have a method named "failures", either. Look at the # error message to find the instance variables of the TestResult # instance def test_access_to_failures_via_instance testresult_instance = testresult_instances[ 0 ] assert_respond_to testresult_instance, :failures end # without reading the Test::Unit source code, the only way to get at # the current list of failures I found is to look for the one # instance of TestResult and to access its "@failures" instance # variable def test_access_to_failures_instance_variable testresult_instance = testresult_instances[ 0 ] failures = testresult_instance.instance_variable_get :@failures assert_not_nil failures end end The question is: what do you want to do with the current list of failures? Regards, Pit