Skip to content

Instantly share code, notes, and snippets.

@ixti
Created January 9, 2023 12:19
Show Gist options
  • Save ixti/6f774420c548aeaa9919ae413aa99836 to your computer and use it in GitHub Desktop.
Save ixti/6f774420c548aeaa9919ae413aa99836 to your computer and use it in GitHub Desktop.
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