# Where is my TestResult?

**URL:** <https://www.ruby-forum.com/t/where-is-my-testresult/51450>\
**Category:** Ruby\
**Created:** [December 31, 2005, 12:51pm UTC](https://www.ruby-forum.com/t/where-is-my-testresult/51450 "2005-12-31T12:51:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cgmjr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cgmjr](https://www.ruby-forum.com/u/cgmjr)\
**Post date:** [December 31, 2005, 12:51pm UTC](https://www.ruby-forum.com/t/where-is-my-testresult/51450/1 "2005-12-31T12:51:32Z")

</div>

So I’m teaching myself Ruby. 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?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![cgmjr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cgmjr](https://www.ruby-forum.com/u/cgmjr)\
**Post date:** [December 31, 2005, 7:50pm UTC](https://www.ruby-forum.com/t/where-is-my-testresult/51450/2 "2005-12-31T19:50:41Z")

</div>

cgmjr schrieb:

> So I’m teaching myself Ruby.

Welcome!

> ```
> 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

---

<div class="post-metadata">

**Author:** ![cgmjr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cgmjr](https://www.ruby-forum.com/u/cgmjr)\
**Post date:** [December 31, 2005, 8:38pm UTC](https://www.ruby-forum.com/t/where-is-my-testresult/51450/3 "2005-12-31T20:38:54Z")

</div>

Excellent, Pit! Many new nuggets of Rubyness for me to chew on here,  
many thanks for taking the time on this Holiday to reply.

> The question is: what do you want to do with the current list of failures?

As I mentioned, I’m exploring Test::Unit to better understand what’s  
going on under the surface. I don’t have a particular need other than  
familarization and dexterity with Ruby.

However, it seems that one must be able to locate the instance of  
Test::Unit::TestResult in order to invoke it’s #add\_observer() method,  
ja? Or perhaps there is a more direct way to Observe what is  
happening? Again, I’m just curious at this point, but some context of  
my project might help:

I wish to create a Ticket Box Office for my wife’s theater company. It  
is a facinating little problem, involving a neat little Domain Model of  
Venues, Performances, Seats, Reservations, and the like. I’m starting  
my Ruby journey by implementing a core concept, the Venue. It will be  
a simple CRUD use case/user story(ies), but will lead to such fun as  
SeatMaps and whatnot. Once I feel like I have sufficent understanding  
of the Standard API, I’ll move on to Rails and let the web fun begin!

Many thanks again for the code example…_runs of to start chewing_…  
g.
