Created
January 9, 2023 12:19
-
-
Save ixti/6f774420c548aeaa9919ae413aa99836 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "active_support/time" | |
require "timecop" | |
Timecop.safe_mode = true | |
RSpec.configure do |config| | |
config.around(:frozen_time) do |ex| | |
time = | |
case (value = ex.metadata[:frozen_time]) | |
when true then Time.current.floor(0) | |
when Time then value | |
when String then Time.parse(value) # rubocop:disable Rails/TimeZone | |
else | |
warn "Invalid frozen_time tag argument: #{value.inspect}, using current time" | |
Time.current.floor(0) | |
end | |
Timecop.freeze(time, &ex) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment