# Subclassing assertions.rb

**URL:** <https://www.ruby-forum.com/t/subclassing-assertions-rb/98402>\
**Category:** Ruby\
**Created:** [July 14, 2006, 2:12pm UTC](https://www.ruby-forum.com/t/subclassing-assertions-rb/98402 "2006-07-14T14:12:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pkspence](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a88e57/32.png) [@pkspence](https://www.ruby-forum.com/u/pkspence)\
**Post date:** [July 14, 2006, 2:12pm UTC](https://www.ruby-forum.com/t/subclassing-assertions-rb/98402/1 "2006-07-14T14:12:53Z")

</div>

I need to subclass Test::Unit::Assertions so I can log the assertions as  
they are being, uhh… “asserted”. The following is giving me a “parse  
error, unexpected ‘\<’” on the line indicated below.

require ‘test/unit/assertions’

module Test  
module Unit  
module MhiqAssertions \< Assertions # \<-- PARSE ERROR!

```
  #overloaded Test::Unit::Assertions.assert()
  def assert(boolean, message=nil)

    #wrap the assertion
    _wrap_assertion do

      assert_block("assert should not be called with a block.") { 

```

!block\_given? }  
assert\_block(build\_message(message, “\<?\> is not true.”,  
boolean)) { boolean }

```
      #-- log the assertion here

    end ## do

  end ## method assert()

end ## module MhiqAssertions

```

end ## module Unit

end ## module Test

---

<div class="post-metadata">

**Author:** ![pkspence](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a88e57/32.png) [@pkspence](https://www.ruby-forum.com/u/pkspence)\
**Post date:** [July 14, 2006, 7:18pm UTC](https://www.ruby-forum.com/t/subclassing-assertions-rb/98402/2 "2006-07-14T19:18:05Z")

</div>

On Jul 14, 2006, at 5:13 AM, Patrick S. wrote:

> I need to subclass Test::Unit::Assertions so I can log the  
> assertions as  
> they are being, uhh… “asserted”. The following is giving me a “parse  
> error, unexpected ‘\<’” on the line indicated below.

You can only subclass a class.

You really want to do one of:

Add methods to Test::Unit::Assertions

Make a custom Test::Unit::TestCase subclass with your new assertions

Write your own set of assertions and include it into  
Test::Unit::TestCase

I recommend the first or second.

–  
Eric H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)
