[rspec-users] Date comparisons

Rick DeNatale rick.denatale at gmail.com
Sat May 3 13:51:43 EDT 2008


On Sat, May 3, 2008 at 12:17 PM, Joe Van Dyk <joe at pinkpucker.net> wrote:
> I occasionally get this error:
>
>  1)
>  'A puzzle once featured, should no longer be nominated' FAILED
>  expected: Sun May 04 09:10:26 -0700 2008,
>      got: Sun May 04 09:10:26 -0700 2008 (using ==)
>  ./spec/models/puzzle_spec.rb:180:
>
>
>
>  So, the dates looks the same to me.  Any ideas for how to debug?

Just because too objects have the same to_s representation don't mean
they are equal:

Are these, perhaps times rather than dates?

k$ irb
irb(main):001:0> Time.now == Time.now
=> false
irb(main):002:0> a, b = Time.now, Time.now
=> [Sat May 03 12:23:12 -0400 2008, Sat May 03 12:23:12 -0400 2008]
irb(main):003:0> a == b
=> false

This is a similar issue to Floats where there's more precision than
the exernal representation shows.

-- 
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/


More information about the rspec-users mailing list