# Change usage of pp in Test::Unit assertions

**URL:** <https://www.ruby-forum.com/t/change-usage-of-pp-in-test-unit-assertions/134630>\
**Category:** Ruby\
**Created:** [April 13, 2008, 5:15am UTC](https://www.ruby-forum.com/t/change-usage-of-pp-in-test-unit-assertions/134630 "2008-04-13T05:15:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6bbea6/32.png) [@mman](https://www.ruby-forum.com/u/mman)\
**Post date:** [April 13, 2008, 5:15am UTC](https://www.ruby-forum.com/t/change-usage-of-pp-in-test-unit-assertions/134630/1 "2008-04-13T05:15:52Z")

</div>

Hi all.

I have some Test::Unit testcases that deal with Date and DateTime. If,  
for whatever reason, I have a failing assert\_equal on either Date or  
DateTime, the resulting message is quite difficult to read: the reason  
obviously is that pp dumps the content of the object, it doesn’t rely  
on to\_s or other more readable ways.

Is there any way to change this behaviour and make assert\_equal print  
Date.to\_s and DateTime.to\_s when the comparison fail?

TIA  
MM

---

<div class="post-metadata">

**Author:** ![mman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6bbea6/32.png) [@mman](https://www.ruby-forum.com/u/mman)\
**Post date:** [April 13, 2008, 7:04pm UTC](https://www.ruby-forum.com/t/change-usage-of-pp-in-test-unit-assertions/134630/2 "2008-04-13T19:04:37Z")

</div>

On Sun, Apr 13, 2008 at 5:15 AM, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi all.
> 
> I have some Test::Unit testcases that deal with Date and DateTime. If,  
> for whatever reason, I have a failing assert\_equal on either Date or  
> DateTime, the resulting message is quite difficult to read: the reason  
> obviously is that pp dumps the content of the object, it doesn’t rely  
> on to\_s or other more readable ways.
> 
> Is there any way to change this behaviour and make assert\_equal print  
> Date.to\_s and DateTime.to\_s when the comparison fail?

You have two possibilities:

1. set Test::Unit::Assertions.use\_pp to false, thus using Date#inspect,  
or
2. create your own assertion that will use to\_s. See documentation for  
Test::Unit::Assertions.  
(the easiest way would be to copy the code for assert\_equal from  
assertions.rb and change the first line with build\_message)

J.

---

<div class="post-metadata">

**Author:** ![mman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6bbea6/32.png) [@mman](https://www.ruby-forum.com/u/mman)\
**Post date:** [April 14, 2008, 1:00am UTC](https://www.ruby-forum.com/t/change-usage-of-pp-in-test-unit-assertions/134630/3 "2008-04-14T01:00:42Z")

</div>

On Apr 13, 1:03 pm, Jano S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Sun, Apr 13, 2008 at 5:15 AM, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Is there any way to change this behaviour and make assert\_equal print  
> > Date.to\_s and DateTime.to\_s when the comparison fail?
> 
> You have two possibilities:
> 
> 1. set Test::Unit::Assertions.use\_pp to false, thus using Date#inspect, or

That made it. I was playing with Date#inspect, but noticed that  
Test::Unit::Assertions was using PP anyway.

Thanks  
MM.

---

<div class="post-metadata">

**Author:** ![mman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6bbea6/32.png) [@mman](https://www.ruby-forum.com/u/mman)\
**Post date:** [April 14, 2008, 6:04pm UTC](https://www.ruby-forum.com/t/change-usage-of-pp-in-test-unit-assertions/134630/4 "2008-04-14T18:04:32Z")

</div>

On Apr 13, 11:07 am, “Phlip” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> (Use my assert{ 2.0 } instead of assert\_equal), but more importantly you  
> need to override .inspect.

Oh nice, I didn’t know about it, I’ll give it a try.

And if you, random reader, are ignorant like me, take a look at  
[O'Reilly Media - Technology and Business Training](http://www.oreillynet.com/ruby/blog/2008/02/assert2.html)🙂

Thanks  
MM

---

<div class="post-metadata">

**Author:** ![mman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6bbea6/32.png) [@mman](https://www.ruby-forum.com/u/mman)\
**Post date:** [April 15, 2008, 11:17am UTC](https://www.ruby-forum.com/t/change-usage-of-pp-in-test-unit-assertions/134630/5 "2008-04-15T11:17:10Z")

</div>

On Apr 13, 2008, at 10:03 AM, Jano S. wrote:

> > 
> 
> assertions.rb and change the first line with build\_message)

1. create a Date#pretty\_print and DateTime#pretty\_print method.
