You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add "Prefer freeze_time over travel_to with an argument of the current time" rule
Since there are several ways to indicate the current time,
we believe that `freeze_time`,
which can be expressed as simply as possible, should be preferred.
```ruby
# bad
travel_to(Time.now)
travel_to(DateTime.now)
travel_to(Time.current)
travel_to(Time.zone.now)
travel_to(Time.now.in_time_zone)
travel_to(Time.current.to_time)
# good
freeze_time
```
Copy file name to clipboardExpand all lines: README.adoc
+18Lines changed: 18 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1791,6 +1791,24 @@ class MyControllerTest < ActionDispatch::IntegrationTest
1791
1791
end
1792
1792
----
1793
1793
1794
+
=== `freeze_time` [[freeze-time]]
1795
+
1796
+
Prefer https://api.rubyonrails.org/classes/ActiveSupport/Testing/TimeHelpers.html#method-i-freeze_time[ActiveSupport::Testing::TimeHelpers#freeze_time] over https://api.rubyonrails.org/classes/ActiveSupport/Testing/TimeHelpers.html#method-i-travel_to[ActiveSupport::Testing::TimeHelpers#travel_to] with an argument of the current time.
0 commit comments