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
merged 1 commit into from Feb 19, 2015

Conversation

Projects
None yet
2 participants
@camertron
Contributor

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.

@camertron

This comment has been minimized.

Show comment
Hide comment
@camertron

camertron Oct 3, 2014

Contributor

Any idea when this might be merged, @travisjeffery?

Contributor

camertron commented Oct 3, 2014

Any idea when this might be merged, @travisjeffery?

@travisjeffery

This comment has been minimized.

Show comment
Hide comment
@travisjeffery

travisjeffery Feb 19, 2015

Owner

Ah, nice! Thank you!

Owner

travisjeffery commented Feb 19, 2015

Ah, nice! Thank you!

travisjeffery added a commit that referenced this pull request Feb 19, 2015

Merge pull request #126 from camertron/fix_timecop_return_when_error
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

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