Ruby
timecop

重ねてTimecop.travel/freezeした後にreturnした後の挙動

More than 1 year has passed since last update.

重ねてTimecop.travelしても、関係なく元の時間に戻る。

[1] pry(main)> Timecop.travel(Time.now + 10.days)
=> 2015-03-22 16:06:13 +0900
[2] pry(main)> Time.now
=> 2015-03-22 16:06:19 +0900
[3] pry(main)> Timecop.travel(Time.now + 10.days)
=> 2015-04-01 16:06:22 +0900
[4] pry(main)> Time.now
=> 2015-04-01 16:06:24 +0900
[5] pry(main)> Timecop.return
=> nil
[6] pry(main)> Time.now
=> 2015-03-12 16:06:30 +0900

重ねてTimecop.freezeしても、関係なく元の時間に戻る。

[1] pry(main)> Timecop.freeze(Time.parse('2014-01-01 00:00:00'))
=> 2014-01-01 00:00:00 +0900
[2] pry(main)> Timecop.freeze(Time.parse('2014-01-01 01:00:00'))
=> 2014-01-01 01:00:00 +0900
[3] pry(main)> Time.now
=> 2014-01-01 01:00:00 +0900
[4] pry(main)> Timecop.return
=> nil
[5] pry(main)> Time.now
=> 2015-03-12 19:59:52 +0900