travisjeffery / timecop

A gem providing "time travel", "time freezing", and "time acceleration" capabilities, making it simple to test time-dependent code. It provides a unified method to mock Time.now, Date.today, and DateTime.now in a single call.
MIT License
3.36k stars 223 forks source link

Add support for ruby-head (3.1) #288

Closed mlarraz closed 3 years ago

mlarraz commented 3 years ago

Problem

As of https://github.com/ruby/ruby/pull/4010, Time.new now accepts an optional keyword argument.

This means the monkey patch here will break in newer Ruby versions, because Ruby now requires keyword arguments be handled separately from other arguments.

Solution

Check if ruby2_keywords is defined (Ruby 2.7+), and use it if it is, which will force the previous behavior.