TimeHelpers#travel_to does not stub Time.new

Hi folks,

I ran into an issue when trying to replace usage of Timecop.freeze in a test with travel_to. I’m using a third party library that invokes Time.new without any arguments (as opposed to Time.now). Looking at the ruby docs, this seems to be a valid way to initialize to now.

It doesn’t look like new is stubbed in time_helpers.rb.

# Expected
irb> travel_to(Time.now) { puts(Time.now.to_s); sleep(1); puts(Time.now.to_s) }
2023-01-25 00:13:07 +0000
2023-01-25 00:13:07 +0000
=> nil

# Unexpected
irb> travel_to(Time.now) { puts(Time.new.to_s); sleep(1); puts(Time.new.to_s) }
2023-01-25 00:13:16 +0000
2023-01-25 00:13:17 +0000
=> nil

I’m new to ruby and rails, so I don’t want to make any assumptions by just filing a bug. Is this a bug with travel_to, the third party library, or neither?

I would file an issue against rails at Issues · rails/rails · GitHub

1 Like