Skip to content

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

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

Merged

Conversation

camertron
Copy link
Contributor

Consider this example:

Timecop.travel(Time.now - (1 * 24 * 60 * 60)) do
  puts Time.now.to_s
  Timecop.return { puts Time.now.to_s; raise 'foo!' } rescue nil
  puts Time.now.to_s
end

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.

@camertron
Copy link
Contributor Author

Any idea when this might be merged, @travisjeffery?

@travisjeffery
Copy link
Owner

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants