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 methods to allow Timecop instance checking if in a travelled or scaled state #414

Closed djgraham closed 8 months ago

djgraham commented 8 months ago

In a recent Timecop release (0.9.7, commit c57a1fc), a fix was made to the boolean method#frozen? which previously returned true if Timecop was active at that instance in time (frozen, scaled or travelled). This method was changed so that only returned true if Timecop was in a frozen state. Once this change was made it was no longer possible to check if Timecop was in a scaled or travelled state.

As a result of this change, our automated test suite, which relied on the previous behaviour of frozen? failed (we used it to check if Timecop present in any way in a database helper, and it affected how our automated factory objects were being created where dates are involved). We discovered this after investigating a dependabot automated gem update failure.

This PR exposes two additional methods scaled? and travelled? to allow a consumer to check for these states. I did consider an alternative method active? which would have been the previous frozen? behaviour, but decided to be explicit in these new methods.

I've added in some additional tests to cover what I think are most of the examples.

(Note: will update changelog if this PR is likely to get merged)

Thank you

joshuacronemeyer commented 8 months ago

@djgraham update changelog request will be accepted. We can plan for this to be the first timecop release of 2024. 2024 is a leap year so looking forward to a lot of fun for tests and testing in this exciting future we're living through!

;p

djgraham commented 8 months ago

Thank you for the PR approval @joshuacronemeyer ! I've added in an additional commit to for the entry to History.md

Hopefully if these are all good they can be merged in 🤞

Thanks again !