change usage of pp in Test::Unit assertions

M

mmalaidini

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
 
J

Jano Svitok

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.
 
M

mmalaidini

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.
 
E

Eric Hodel

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)

3. create a Date#pretty_print and DateTime#pretty_print method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,278
Latest member
BuzzDefenderpro

Latest Threads

Top