1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Remove automatic removal of Date/Time stubs after each test case

This behavior is only work out-of-box with minitest and also add a
downside to run after each test case, even if we don't used the travel
or travel_to methods
This commit is contained in:
Rafael Mendonça França 2014-01-29 22:41:30 -02:00
parent 6b16c27881
commit 7abb6e00c0
5 changed files with 22 additions and 10 deletions

View file

@ -6,10 +6,14 @@ end
class TouchTest < ActiveRecord::TestCase class TouchTest < ActiveRecord::TestCase
fixtures :mixins fixtures :mixins
def setup setup do
travel_to Time.now travel_to Time.now
end end
teardown do
travel_back
end
def test_update def test_update
stamped = Mixin.new stamped = Mixin.new

View file

@ -1,3 +1,11 @@
* Remove behavior that automatically remove the Date/Time stubs, added by `travel`
and `travel_to` methods, after each test case.
Now users have to use the `travel_back` or the block version of `travel` and
`travel_to` methods to clean the stubs.
*Rafael Mendonça França*
* Add `travel_back` to remove stubs from `travel` and `travel_to`. * Add `travel_back` to remove stubs from `travel` and `travel_to`.
*Rafael Mendonça França* *Rafael Mendonça França*

View file

@ -41,14 +41,8 @@ module ActiveSupport
# Containing helpers that helps you test passage of time. # Containing helpers that helps you test passage of time.
module TimeHelpers module TimeHelpers
def after_teardown #:nodoc:
travel_back
super
end
# Change current time to the time in the future or in the past by a given time difference by # Change current time to the time in the future or in the past by a given time difference by
# stubbing +Time.now+ and +Date.today+. Note that the stubs are automatically removed # stubbing +Time.now+ and +Date.today+.
# at the end of each test.
# #
# Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00 # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
# travel 1.day # travel 1.day
@ -68,8 +62,7 @@ module ActiveSupport
end end
# Change current time to the given time by stubbing +Time.now+ and +Date.today+ to return the # Change current time to the given time by stubbing +Time.now+ and +Date.today+ to return the
# time or date passed into this method. Note that the stubs are automatically removed # time or date passed into this method.
# at the end of each test.
# #
# Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00 # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
# travel_to Time.new(2004, 11, 24, 01, 04, 44) # travel_to Time.new(2004, 11, 24, 01, 04, 44)

View file

@ -162,6 +162,10 @@ class TimeHelperTest < ActiveSupport::TestCase
Time.stubs now: Time.now Time.stubs now: Time.now
end end
teardown do
travel_back
end
def test_time_helper_travel def test_time_helper_travel
expected_time = Time.now + 1.day expected_time = Time.now + 1.day
travel 1.day travel 1.day

View file

@ -97,6 +97,7 @@ class TimeZoneTest < ActiveSupport::TestCase
assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today
travel_to(Time.utc(2000, 1, 2, 5)) # midnight Jan 2 EST travel_to(Time.utc(2000, 1, 2, 5)) # midnight Jan 2 EST
assert_equal Date.new(2000, 1, 2), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today assert_equal Date.new(2000, 1, 2), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today
travel_back
end end
def test_tomorrow def test_tomorrow
@ -108,6 +109,7 @@ class TimeZoneTest < ActiveSupport::TestCase
assert_equal Date.new(2000, 1, 2), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].tomorrow assert_equal Date.new(2000, 1, 2), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].tomorrow
travel_to(Time.utc(2000, 1, 2, 5)) # midnight Jan 2 EST travel_to(Time.utc(2000, 1, 2, 5)) # midnight Jan 2 EST
assert_equal Date.new(2000, 1, 3), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].tomorrow assert_equal Date.new(2000, 1, 3), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].tomorrow
travel_back
end end
def test_yesterday def test_yesterday
@ -119,6 +121,7 @@ class TimeZoneTest < ActiveSupport::TestCase
assert_equal Date.new(1999, 12, 31), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].yesterday assert_equal Date.new(1999, 12, 31), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].yesterday
travel_to(Time.utc(2000, 1, 2, 5)) # midnight Jan 2 EST travel_to(Time.utc(2000, 1, 2, 5)) # midnight Jan 2 EST
assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].yesterday assert_equal Date.new(2000, 1, 1), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].yesterday
travel_back
end end
def test_local def test_local