4 ms·
That expression wouldn't always be true even if months did have the same lengths. Two calls to the clock in the same expression are not guaranteed to return the
by bazzargh 11y ago
That expression wouldn't always be true even if months did have the same lengths. Two calls to the clock in the same expression are not guaranteed to return the same time.
In the article, that problem is papered over by using string equality. That makes the problem much less likely (because it only occurs at rollovers of seconds) but it will still happen. Tests like this one - has a subscription expired? - should use inequalities, since that's all that's needed and it won't contain heisenbugs like the above.
Edited to add - just to demonstrate:
irb(main):045:0> i=0; loop { i=i+1; raise "#{i}" unless Time.now.to_s == Time.now.to_s; }
RuntimeError: 61473