Skip to content

Commit

Permalink
Fixes an issue when an error is raised in a Timecop.return block, whi…
Browse files Browse the repository at this point in the history
…ch unsets any global freezes or travels
  • Loading branch information
Cameron Dutro committed Sep 11, 2014
1 parent 5fe7dd8 commit 3d07f72
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/timecop/timecop.rb
Expand Up @@ -150,6 +150,7 @@ def return(&block)
current_baseline = @baseline
unmock!
yield
ensure
@_stack = current_stack
@baseline = current_baseline
end
Expand Down
8 changes: 8 additions & 0 deletions test/timecop_test.rb
Expand Up @@ -219,6 +219,14 @@ def test_exception_thrown_in_freeze_block_properly_resets_time
end
end

def test_exception_thrown_in_return_block_restores_previous_time
t = Time.local(2008, 10, 10, 10, 10, 10)
Timecop.freeze(t) do
Timecop.return { raise 'foobar' } rescue nil
assert_equal t, Time.now
end
end

def test_freeze_freezes_time
t = Time.local(2008, 10, 10, 10, 10, 10)
now = Time.now
Expand Down

0 comments on commit 3d07f72

Please sign in to comment.