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
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.
···
On Sun, Apr 13, 2008 at 5:15 AM, <mmalaidini@gmail.com> 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?
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
http://www.oreillynet.com/ruby/blog/2008/02/assert2.html
Thanks
MM
···
On Apr 13, 11:07 am, "Phlip" <phlip2...@gmail.com> wrote:
(Use my assert{ 2.0 } instead of assert_equal), but more importantly you
need to override .inspect.
That made it. I was playing with Date#inspect, but noticed that
Test::Unit::Assertions was using PP anyway.
Thanks
MM.
···
On Apr 13, 1:03 pm, Jano Svitok <jan.svi...@gmail.com> wrote:
On Sun, Apr 13, 2008 at 5:15 AM, <mmalaid...@gmail.com> 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
3. create a Date#pretty_print and DateTime#pretty_print method.
···
On Apr 13, 2008, at 10:03 AM, Jano Svitok wrote:
On Sun, Apr 13, 2008 at 5:15 AM, <mmalaidini@gmail.com> 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)