diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-01-30 04:19:00 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-01-30 04:19:00 -0800 |
commit | db6f69fd2a35dde23ab8a9b8fad6071043ac8954 (patch) | |
tree | c36d39f66c220c8041ddd72efff3264275adf4b5 /activesupport/lib/active_support/testing/time_helpers.rb | |
parent | 7f5466d58299db35a3d320e0b526001ae3be11a7 (diff) | |
parent | fa1f20e6549f962112948f5b3c27d09ab5e5faaf (diff) | |
download | rails-db6f69fd2a35dde23ab8a9b8fad6071043ac8954.tar.gz rails-db6f69fd2a35dde23ab8a9b8fad6071043ac8954.tar.bz2 rails-db6f69fd2a35dde23ab8a9b8fad6071043ac8954.zip |
Merge pull request #13884 from rafaelfranca/rm-travel-back
Add `travel_back` to remove stubs from `travel` and `travel_to` and remove auto-rollback after each test case
Diffstat (limited to 'activesupport/lib/active_support/testing/time_helpers.rb')
-rw-r--r-- | activesupport/lib/active_support/testing/time_helpers.rb | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/activesupport/lib/active_support/testing/time_helpers.rb b/activesupport/lib/active_support/testing/time_helpers.rb index 0ee6332d6f..9e0a3d6345 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: - simple_stubs.unstub_all! - 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. + # 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 # travel 1.day @@ -67,9 +61,8 @@ 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 - # time or date passed into this method. Note that the stubs are automatically removed - # at the end of each test. + # 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 # travel_to Time.new(2004, 11, 24, 01, 04, 44) @@ -81,7 +74,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 +83,22 @@ module ActiveSupport if block_given? block.call - simple_stubs.unstub_all! + travel_back end end + # 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) + # 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 |