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

Merged

Conversation

@camertron
Copy link
Contributor

@camertron camertron commented Sep 11, 2014

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.

…ch unsets any global freezes or travels
@camertron
Copy link
Contributor Author

@camertron camertron commented Oct 3, 2014

Any idea when this might be merged, @travisjeffery?

@travisjeffery
Copy link
Owner

@travisjeffery travisjeffery commented Feb 19, 2015

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
1 check passed
1 check passed
continuous-integration/travis-ci The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.