Created
December 24, 2014 14:58
-
-
Save qd3v/f1becf9718cced46ad67 to your computer and use it in GitHub Desktop.
Timecop explained
This file contains hidden or 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
t = Time.local(2008, 9, 1, 10, 5, 0) | |
# Self-explained | |
Timecop.freeze(t) do | |
expect(Time.zone.now.sec).to eq 0 | |
end | |
# The same as above | |
Timecop.freeze(new_time) | |
expect(Time.zone.now.sec).to eq 0 | |
Timecop.return | |
# Move to time and start counting as usual | |
Timecop.travel(t) do | |
sleep(1) | |
# travel time to + 1 sec | |
puts Time.now | |
end | |
# Combo. Travel to time, allow it run and treat one second as hour | |
Timecop.travel(t) do | |
Timecop.scale(3600) do | |
sleep(1) | |
# travel time + msecs + one hour | |
puts Time.now | |
sleep(1) | |
# travel time + msecs + two hours | |
puts Time.now | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment