Weirdest test failure ever...

September 17, 2009 · rails · ruby · testing

So based on some customer feedback on a project I’m currently working on, I added a validation requiring that one of the dates be in the past. The validation is pretty straightforward:

gist 188474

After re-running the test suite though, I got a couple of failures. After digging into the code, it turns out that the following code snippet evaluates to true!

gist 188475

Of course this makes no sense. What’s more is that I tried the code again while writing this blog post and now it’s false. So I did some digging into the Ruby internals and it turns out that Time is implemented in C in the following method:

gist 189385

The best I can come up with is that there’s a problem with the GetTimeval method since it’s just a macro that pulls out some data from a time struct – but the Date class is implemented in pure Ruby. Anyone come across this or can explain better?