I've TimeCop installed and using the travel: option with my tests but my tests seem to be failing when I know they shouldn't be. I thought it was my code but it seems that I'm getting fractions of a second added somewhere which is causing dates that should be equal to not be.
Given the following rspec test:
it 'Testing TimeCop', travel: Time.new(2021, 10, 5, 9, 0, 0, '-07:00') do puts "Time.now: #{Time.now}" puts "Time.new(2021, 10, 5, 9, 0, 0, '-07:00')}: #{Time.new(2021, 10, 5, 9, 0, 0, '-07:00')}" puts "Time.now == Time.new(2021, 10, 5, 9, 0, 0, '-07:00')}: #{Time.now == Time.new(2021, 10, 5, 9, 0, 0, '-07:00')}" puts "Time.now - Time.new(2021, 10, 5, 9, 0, 0, '-07:00')}: #{Time.now - Time.new(2021, 10, 5, 9, 0, 0, '-07:00')}" end I'm getting the following output:
Time.now: 2021-10-05 09:00:00 -0700 Time.new(2021, 10, 5, 9, 0, 0, '-07:00')}: 2021-10-05 09:00:00 -0700 Time.now == Time.new(2021, 10, 5, 9, 0, 0, '-07:00')}: false Time.now - Time.new(2021, 10, 5, 9, 0, 0, '-07:00')}: 0.0004161418930646181 As you can see these times are not equal and the reason being is there seems to be a 4/10000th of a second discrepancy between the two. I don't know whats going on here. Is there something I'm doing wrong with TimeCop or is this a bug?
Timecop.freeze(Time.new(2021, 10, 5, 9, 0, 0, '-07:00')) { }? Maybe the RSpec integration is not properly setup?travel:works so TimeCop is doing something but my tests are not aware ofTimeCopapparently, so I need to properly set it up as you say. Any ideas would be helpful. Also, please submit an answer like spickerman did and I'll give you a +1 when I finally get this figured out.