From 6b16c2788186d45c70bd1d9fc476407e3e265439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 29 Jan 2014 22:24:48 -0200 Subject: Add `travel_back` to remove stubs from `travel` and `travel_to` --- .../lib/active_support/testing/time_helpers.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'activesupport/lib/active_support/testing') diff --git a/activesupport/lib/active_support/testing/time_helpers.rb b/activesupport/lib/active_support/testing/time_helpers.rb index 0ee6332d6f..b183b8d8ef 100644 --- a/activesupport/lib/active_support/testing/time_helpers.rb +++ b/activesupport/lib/active_support/testing/time_helpers.rb @@ -42,7 +42,7 @@ module ActiveSupport # Containing helpers that helps you test passage of time. module TimeHelpers def after_teardown #:nodoc: - simple_stubs.unstub_all! + travel_back super end @@ -81,7 +81,7 @@ module ActiveSupport # # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00 # travel_to Time.new(2004, 11, 24, 01, 04, 44) do - # User.create.created_at # => Wed, 24 Nov 2004 01:04:44 EST -05:00 + # Time.current # => Wed, 24 Nov 2004 01:04:44 EST -05:00 # end # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00 def travel_to(date_or_time, &block) @@ -90,10 +90,21 @@ module ActiveSupport if block_given? block.call - simple_stubs.unstub_all! + travel_back end end + # Return the current time back to its original state. + # + # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00 + # travel_to Time.new(2004, 11, 24, 01, 04, 44) + # Time.current # => Wed, 24 Nov 2004 01:04:44 EST -05:00 + # travel_back + # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00 + def travel_back + simple_stubs.unstub_all! + end + private def simple_stubs -- cgit v1.2.3 From 7abb6e00c0f1d6cc98b10b0e7620dfb9786449a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 29 Jan 2014 22:41:30 -0200 Subject: 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 --- activesupport/lib/active_support/testing/time_helpers.rb | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'activesupport/lib/active_support/testing') diff --git a/activesupport/lib/active_support/testing/time_helpers.rb b/activesupport/lib/active_support/testing/time_helpers.rb index b183b8d8ef..4c6bca5ada 100644 --- a/activesupport/lib/active_support/testing/time_helpers.rb +++ b/activesupport/lib/active_support/testing/time_helpers.rb @@ -41,14 +41,8 @@ module ActiveSupport # Containing helpers that helps you test passage of time. 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 - # stubbing +Time.now+ and +Date.today+. Note that the stubs are automatically removed - # at the end of each test. + # stubbing +Time.now+ and +Date.today+. # # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00 # travel 1.day @@ -68,8 +62,7 @@ module ActiveSupport end # 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 - # at the end of each test. + # time or date passed into this method. # # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00 # travel_to Time.new(2004, 11, 24, 01, 04, 44) -- cgit v1.2.3 From fa1f20e6549f962112948f5b3c27d09ab5e5faaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Thu, 30 Jan 2014 10:13:58 -0200 Subject: Improve documentation [ci skip] --- activesupport/lib/active_support/testing/time_helpers.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'activesupport/lib/active_support/testing') diff --git a/activesupport/lib/active_support/testing/time_helpers.rb b/activesupport/lib/active_support/testing/time_helpers.rb index 4c6bca5ada..9e0a3d6345 100644 --- a/activesupport/lib/active_support/testing/time_helpers.rb +++ b/activesupport/lib/active_support/testing/time_helpers.rb @@ -41,7 +41,7 @@ module ActiveSupport # Containing helpers that helps you test passage of time. module TimeHelpers - # Change current time to the time in the future or in the past by a given time difference by + # Changes current time to the time in the future or in the past by a given time difference by # stubbing +Time.now+ and +Date.today+. # # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00 @@ -61,7 +61,7 @@ module ActiveSupport travel_to Time.now + duration, &block end - # Change current time to the given time by stubbing +Time.now+ and +Date.today+ to return the + # Changes current time to the given time by stubbing +Time.now+ and +Date.today+ to return the # time or date passed into this method. # # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00 @@ -87,7 +87,8 @@ module ActiveSupport end end - # Return the current time back to its original state. + # Returns the current time back to its original state, by removing the stubs added by + # `travel` and `travel_to`. # # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00 # travel_to Time.new(2004, 11, 24, 01, 04, 44) -- cgit v1.2.3