Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue when an error is raised in a Timecop.return block #126



Copy link

Consider this example: - (1 * 24 * 60 * 60)) do
  Timecop.return { puts; raise 'foo!' } rescue nil

Console output:

2014-09-10 14:05:55 -0700
2014-09-11 14:05:55 -0700
2014-09-11 14:05:55 -0700

Errors raised in a Timecop.return block mean the previous time is never restored, undoing any freezes or travels. This PR simply adds an ensure statement in Timecop#return that ensures the current stack always gets restored, even when an error occurs in the yield.

Copy link
Contributor Author

Any idea when this might be merged, @travisjeffery?

Copy link

Ah, nice! Thank you!

travisjeffery pushed a commit that referenced this pull request Feb 19, 2015
Issue when an error is raised in a Timecop.return block
@travisjeffery travisjeffery merged commit 8093f4a into travisjeffery:master Feb 19, 2015
@camertron camertron deleted the fix_timecop_return_when_error branch December 2, 2021 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants